Skip to content

Commit

Permalink
Merge branch 'master' into fix/iampavangandhi#29
Browse files Browse the repository at this point in the history
  • Loading branch information
fabcodingzest authored Aug 16, 2020
2 parents 4c91dde + e4bf26a commit 9e1f999
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 23 deletions.
30 changes: 27 additions & 3 deletions routes/api/addBalance.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,41 @@
const express = require("express");
const router = express.Router();
const { ensureAuth, ensureGuest } = require("../../middleware/auth");
const User = require("../../models/User");

// @desc // Add Balance page
// @route GET /
// @access Private
router.get("/", ensureAuth, (req, res) => {
res.status(200).render("addBalance");
let user = req.user
res.status(200).render("addBalance"), {
user,
}

});

// TODO
router.post("/", ensureGuest, (req, res) => {
console.log("added");
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 {
req.body.user = req.user.id;
const updateBalance = await User.findOneAndUpdate(
{ _id: req.user.id },
{ balance: finalAmont},
{
new: true, // it will create a new one, if it doesn't exist
runValidators: true, // it check weather the fields are valid or not
}
)
console.log(updateBalance);
res.redirect("/");

} catch (err) {
console.error(err)
res.render('error/500')
}
});

module.exports = router;
2 changes: 1 addition & 1 deletion routes/api/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ router.get("/:symbol", ensureAuth, async (req, res) => {
const symbol = req.params.symbol;
const price = await getPrice(symbol);
res.status(200).render("cart", { layout: "layouts/app", symbol, price, href: '/market', avatar: req.user.image });

});

