Skip to content

Commit

Permalink
Resolved conflicts #46
Browse files Browse the repository at this point in the history
  • Loading branch information
fabcodingzest committed Aug 24, 2020
2 parents 1d74bd2 + 11bdf9e commit bbe7f75
Show file tree
Hide file tree
Showing 19 changed files with 697 additions and 532 deletions.
50 changes: 26 additions & 24 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -81,12 +81,13 @@ 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
Expand All @@ -103,12 +104,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}`)
);
28 changes: 28 additions & 0 deletions models/Transaction.js
Original file line number Diff line number Diff line change
@@ -1 +1,29 @@
// Adding / Spending Balance History

const mongoose = require("mongoose");
var Float = require("mongoose-float").loadType(mongoose);

const TransactionSchema = new mongoose.Schema({
details: {
type: String,
required: true,
},
amount: {
type: Float,
required: true,
},
opration: {
type: String,
required: true
},
user: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
},
createdAt: {
type: Date,
default: Date.now,
},
});

module.exports = mongoose.model("Transaction", TransactionSchema);
2 changes: 1 addition & 1 deletion public/css/style.css

Large diffs are not rendered by default.

110 changes: 87 additions & 23 deletions public/css/tailwind.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,104 @@

html,
body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
overflow-x: hidden;
box-sizing: border-box;
background-color: rgb(226, 232, 240);
margin: 0;
padding: 0;
width: 100%;
height: 100%;
overflow-x: hidden;
box-sizing: border-box;
background-color: rgb(226, 232, 240);
}

.chartjs-container {
position: relative;
margin: auto;
height: 75vh;
width: 75vw;
position: relative;
margin: auto;
height: 75vh;
width: 75vw;
}

.tradebyte-logo {
color: #1955e4;
text-shadow: 1px 2px 40px rgba(0, 0, 0, 0.5);
}

.line {
border: 1.5px solid #8e9aad;
}

.user-profile {
border-radius: 100px;
border: 10px solid #1955e4;
width: 130px;
height: 130px;
}

.tick {
height: 22px;
width: 22px;
border-radius: 50%;
background-color: #38cda0;
color: white;
}

.tick-background {
background: #a9f7e6;
border-radius: 29px;
color: #1b9b7f;
}

.tab-color {
border-radius: 10px;
border-color: #1955e4;
color: #1955e4;
}

.view-link {
color: #1955e4;
}

.view-link:hover {
color: #0d338a;
}

.button {
background-color: #1955e4;
}

.button:hover {
background-color: #0d338a;
}

.table-content {
overflow: scroll;
overflow-x: scroll;
overflow-y: auto;
}

.transaction-companySymbol {
color: rgb(0, 0, 0);
font-weight: 700;
font-size: 1.1rem;
}

@tailwind components;

.symbolicon {
font-size: 72px;
background: -webkit-linear-gradient(#eee, #333);
background-clip: text;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
font-size: 72px;
background: -webkit-linear-gradient(#eee, #333);
background-clip: text;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}

.min-w{
min-width: 400px;
.min-w {
min-width: 400px;
}

@media (max-width:400px){
.min-w{
min-width: 300px;
}
@media (max-width: 400px) {
.min-w {
min-width: 300px;
}
}

@tailwind utilities;
@tailwind utilities;
2 changes: 1 addition & 1 deletion public/javascript/script.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Main Script

console.log("Hello TradeByte!");
console.log("Hello TradeByte!");
18 changes: 16 additions & 2 deletions routes/api/addBalance.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const express = require("express");
const router = express.Router();
const { ensureAuth, ensureGuest } = require("../../middleware/auth");
const User = require("../../models/User");
const Transaction = require("../../models/Transaction");

// @desc // Add Balance page
// @route GET /
Expand All @@ -26,6 +27,8 @@ router.post("/", ensureAuth, async (req, res) => {
let finalAmont = amount + req.user.balance;

try {

// Updating balance to user's schema.
req.body.user = req.user.id;
const updateBalance = await User.findOneAndUpdate(
{ _id: req.user.id },
Expand All @@ -35,8 +38,19 @@ router.post("/", ensureAuth, async (req, res) => {
runValidators: true, // it check weather the fields are valid or not
}
);
console.log(updateBalance);
res.redirect("/");
// 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,
});

console.log(updateTransactoin);
res.redirect("/done");
} catch (err) {
console.error(err);
res.render("error/500");
Expand Down
30 changes: 21 additions & 9 deletions routes/api/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,40 @@ router.get("/:symbol", ensureAuth, async (req, res) => {
// @desc To buy
// @route POST /cart/buy
router.post("/buy", ensureAuth, async (req, res) => {
let data = req.body;
let user = req.user;
let stockPrice = data.stockPrice;
let noOfStock = data.noOfStock;
let totalAmount = parseFloat(stockPrice * noOfStock).toFixed(4);
const user = req.user;
const symbol = req.body.companySymbol;
const { latestPrice } = await getPrice(symbol);
const noOfStock = req.body.noOfStock;
const totalAmount = parseFloat(latestPrice * noOfStock).toFixed(4);

const data = {
companySymbol: symbol,
stockPrice: latestPrice,
noOfStock: noOfStock,
totalAmount: totalAmount,
};

console.log(data);

try {
if (totalAmount > req.user.balance) {
let ExtraBalance = totalAmount - req.user.balance;
res.render("transaction", {
data,
totalAmount,

res.render("transaction/transaction", {
layout: "layouts/app",
href: "/buy",
ExtraBalance,
message: "Insufficent Balance",
});
} else {
res.render("transaction", {
res.render("transaction/transaction", {
data,
user,
totalAmount,
stockPrice,
message: "Order Review",
layout: "layouts/app",
href: "/buy",
});
}
} catch (err) {
Expand Down
10 changes: 9 additions & 1 deletion routes/api/portfolio.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@ 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;
let avatar = req.user.image;
res
.status(200)
.render("portfolio", { layout: "layouts/app", avatar, href: "/portfolio" });
.render("portfolio", {
layout: "layouts/app",
avatar,
totalData,
href: "/portfolio",
});
});

module.exports = router;
20 changes: 20 additions & 0 deletions routes/api/search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// search Routes

const express = require("express");
const router = express.Router();
const { ensureAuth, ensureGuest } = require("../../middleware/auth");

const totalData = require("../../config/data-total.json");

router.get("/", ensureAuth, (req, res) => {
let avatar = req.user.image;

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

module.exports = router;
Loading

0 comments on commit bbe7f75

Please sign in to comment.