Skip to content

Commit

Permalink
Merge pull request #57 from iampavangandhi/fix/#28
Browse files Browse the repository at this point in the history
Fix/#44
  • Loading branch information
iampavangandhi authored Aug 24, 2020
2 parents 6926451 + ac52fb8 commit 351b9a7
Show file tree
Hide file tree
Showing 8 changed files with 330 additions and 220 deletions.
49 changes: 25 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,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
Expand All @@ -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}`)
);
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!");
65 changes: 33 additions & 32 deletions routes/api/market.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
19 changes: 8 additions & 11 deletions routes/api/portfolio.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
28 changes: 28 additions & 0 deletions routes/api/search.js
Original file line number Diff line number Diff line change
@@ -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;
Loading

0 comments on commit 351b9a7

Please sign in to comment.