Skip to content

Commit

Permalink
Merge branch 'master' into fix/iampavangandhi#30
Browse files Browse the repository at this point in the history
  • Loading branch information
iampavangandhi authored Aug 24, 2020
2 parents 509ec32 + d7d9f97 commit 1977891
Show file tree
Hide file tree
Showing 10 changed files with 817 additions and 393 deletions.
3 changes: 2 additions & 1 deletion public/css/style.css

Large diffs are not rendered by default.

28 changes: 16 additions & 12 deletions routes/api/addBalance.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,23 @@ const Transaction = require("../../models/Transaction");
// @route GET /
// @access Private
router.get("/", ensureAuth, (req, res) => {
let user = req.user;
res.status(200).render("addBalance", {
layout: "layouts/app",
href: "/addBalance",
user,
});
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 Down Expand Up @@ -52,6 +55,7 @@ router.post("/", ensureAuth, async (req, res) => {
console.error(err);
res.render("error/500");
}

});

module.exports = router;
module.exports = router;
7 changes: 6 additions & 1 deletion routes/api/portfolio.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ const { ensureAuth, ensureGuest } = require("../../middleware/auth");
// @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", user, href: "/portfolio" });
.render("portfolio", { layout: "layouts/app", avatar, href: "/portfolio" });
});

module.exports = router;
1 change: 0 additions & 1 deletion views/addBalance.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,3 @@

</div>
</section>

98 changes: 72 additions & 26 deletions views/cart.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -17,52 +17,94 @@
<div class="mx-auto max-w-6xl flex flex-col w-full px-4 md:py-12 md:px-8 text-gray-800">
<form action="/cart/buy" method="POST">
<h1 class="text-2xl lg:text-4xl font-bold mt-8 mb-4 flex">
Buy Stock :<input class="bg-gray-300 max-w-sm w-24 ml-2" type="text" readonly value="<%= symbol %>"
id="companySymbol" name="companySymbol" />
Buy Stock :<input
class="bg-gray-300 max-w-sm w-24 ml-2"
type="text"
readonly
value="<%= symbol %>"
id="companySymbol"
name="companySymbol"
/>
</h1>
<div class="w-full text-sm lg:text-base border-4"></div>
<div
class="new grid grid-flow-col grid-cols-3 md:grid-cols-4 grid-rows-2 grig-gap-0 md:gap-4 lg:grid-rows-3 bg-white shadow-md p-2 lg:p-6 text-center">

