Skip to content

Commit

Permalink
#44 PR Merge Conflits Resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
iampavangandhi committed Aug 24, 2020
1 parent 351b9a7 commit 11bdf9e
Show file tree
Hide file tree
Showing 13 changed files with 409 additions and 413 deletions.
2 changes: 1 addition & 1 deletion public/css/style.css

Large diffs are not rendered by default.

48 changes: 23 additions & 25 deletions routes/api/addBalance.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,22 @@ const Transaction = require("../../models/Transaction");
// @route GET /
// @access Private
router.get("/", ensureAuth, (req, res) => {
let user = req.user;
let avatar = req.user.image;
res
.status(200).render("addBalance", {
layout: "layouts/app",
avatar,
user,
href: "/addBalance"
});
let user = req.user;
let avatar = req.user.image;
res.status(200).render("addBalance", {
layout: "layouts/app",
avatar,
user,
href: "/addBalance",
});
});

// TODO
router.post("/", ensureAuth, async(req, res) => {
// why ensureGuest here?
let amount = Number(req.body.addAmount); // type cast amount to number as body parser take it as string
let finalAmont = amount + req.user.balance;
router.post("/", ensureAuth, async (req, res) => {
// why ensureGuest here?
let amount = Number(req.body.addAmount); // type cast amount to number as body parser take it as string
let finalAmont = amount + req.user.balance;

try {
// Updating balance to user's schema.
req.body.user = req.user.id;
Expand All @@ -39,23 +38,22 @@ router.post("/", ensureAuth, async(req, res) => {
}
);
// Adding new transaction details on Transaction Schema.
const transactionDetails = 'Balance Added to Wallet'
const transactionOpration = 'Deposit'
const transactionUser = req.user.id
const updateTransactoin = await Transaction.create(
{ details: transactionDetails,
amount: amount,
opration: transactionOpration,
user: transactionUser
})
const transactionDetails = "Balance Added to Wallet";
const transactionOpration = "Deposit";
const transactionUser = req.user.id;
const updateTransactoin = await Transaction.create({
details: transactionDetails,
amount: amount,
opration: transactionOpration,
user: transactionUser,
});

console.log(updateTransactoin);
res.redirect("/done");
} catch (err) {
console.error(err);
res.render("error/500");
}

});

module.exports = router;
module.exports = router;
26 changes: 12 additions & 14 deletions routes/api/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,23 @@ router.get("/:symbol", ensureAuth, async (req, res) => {
const symbol = req.params.symbol;
const { latestPrice } = await getPrice(symbol);
const { companyName, logoSrc } = await getCompanyNameAndLogo(symbol);
res
.status(200)
.render("cart", {
layout: "layouts/app",
symbol,
latestPrice,
logoSrc,
companyName,
href: "/market",
avatar: req.user.image,
});
res.status(200).render("cart", {
layout: "layouts/app",
symbol,
latestPrice,
logoSrc,
companyName,
href: "/market",
avatar: req.user.image,
});
});

// @desc To buy
// @route POST /cart/buy
router.post("/buy", ensureAuth, async (req, res) => {
const user = req.user;
const symbol = req.body.companySymbol;
const { latestPrice } = await getPrice(symbol);;
const { latestPrice } = await getPrice(symbol);
const noOfStock = req.body.noOfStock;
const totalAmount = parseFloat(latestPrice * noOfStock).toFixed(4);

Expand All @@ -46,9 +44,9 @@ router.post("/buy", ensureAuth, async (req, res) => {
stockPrice: latestPrice,
noOfStock: noOfStock,
totalAmount: totalAmount,
}
};

console.log(data)
console.log(data);

try {
if (totalAmount > req.user.balance) {
Expand Down
65 changes: 32 additions & 33 deletions routes/api/market.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,42 @@ 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;
17 changes: 11 additions & 6 deletions routes/api/portfolio.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@ const totalData = require("../../config/data-total.json");
// @route GET /portfolio
// @access Private
router.get("/", ensureAuth, (req, res) => {
let user = req.user;
let avatar = req.user.image;
res
.status(200)
.render("portfolio", { layout: "layouts/app", avatar, totalData, 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;
24 changes: 8 additions & 16 deletions routes/api/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,16 @@ 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);
let avatar = req.user.image;

// }
// console.log(compactData);
res
.status(200)
.render("search", { layout: "layouts/app", avatar, totalData, href: "/search" });
res.status(200).render("search", {
layout: "layouts/app",
avatar,
totalData,
href: "/search",
});
});

module.exports = router;
module.exports = router;
Loading

0 comments on commit 11bdf9e

Please sign in to comment.