// @desc To buy
// @route POST /cart/buy
router.post("/buy", ensureAuth, async (req, res) => {
let data = req.body;
let user = req.user;
let companySymbol = req.body.companySymbol;
let stockPrice = req.body.stockPrice;
let noOfStock = req.body.noOfStock;
let totalAmount = stockPrice * noOfStock;
Expand Down
2 changes: 1 addition & 1 deletion routes/api/market.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ const { ensureAuth, ensureGuest } = require("../../middleware/auth");
router.get("/", ensureAuth, async (req, res) => {
res.status(200).render("market", { layout: "layouts/app", jsonData, href: '/market', avatar: req.user.image });
});

module.exports = router;
4 changes: 3 additions & 1 deletion routes/api/portfolio.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ const { ensureAuth, ensureGuest } = require("../../middleware/auth");
// @access Private
router.get("/", ensureAuth, (req, res) => {
let avatar = req.user.image;
res.status(200).render("portfolio", { layout: "layouts/app", avatar, href: '/portfolio' });
res
.status(200)
.render("portfolio", { layout: "layouts/app", avatar, href: "/portfolio" });
});

module.exports = router;
19 changes: 10 additions & 9 deletions views/addBalance.ejs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<h1>ADD BALANCE</h1>

<form action="/" method="POST" class="bg-white shadow-md rounded px-8 pt-6 pb-8 mb-4">
<hr>
<h3>Your Current Balance: <%= user.balance%> </h3>
<hr>
<br>
<form action="/addBalance" method="POST" class="bg-white shadow-md rounded px-8 pt-6 pb-8 mb-4">
<div class="mb-4">
<label class="block text-gray-700 text-sm font-bold mb-2" "> Add amount </label>
<input type=" number " class=" shadow appearance-none border rounded w-full py-2 px-3 text-gray-700
leading-tight focus:outline-none focus:shadow-outline " name=" add amount " placeholder=" add amount " >
</div>
<div class=" bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded focus:outline-none
focus:shadow-outline " type=" submit " onclick=" addAmount() ">
ADD
<label class="block text-gray-700 text-sm font-bold mb-2" "> Enter amount </label>
<input type="number" class=" shadow appearance-none border rounded w-full py-2 px-3 text-gray-700
leading-tight focus:outline-none focus:shadow-outline " name="addAmount" placeholder="amount" >
<input type="submit" value="Add" class=" bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded focus:outline-none
focus:shadow-outline">
</div>
</form>
21 changes: 13 additions & 8 deletions views/partials/_nav.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div @click.away="open = false"
class="flex flex-col w-full md:w-56 lg:w-64 text-gray-700 bg-white flex-shrink-0 md:h-screen md:z-50 md:fixed md:left-0 md:top-0"
x-data="{ open: false }">
<div class="flex-shrink-0 px-6 py-4 flex flex-row items-center justify-between ">
<div class="flex-shrink-0 px-6 py-4 flex flex-row items-center justify-between">
<h1 class="font-bold uppercase border-b border-gray-100 w-full text-center">
<a href="/" class="hover:text-gray-900 tracking-widest text-2xl md:text-2xl lg:text-3xl pb-2 pt-32">Tradebyte</a>
</h1>
Expand All @@ -17,7 +17,7 @@
</svg>
</button>
</div>
<nav :class="{'block': open, 'hidden': !open}" class="flex-grow md:block px-4 pb-4 md:pb-0 ">
<nav :class="{'block': open, 'hidden': !open}" class="flex-grow md:block px-4 pb-4 md:pb-0">
<div class="flex justify-center align-center rounded-full">
<img class="h-20 w-20 border-8 border-blue-600 box-1 rounded-full" src="<%= avatar %>" alt="" />
</div>
Expand All @@ -27,22 +27,27 @@
<path d="M5 13l4 4L19 7"></path>
</svg>Trading Active</a>
<div class="nav-box h-full flex flex-col justify-start">

<a class="block px-4 py-2 mt-2 text-sm font-semibold text-gray-900 hover:text-gray-900 focus:text-gray-900 hover:bg-gray-200 focus:bg-gray-200 focus:outline-none focus:shadow-outline flex <%= href === '/portfolio' ? 'bg-gray-200 border border-purple-700 border-l-8': '' %>"
href="/portfolio"> <svg class="w-5 ml-2 mr-1 " fill="none " stroke-linecap="round " stroke-linejoin="round "
stroke-width="2 " viewBox="0 0 24 24 " stroke="currentColor ">
<a class="block px-4 py-2 mt-2 text-sm font-semibold text-gray-900 hover:text-gray-900 focus:text-gray-900 hover:bg-gray-200 focus:bg-gray-200 focus:outline-none focus:shadow-outline flex <%= href === '/portfolio' ? 'bg-gray-200 border border-purple-700 border-l-8': '' %>"
href="/portfolio">
<svg class="w-5 ml-2 mr-1" fill="none " stroke-linecap="round " stroke-linejoin="round " stroke-width="2 "
viewBox="0 0 24 24 " stroke="currentColor ">
<path
d="M4 5a1 1 0 011-1h14a1 1 0 011 1v2a1 1 0 01-1 1H5a1 1 0 01-1-1V5zM4
13a1 1 0 011-1h6a1 1 0 011 1v6a1 1 0 01-1 1H5a1 1 0 01-1-1v-6zM16 13a1 1 0 011-1h2a1 1 0 011 1v6a1 1 0 01-1 1h-2a1 1 0 01-1-1v-6z ">
</path>
</svg>Dashboard</a>
<a class="block px-4 py-2 mt-2 text-sm font-semibold text-gray-900 bg-transparent hover:text-gray-900 focus:text-gray-900 hover:bg-gray-200 focus:bg-gray-200 focus:outline-none focus:shadow-outline flex <%= href === '/market' ? 'bg-gray-200 border border-purple-700 border-l-8': '' %>"
href="/market"><svg class="w-5 ml-2 mr-1 " fill="none " stroke-linecap="round " stroke-linejoin="round "
href="/market"><svg class="w-5 ml-2 mr-1" fill="none " stroke-linecap="round " stroke-linejoin="round "
stroke-width="2 " viewBox="0 0 24 24 " stroke="currentColor ">
<path d="M8 14v3m4-3v3m4-3v3M3 21h18M3 10h18M3 7l9-4 9 4M4 10h16v11H4V10z "></path>
</svg>Market</a>

<a class="block px-4 py-2 mt-2 text-sm font-semibold text-gray-900 bg-transparent hover:text-gray-900 focus:text-gray-900 hover:bg-gray-200 focus:bg-gray-200 focus:outline-none focus:shadow-outline flex"
href="/addBalance">+ Add Balance</a>
<!-- only for development purpose i added ADD BALANCE button here on navbar. -->

<a class="block px-4 py-2 mt-2 text-sm font-semibold text-gray-900 bg-transparent hover:text-gray-900 focus:text-gray-900 hover:bg-gray-200 focus:bg-gray-200 focus:outline-none focus:shadow-outline flex"
href="/auth/logout"><svg class="w-6 ml-2 mr-1 " fill="currentColor" viewBox="0 0 20 20">
href="/auth/logout"><svg class="w-6 ml-2 mr-1" fill="currentColor" viewBox="0 0 20 20">
<path fill-rule="evenodd"
d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z"
clip-rule="evenodd"></path>
Expand Down
1 change: 1 addition & 0 deletions views/portfolio.ejs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<main class="px-16 py-6 md:col-span-4 bg-gray-300 md:pl-64 md:mx-auto">


<!-- header -->

<header class="mt-4 absolute-center">
Expand Down

0 comments on commit 9e1f999

Please sign in to comment.