<div class="text-xs text-left lg:text-lg font-bold uppercase flex items-center lg:justify-center">
class="new grid grid-flow-col grid-cols-3 md:grid-cols-4 grid-rows-2 grig-gap-0 md:gap-4 lg:grid-rows-3 bg-white shadow-md p-2 lg:p-6 text-center"
>
<div
class="text-xs text-left lg:text-lg font-bold uppercase flex items-center lg:justify-center"
>
Company Name
</div>
<div class="text-xs lg:text-lg font-bold flex items-center lg:items-center lg:row-span-2">
<div
class="text-xs lg:text-lg font-bold flex items-center lg:items-center lg:row-span-2"
>
<div class="flex flex-col items-center justify-center w-full">
<img class="hidden lg:block h-16" src="<%= logoSrc %> " alt="<%= companyName %>" />
<p class="font-medium text-left text-xs md:text-sm lg:text-center lg:text-lg w-full md:break-all">
<img
class="hidden lg:block h-16"
src="<%= logoSrc %> "
alt="<%= companyName %>"
/>
<p
class="font-medium text-left text-xs md:text-sm lg:text-center lg:text-lg w-full md:break-all"
>
<%= companyName %>
</p>
</div>
</div>
<div
class="hidden md:block text-xs lg:text-lg font-bold uppercase md:flex items-center justify-center">
class="hidden md:block text-xs lg:text-lg font-bold uppercase md:flex md:items-center md:justify-center lg:items-start"
>
Unit Price
</div>
<div class="hidden md:block md:flex md:justify-center text-xs lg:text-lg font-bold uppercase lg:row-span-2">
<input class="text-sm lg:text-center font-medium text-xs lg:text-lg w-full text-center"
value="<%= latestPrice %>" name="stockPrice" id="stockPrice" readonly />
<div
class="hidden md:block md:flex md:justify-center text-xs lg:text-lg font-bold uppercase lg:row-span-2"
>
<input
class="text-sm lg:text-center font-medium text-xs lg:text-lg w-full text-center"
value="<%= latestPrice %>"
name="stockPrice"
id="stockPrice"
readonly
/>
</div>
<div class="md:hidden text-xs text-center font-semibold uppercase flex items-center justify-center">
<div
class="md:hidden text-xs text-center font-semibold uppercase flex items-center justify-center"
>
Qty
</div>
<div
class="hidden md:block text-xs lg:text-lg font-bold uppercase md:flex items-center justify-center ">
class="hidden md:block text-xs lg:text-lg font-bold uppercase md:flex md:items-center md:justify-center lg:items-start"
>
Quantity
</div>
<div class="text-xs lg:text-lg font-bold uppercase flex items-center justify-center lg:row-span-2">
<div
class="text-xs lg:text-lg font-bold uppercase flex items-center justify-center lg:row-span-2"
>
<div class="h-8">
<div class="relative flex flex-row w-full h-8">
<input type="number" value="1" min="1" name="noOfStock" id="noOfStock"
class="w-full font-semibold text-center text-gray-700 bg-gray-200 outline-none focus:outline-none hover:text-black focus:text-black" />
<input
type="number"
value="1"
min="1"
name="noOfStock"
id="noOfStock"
class="w-full font-semibold text-center text-gray-700 bg-gray-200 outline-none focus:outline-none hover:text-black focus:text-black"
/>
</div>
</div>
</div>
<div class="text-xs lg:text-lg text-right font-bold uppercase flex items-center justify-end">
<div
class="text-xs lg:text-lg text-right font-bold uppercase flex items-center justify-end lg:items-start"
>
Total Price
</div>
<div class="text-xs lg:text-lg font-bold uppercase flex items-center justify-end lg:row-span-2">
<p class="text-xs md:text-sm font-medium text-right text-xs lg:text-lg break-words" id="totalPrice">
<div
class="text-xs lg:text-lg font-bold uppercase flex items-center justify-end lg:row-span-2"
>
<p
class="text-xs md:text-sm font-medium text-right text-xs lg:text-lg break-words"
id="totalPrice"
>
<span class="total-price">
<%= latestPrice %>
</span>
Expand All @@ -71,11 +113,15 @@
</div>
</div>
<div class="flex justify-end w-full items-center">
<a href="/market"
class="block uppercase ml-0 md:ml-auto mt-4 shadow bg-blue-800 hover:bg-indigo-700 focus:shadow-outline focus:outline-none text-white font-semibold text-xs lg:text-sm py-3 px-4 rounded">Back
to Market</a>
<button type="submit"
class="block uppercase mt-4 ml-4 shadow bg-yellow-500 hover:bg-yellow-600 focus:shadow-outline focus:outline-none text-black font-semibold text-xs lg:text-sm py-3 px-4 rounded">
<a
href="/market"
class="block uppercase ml-0 md:ml-auto mt-4 shadow bg-blue-800 hover:bg-indigo-700 focus:shadow-outline focus:outline-none text-white font-semibold text-xs lg:text-sm py-3 px-4 rounded"
>Back to Market</a
>
<button
type="submit"
class="block uppercase mt-4 ml-4 shadow bg-yellow-500 hover:bg-yellow-600 focus:shadow-outline focus:outline-none text-black font-semibold text-xs lg:text-sm py-3 px-4 rounded"
>
<span class="hidden md:inline-block">Proceed to</span> Checkout
</button>
</div>
Expand All @@ -91,4 +137,4 @@
const val = e.target.value;
totalPrice.textContent = parseFloat(stockPrice.value * val).toFixed(4);
});
</script>
</script>
48 changes: 25 additions & 23 deletions views/layouts/app.ejs
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.0-2/css/all.min.css"
integrity="sha256-46r060N2LrChLLb5zowXQ72/iKKNiw/lAmygmHExk/o="
crossorigin="anonymous"
/>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/Chart.min.js"></script>

<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.0-2/css/all.min.css"
integrity="sha256-46r060N2LrChLLb5zowXQ72/iKKNiw/lAmygmHExk/o=" crossorigin="anonymous" />
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/Chart.min.js"></script>
<link type="text/css" rel="stylesheet" href="./css/style.css" />
<link type="text/css" rel="stylesheet" href="../css/style.css" />
<title>TradeByte</title>
</head>

<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;700;900&display=swap" rel="stylesheet" />

<link type="text/css" rel="stylesheet" href="../css/style.css" />
<link type="text/css" rel="stylesheet" href="../css/tailwind.css" />
<link rel="shortcut icon" href="../images/TradeByte-Favicon.png" type="image/x-icon">
<title>TradeByte</title>
</head>

