diff --git a/app.js b/app.js index d43a27d..b916396 100644 --- a/app.js +++ b/app.js @@ -40,19 +40,19 @@ app.use(express.json()); // Method override app.use( - methodOverride(function (req, res) { - if (req.body && typeof req.body === "object" && "_method" in req.body) { - // look in urlencoded POST bodies and delete it - let method = req.body._method; - delete req.body._method; - return method; - } - }) + methodOverride(function(req, res) { + if (req.body && typeof req.body === "object" && "_method" in req.body) { + // look in urlencoded POST bodies and delete it + let method = req.body._method; + delete req.body._method; + return method; + } + }) ); // Logging if (process.env.NODE_ENV === "development") { - app.use(morgan("dev")); + app.use(morgan("dev")); } // EJS @@ -65,12 +65,12 @@ app.use(expressLayouts); // Sessions app.use( - session({ - secret: "keyboard cat", - resave: false, - saveUninitialized: false, - store: new MongoStore({ mongooseConnection: mongoose.connection }), - }) + session({ + secret: "keyboard cat", + resave: false, + saveUninitialized: false, + store: new MongoStore({ mongooseConnection: mongoose.connection }), + }) ); // Passport middleware @@ -81,12 +81,12 @@ app.use(passport.session()); app.use(flash()) // Set Global variables -app.use(function (req, res, next) { - res.locals.user = req.user || null; - res.locals.success_msg = req.flash('success_msg'); - res.locals.error_msg = req.flash('error_msg'); - res.locals.error = req.flash('error'); - next(); +app.use(function(req, res, next) { + res.locals.user = req.user || null; + res.locals.success_msg = req.flash('success_msg'); + res.locals.error_msg = req.flash('error_msg'); + res.locals.error = req.flash('error'); + next(); }); // Static folder @@ -103,12 +103,13 @@ app.use("/cart", require("./routes/api/cart")); app.use("/done", require("./routes/api/done")); app.use("/addBalance", require("./routes/api/addBalance")); app.use("/transaction", require("./routes/api/transaction")); +app.use("/search", require("./routes/api/search")); // Port: Love You 3000 const PORT = process.env.PORT || 3000; // Server Listening app.listen( - PORT, - console.log(`Server running in ${process.env.NODE_ENV} mode on port ${PORT}`) -); + PORT, + console.log(`Server running in ${process.env.NODE_ENV} mode on port ${PORT}`) +); \ No newline at end of file diff --git a/public/javascript/script.js b/public/javascript/script.js index a106a15..c684f2b 100644 --- a/public/javascript/script.js +++ b/public/javascript/script.js @@ -1,3 +1,3 @@ // Main Script -console.log("Hello TradeByte!"); +console.log("Hello TradeByte!"); \ No newline at end of file diff --git a/routes/api/market.js b/routes/api/market.js index e9c98b0..4fd3d07 100644 --- a/routes/api/market.js +++ b/routes/api/market.js @@ -14,42 +14,43 @@ const totalData = require("../../config/data-total.json"); // @desc Market page // @route GET /Market // @access Privat -router.get("/", ensureAuth, async (req, res) => { - let min = 0; - let max = 75; - - res.status(200).render("market", { - layout: "layouts/app", - compactData, - totalData, - min, - max, - href: "/market", - avatar: req.user.image, - }); +router.get("/", ensureAuth, async(req, res) => { + let min = 0; + let max = 75; + + + res.status(200).render("market", { + layout: "layouts/app", + compactData, + totalData, + min, + max, + href: "/market", + avatar: req.user.image, + }); }); // @desc Market page // @route GET /Market/:page // @access Private -router.get("/:page", ensureAuth, async (req, res) => { - let page = req.params.page - 1; - let min = page * 75; - let max = page * 75 + 75; - - if (page <= 0 || page >= 39) { - res.status(200).redirect("/market"); - } else { - res.status(200).render("market", { - layout: "layouts/app", - compactData, - totalData, - min, - max, - href: "/market", - avatar: req.user.image, - }); - } +router.get("/:page", ensureAuth, async(req, res) => { + let page = req.params.page - 1; + let min = page * 75; + let max = page * 75 + 75; + + if (page <= 0 || page >= 39) { + res.status(200).redirect("/market"); + } else { + res.status(200).render("market", { + layout: "layouts/app", + compactData, + totalData, + min, + max, + href: "/market", + avatar: req.user.image, + }); + } }); -module.exports = router; +module.exports = router; \ No newline at end of file diff --git a/routes/api/portfolio.js b/routes/api/portfolio.js index 76d3f26..090f60f 100644 --- a/routes/api/portfolio.js +++ b/routes/api/portfolio.js @@ -4,20 +4,17 @@ const express = require("express"); const router = express.Router(); const { ensureAuth, ensureGuest } = require("../../middleware/auth"); +const totalData = require("../../config/data-total.json"); + // @desc Portfolio page // @route GET /portfolio // @access Private router.get("/", ensureAuth, (req, res) => { - - let user = req.user; - console.log(user) - - // Check1 - let avatar = req.user.image; - - res - .status(200) - .render("portfolio", { layout: "layouts/app", avatar, href: "/portfolio" }); + let user = req.user; + let avatar = req.user.image; + res + .status(200) + .render("portfolio", { layout: "layouts/app", avatar, totalData, href: "/portfolio" }); }); -module.exports = router; +module.exports = router; \ No newline at end of file diff --git a/routes/api/search.js b/routes/api/search.js new file mode 100644 index 0000000..5cd3468 --- /dev/null +++ b/routes/api/search.js @@ -0,0 +1,28 @@ +// search Routes + +const express = require("express"); +const router = express.Router(); +const { ensureAuth, ensureGuest } = require("../../middleware/auth"); + +const totalData = require("../../config/data-total.json"); +// const app = express(); +// app.locals.searchbar = function(event) { +// console.log("hello" + event.target.value); +// } +// app.locals.vm = "string name"; + + + +router.get("/", ensureAuth, (req, res) => { + let avatar = req.user.image; + // const searchbar = function(event) { + // console.log("hello" + event.target.value); + + // } + // console.log(compactData); + res + .status(200) + .render("search", { layout: "layouts/app", avatar, totalData, href: "/search" }); +}); + +module.exports = router; \ No newline at end of file diff --git a/routes/api/view.js b/routes/api/view.js index da88452..72a963c 100644 --- a/routes/api/view.js +++ b/routes/api/view.js @@ -6,7 +6,7 @@ const express = require("express"); const router = express.Router(); const getPrice = require("../../helpers/getPrice"); const alpha = require("alphavantage")({ - key: process.env.ALPHA_VANTAGE_KEY, + key: process.env.ALPHA_VANTAGE_KEY, }); const getOverview = require("../../helpers/getOverview"); @@ -15,98 +15,98 @@ const { ensureAuth } = require("../../middleware/auth"); // @desc View Page // @route GET /view/:symbol // @access Private -router.get("/:symbol", ensureAuth, async (req, res) => { - const symbol = req.params.symbol; - let data = await getOverview(symbol); - let { latestPrice, low, high } = await getPrice(symbol); - let AssetType = data["AssetType"]; - let assetName = data["Name"]; - let assetExchange = data["Exchange"]; - let Currency = data["Currency"]; - let Country = data["Country"]; - let Sector = data["Sector"]; - let MarketCap = data["MarketCap"]; - let Ebitda = data["EBITDA"]; - let PERatio = data["PERatio"]; - let PriceToBookRatio = data["PriceToBookRatio"]; - let EPS = data["EPS"]; - let DividendYield = data["DividendYield"]; - let BookValue = data["BookValue"]; - let ProfitMargin = data["ProfitMargin"]; - let RevenueTTM = data["RevenueTTM"]; - let Desc = data["Desc"]; - let weeksLow = data["weeksLow"]; - let weeksHigh = data["weeksHigh"]; +router.get("/:symbol", ensureAuth, async(req, res) => { + const symbol = req.params.symbol; + let data = await getOverview(symbol); + let { latestPrice, low, high } = await getPrice(symbol); + let AssetType = data["AssetType"]; + let assetName = data["Name"]; + let assetExchange = data["Exchange"]; + let Currency = data["Currency"]; + let Country = data["Country"]; + let Sector = data["Sector"]; + let MarketCap = data["MarketCap"]; + let Ebitda = data["EBITDA"]; + let PERatio = data["PERatio"]; + let PriceToBookRatio = data["PriceToBookRatio"]; + let EPS = data["EPS"]; + let DividendYield = data["DividendYield"]; + let BookValue = data["BookValue"]; + let ProfitMargin = data["ProfitMargin"]; + let RevenueTTM = data["RevenueTTM"]; + let Desc = data["Desc"]; + let weeksLow = data["weeksLow"]; + let weeksHigh = data["weeksHigh"]; - // console.log(data); - alpha.data - .intraday(symbol, "compact", "json", "60min") - .then((data) => { - const intraDay = data["Time Series (60min)"]; + // console.log(data); + alpha.data + .intraday(symbol, "compact", "json", "60min") + .then((data) => { + const intraDay = data["Time Series (60min)"]; - // const assetInformation = data["Meta Data"]["1. Information"]; - // const lastRefreshed = data["Meta Data"]["3. Last Refreshed"]; - let dates = []; - let opening = []; - let closing = []; - let highs = []; - let lows = []; - let volumes = []; - const keys = Object.getOwnPropertyNames(intraDay); + // const assetInformation = data["Meta Data"]["1. Information"]; + // const lastRefreshed = data["Meta Data"]["3. Last Refreshed"]; + let dates = []; + let opening = []; + let closing = []; + let highs = []; + let lows = []; + let volumes = []; + const keys = Object.getOwnPropertyNames(intraDay); - for (let i = 0; i < 40; i++) { - dates.push(keys[i]); - opening.push(intraDay[keys[i]]["1. open"]); - highs.push(intraDay[keys[i]]["2. high"]); - lows.push(intraDay[keys[i]]["3. low"]); - closing.push(intraDay[keys[i]]["4. close"]); - volumes.push(intraDay[keys[i]]["5. volume"]); - } - // reverse so dates appear from left to right - dates.reverse(); - closing.reverse(); - // dates = JSON.stringify(dates); - // closing = JSON.stringify(closing); + for (let i = 0; i < 40; i++) { + dates.push(keys[i]); + opening.push(intraDay[keys[i]]["1. open"]); + highs.push(intraDay[keys[i]]["2. high"]); + lows.push(intraDay[keys[i]]["3. low"]); + closing.push(intraDay[keys[i]]["4. close"]); + volumes.push(intraDay[keys[i]]["5. volume"]); + } + // reverse so dates appear from left to right + dates.reverse(); + closing.reverse(); + // dates = JSON.stringify(dates); + // closing = JSON.stringify(closing); - res.status(200).render("view", { - layout: "layouts/app", - href: "/market", - avatar: req.user.image, - symbol, - data, - dates, - opening, - closing, - highs, - lows, - volumes, - AssetType, - assetName, - assetExchange, - Currency, - Country, - Sector, - MarketCap, - Ebitda, - PERatio, - PriceToBookRatio, - EPS, - DividendYield, - BookValue, - ProfitMargin, - RevenueTTM, - Desc, - latestPrice, - high, - low, - weeksLow, - weeksHigh, - }); - }) - .catch((err) => { - console.error(err); - res.render("error/500"); - }); + res.status(200).render("view", { + layout: "layouts/app", + href: "/market", + avatar: req.user.image, + symbol, + data, + dates, + opening, + closing, + highs, + lows, + volumes, + AssetType, + assetName, + assetExchange, + Currency, + Country, + Sector, + MarketCap, + Ebitda, + PERatio, + PriceToBookRatio, + EPS, + DividendYield, + BookValue, + ProfitMargin, + RevenueTTM, + Desc, + latestPrice, + high, + low, + weeksLow, + weeksHigh, + }); + }) + .catch((err) => { + console.error(err); + res.render("error/500"); + }); }); -module.exports = router; +module.exports = router; \ No newline at end of file diff --git a/views/portfolio.ejs b/views/portfolio.ejs index a0ce06a..06120fb 100644 --- a/views/portfolio.ejs +++ b/views/portfolio.ejs @@ -18,9 +18,10 @@ -
-
- +
+
+ +
- -
- - - - -
-
-  -
-
-

- $40,342.04 -

- Total Portfolio -
-
- - - -
-
-  -
-
-

- $ 40,342.04 -

- Profit / Loss -
-
- - - -
-
-  -
-
-

- $40,342.04 -

- $ Balance -
+ +
+
    + + +
    + + + + +
    +
    +  +
    +
    +

    + $40,342.04 +

    + Total Portfolio +
    +
    + + + +
    +
    +  +
    +
    +

    + $ 40,342.04 +

    + Profit / Loss +
    +
    + + + +
    +
    +  +
    +
    +

    + $40,342.04 +

    + $ Balance +
    +
    +
    -
    -
    @@ -524,3 +516,29 @@ + + + + + diff --git a/views/search.ejs b/views/search.ejs new file mode 100644 index 0000000..10a546f --- /dev/null +++ b/views/search.ejs @@ -0,0 +1,65 @@ +
    +
    + +

    SEARCHED ITEMS

    +
    + + +
    + +
      + + + +
      + +
      + \ No newline at end of file