diff options
Diffstat (limited to 'server.js')
| -rw-r--r-- | server.js | 160 |
1 files changed, 135 insertions, 25 deletions
@@ -285,6 +285,24 @@ app.post('/logout', (req, res, next) => { // }); app.get('/profile', async (req, res, next) => { + let EntryCount = await EntryItem.countDocuments(); + let UserCount = await User.countDocuments(); + + let rawUptime = process.uptime(); + const date = new Date(rawUptime * 1000); + const days = date.getUTCDate() - 1, + hours = date.getUTCHours(), + minutes = date.getUTCMinutes(), + seconds = date.getUTCSeconds(), + milliseconds = date.getUTCMilliseconds(); + let segments = []; + if (days > 0) segments.push(days + ' day' + ((days == 1) ? '' : 's')); + if (hours > 0) segments.push(hours + ' hour' + ((hours == 1) ? '' : 's')); + if (minutes > 0) segments.push(minutes + ' minute' + ((minutes == 1) ? '' : 's')); + if (seconds > 0) segments.push(seconds + ' second' + ((seconds == 1) ? '' : 's')); + if (milliseconds > 0) segments.push(milliseconds + ' millisecond' + ((seconds == 1) ? '' : 's')); + const dateString = segments.join(', '); + User.findById(req.session.userId) .exec((error, user) => { if (error) { @@ -307,7 +325,10 @@ app.get('/profile', async (req, res, next) => { req: req, User: User, name: user.username, - quote: quotes.getRandomQuote() + quote: quotes.getRandomQuote(), + EntryCount: EntryCount, + UserCount: UserCount, + dateString: dateString }); } } @@ -355,30 +376,30 @@ app.get('/terms', (req, res) => { // }) // }); -app.get('/marketplace', (req, res) => { - User.findById(req.session.userId) - .exec((error, user) => { - if (error) { - return res.render('error', { - quote: quotes.getRandomQuote(), - errorMsg: 'Unknown error.' - }); - } else { - if (user === null) { - //let err = new Error('Not logged in!'); - return res.render('login', { - req: req, - User: User, - quote: quotes.getRandomQuote() - }); - //return err.status = 400; - //return next(err); - } else { - return res.redirect('/') - } - } - }) -}) +// app.get('/marketplace', (req, res) => { +// User.findById(req.session.userId) +// .exec((error, user) => { +// if (error) { +// return res.render('error', { +// quote: quotes.getRandomQuote(), +// errorMsg: 'Unknown error.' +// }); +// } else { +// if (user === null) { +// //let err = new Error('Not logged in!'); +// return res.render('login', { +// req: req, +// User: User, +// quote: quotes.getRandomQuote() +// }); +// //return err.status = 400; +// //return next(err); +// } else { +// return res.redirect('/') +// } +// } +// }) +// }) app.post('/closeExampleVideo', async (req, res) => { req.session.exampleVideo = false; @@ -489,6 +510,95 @@ app.post('/deleteItem/:id', (req, res) => { }) }) +app.get('/marketplace', async (req, res) => { + //const todoItems = await TodoItem.find(); + User.findById(req.session.userId) + .exec(async (error, user) => { + if (error) { + return res.render('error', { + quote: quotes.getRandomQuote(), + errorMsg: 'Unknown error.' + }); + } else { + if (user === null) { + //let err = new Error('Not logged in!'); + res.render('marketplace', { + req: req, + User: User, + name: null, + quote: quotes.getRandomQuote() + }); + //return err.status = 400; + //return next(err); + } else { + const entryItems = EntryItem; + const loop = await EntryItem.find({ + "type": "purchase", + user: user.username + }); + const loopCount = await EntryItem.find({ + "type": "purchase", + "user": user.username + }).countDocuments(); + + const loop2 = await EntryItem.find({ + "type": "sale", + "user": user.username + }); + const loop2Count = await EntryItem.find({ + "type": "sale", + "user": user.username + }).countDocuments(); + + const loop3 = await EntryItem.find({ + "type": "trade", + "user": user.username + }); + const loop3Count = await EntryItem.find({ + "type": "trade", + "user": user.username + }).countDocuments(); + + let EntryCount = await EntryItem.countDocuments(); + let UserCount = await User.countDocuments(); + + let rawUptime = process.uptime(); + const date = new Date(rawUptime * 1000); + const days = date.getUTCDate() - 1, + hours = date.getUTCHours(), + minutes = date.getUTCMinutes(), + seconds = date.getUTCSeconds(), + milliseconds = date.getUTCMilliseconds(); + let segments = []; + if (days > 0) segments.push(days + ' day' + ((days == 1) ? '' : 's')); + if (hours > 0) segments.push(hours + ' hour' + ((hours == 1) ? '' : 's')); + if (minutes > 0) segments.push(minutes + ' minute' + ((minutes == 1) ? '' : 's')); + if (seconds > 0) segments.push(seconds + ' second' + ((seconds == 1) ? '' : 's')); + if (milliseconds > 0) segments.push(milliseconds + ' millisecond' + ((seconds == 1) ? '' : 's')); + const dateString = segments.join(', '); + + return res.render('marketplace', { + req: req, + User: User, + name: user.username, + entryItems: entryItems, + user: user, + loop: loop, + loopCount: loopCount, + loop2: loop2, + loop2Count: loop2Count, + loop3: loop3, + loop3Count: loop3Count, + EntryCount: EntryCount, + UserCount: UserCount, + dateString: dateString, + quote: quotes.getRandomQuote() + }); + } + } + }); +}); + app.get('*', (req, res) => { res.redirect('/') }) |