<body>
<div class="md:flex flex-col md:flex-row min-h-screen w-full">
<%- include('../partials/_nav.ejs') %>
<%- body %>
</div>
<script type="application/javascript" src="../javascript/script.js"></script>
</body>

</html>
<body>
<div class="md:flex flex-col bg-gray-300 md:flex-row min-h-screen w-full">
<%- include('../partials/_nav.ejs') %> <%- body %>
</div>
<script type="application/javascript" src="./javascript/script.js"></script>
<script
type="application/javascript"
src="../javascript/script.js"
></script>
</body>
</html>
5 changes: 2 additions & 3 deletions views/market.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
var pageNo = url.slice(url.length - 1, url.length) || 0;
var pageUrl = url.slice(0, url.length - 1);
if (pageNo == "t" ){
if (pageNo == "t") {
window.location.href = window.location.href + "/2"
} else if (pageNo == "/") {
window.location.href = window.location.href + "2"
Expand All @@ -140,5 +140,4 @@
}
}
}
</script>
</script>
84 changes: 31 additions & 53 deletions views/partials/_nav.ejs
Original file line number Diff line number Diff line change
@@ -1,57 +1,38 @@
<script src="https://cdn.jsdelivr.net/gh/alpinejs/[email protected]/dist/alpine.min.js" defer></script>

<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 text-center">
<img class="h-8 w-8 tradebyte-logo " src="../images/TradeByte-Favicon.png" alt="Logo">
</div>
<h4 class="font-bold text-center pt-1">
<a href="/"
class="hover:text-gray-900 tracking-widest text-2xl md:text-2xl lg:text-3xl tradebyte-logo">Tradebyte</a>
</h4>
<button class="rounded-lg md:hidden rounded-lg focus:outline-none focus:shadow-outline" @click="open = !open">
<svg fill="currentColor" viewBox="0 0 20 20" class="w-6 h-6">
<path x-show="!open" fill-rule="evenodd"
d="M3 5a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM3 10a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM9 15a1 1 0 011-1h6a1 1 0 110 2h-6a1 1 0 01-1-1z"
clip-rule="evenodd"></path>
<path x-show="open" 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>
</svg>
</button>

</div>


<nav :class="{'block': open, 'hidden': !open}" class="flex-grow md:block px-4 pb-4 md:pb-0">

<hr class="line mb-6">

<div class="flex justify-center align-center rounded-full">
<img class="h-16 w-16 border-8 user-profile box-1 rounded-full" src="<%= user.image %>" alt="" />
</div>

<a class="block w-2/5 md:w-4/5 max-w-xs p-2 mt-4 mb-8 mx-auto text-xs font-bold text-gray-900 focus:shadow-outline flex justify-center rounded-full text-green-900 font-bold tick-background"
href="#">
<div class="tick mr-1">
<svg class="w-5 mr-1 " fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
viewBox="0 0 24 24" stroke="currentColor">
<path d="M5 13l4 4L19 7"></path>
</svg>
</div> Trading Active
</a>

<div class="nav-box flex flex-col justify-start">

<a class="block px-4 py-2 mt-2 text-sm font-semibold text-gray-900 hover:text-blue-800 focus:text-blue-900 hover:bg-blue-100 focus:bg-blue-200 focus:outline-none focus:shadow-outline flex <%= href === '/portfolio' ? 'border tab-color 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
<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>
<button class="rounded-lg md:hidden rounded-lg focus:outline-none focus:shadow-outline" @click="open = !open">
<svg fill="currentColor" viewBox="0 0 20 20" class="w-6 h-6">
<path x-show="!open" fill-rule="evenodd"
d="M3 5a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM3 10a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM9 15a1 1 0 011-1h6a1 1 0 110 2h-6a1 1 0 01-1-1z"
clip-rule="evenodd"></path>
<path x-show="open" 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>
</svg>
</button>
</div>
<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>
<a class="block w-2/5 md:w-4/5 max-w-xs lg:w-3/5 p-2 mt-4 mb-8 mx-auto text-xs font-bold text-gray-900 focus:shadow-outline flex justify-center bg-green-200 rounded-full text-green-900 font-bold"
href="#"><svg class="w-5 mr-1 " fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
viewBox="0 0 24 24" stroke="currentColor">
<path d="M5 13l4 4L19 7"></path>
</svg>Trading Active</a>
<div class="nav-box 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 ">
<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>
Expand All @@ -76,7 +57,4 @@
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>
</svg>Logout</a>

</div>
</nav>
</div>
Loading

0 comments on commit 1977891

Please sign in to comment.