Skip to content

Commit

Permalink
backend-outlays
Browse files Browse the repository at this point in the history
  • Loading branch information
GO-viper7 committed Sep 22, 2022
1 parent f02c2db commit 64df518
Show file tree
Hide file tree
Showing 13 changed files with 383 additions and 98 deletions.
10 changes: 8 additions & 2 deletions controllers/userController.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const mails = require('../mailIds.json')
const jwt = require('jsonwebtoken')
const nodeMailer = require('nodemailer')
const categorySchema = require('../schemas/category-schema');
const notificationSchema = require('../schemas/notification-schema')
const DiscordOauth2 = require("discord-oauth2");
const oauth = new DiscordOauth2({
clientId: process.env.clientId,
Expand Down Expand Up @@ -73,7 +74,7 @@ const getProfile = async (req, res, next) => {
let cookies = req.cookies.get('key')
let result = await categorySchema.find({})
if (cookies == undefined) {
return res.status(200).render('shop', {prod: req.products, prof: '', url: process.env.discordURI, user: '', coins: '', bool: '', inv: '', cats: result, unique: '', products: ''})
return res.status(200).render('shop', {prod: req.products, prof: '', url: process.env.discordURI, user: '', coins: '', bool: '', inv: '', cats: result, unique: '', products: '',notifs: []})
}
else {
next()
Expand Down Expand Up @@ -102,7 +103,10 @@ const getVerified = async (req, res, next) => {
return res.redirect('/logout')
}
else {
return res.render('shop', {prod: req.products, user: user, id : user.id, url: process.env.discordURI, coins: data.OctaCreds, prof: JSON.stringify(data), bool: '', ids: users, cats: result, unique: JSON.stringify(uniquePremItems), products: JSON.stringify(req.products)})
const notifRes = await notificationSchema.find({userId: user.id})
let notif = notifRes.reverse()
console.log(notif)
return res.render('shop', {prod: req.products, user: user, id : user.id, url: process.env.discordURI, coins: data.OctaCreds, prof: JSON.stringify(data), bool: '', ids: users, cats: result, unique: JSON.stringify(uniquePremItems), products: JSON.stringify(req.products), notifs: notif})
}
})
}catch (err) {
Expand Down Expand Up @@ -187,9 +191,11 @@ const buyProduct = async (req, res, next) => {
}
})
let arr = await profileSchema.findOne({userId: user.id})
const date = new Date()
await new itemSchema({
id: req.body.id,
userId: user.id,
date: `test`,
orderId: crypto.randomBytes(10).toString("hex"),
userName: `${user.username}#${user.discriminator}`,
cost: req.body.cost,
Expand Down
Binary file added public/assets/1663557681036coin.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 15 additions & 2 deletions public/css/inventory.css
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@

.wl-image{
border-radius: 10px;
width: 100%;
width: 200px;
height: 200px;
}

.claim {
Expand All @@ -143,6 +144,17 @@
border-radius: 30px;
}

.innerPanel::-webkit-scrollbar {
background: var(--sidebar);
border-radius: 30px;
height: 5px;
width: 5px;
}

.innerPanel::-webkit-scrollbar-thumb{
background: #7182FF;
border-radius: 30px;
}


/* responsive profile details */
Expand Down Expand Up @@ -172,7 +184,8 @@

.wl-image{
border-radius: 10px;
width: 100%;
width: 200px;
height: 200px;
}


Expand Down
21 changes: 18 additions & 3 deletions public/css/shop.css
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,10 @@
}

.rows {
margin-top: 20px;
padding-bottom: 100px;
width: 100%;
overflow: auto;
grid-column-end: 3;
grid-column-start: 1;
}

.detail{
Expand Down Expand Up @@ -140,7 +142,20 @@

.rows-wrapper::-webkit-scrollbar-thumb{
background: #7182FF;
border-radius: 30px;}
border-radius: 30px;
}

.innerPanel::-webkit-scrollbar {
background: var(--sidebar);
border-radius: 30px;
height: 5px;
width: 5px;
}

.innerPanel::-webkit-scrollbar-thumb{
background: #7182FF;
border-radius: 30px;
}


.homePageColumn{
Expand Down
11 changes: 9 additions & 2 deletions routes/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ router.post('/', upload.single('file'), async (req, res, next) => {
}
else {
try {
console.log('went to buy')
console.log('went to fk')
let user = await oauth.getUser(jwt.verify(req.cookies.get('key'), process.env.jwtSecret))
profileSchema.findOneAndUpdate({userId: user.id}, {OctaCreds : req.body.cost}, null, async (err, data) => {
if (err) {
Expand All @@ -90,10 +90,17 @@ router.post('/', upload.single('file'), async (req, res, next) => {
}
})
let arr = await profileSchema.findOne({userId: user.id})
const date = new Date()
let hexId = crypto.randomBytes(4).toString("hex")
// while(itemSchema.findOne({orderId: hexId}) != undefined) {
// hexId = crypto.randomBytes(4).toString("hex")
// }
await new itemSchema({
id: req.body.id,
userId: user.id,
orderId: crypto.randomBytes(10).toString("hex"),
userAvatar: user.avatar,
orderId: hexId,
date: `${date.getDate()}.${date.getMonth()}.${date.getFullYear()}`,
userName: `${user.username}#${user.discriminator}`,
cost: req.body.cost,
itemName: req.body.name.trim(),
Expand Down
69 changes: 55 additions & 14 deletions routes/inventory.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const oauth = new DiscordOauth2({
redirectUri: `${process.env.websiteURL}/discord`,
});
const categorySchema = require('../schemas/category-schema');
const profileSchema = require('../schemas/profile-schema')
const profileSchema = require('../schemas/profile-schema');
const notificationSchema = require('../schemas/notification-schema')

router.get('/inventory', async (req, res, next) => {
let p
Expand All @@ -25,32 +26,72 @@ router.get('/inventory', async (req, res, next) => {
return res.render('inventory', {filled: "false", prod: [], bool: false, user: '', cats: await categorySchema.find({})});
}
if (req.cookies.get('inv-cat') == undefined) {
k = result.filter(x => x.category == x.category)
p = k.filter(q => q.order == (`${req.cookies.get('fill')}` == 'false' ? false : true))
k = result
p = k
}
else {
k = result.filter(x => x.category == (`${req.cookies.get('inv-cat')}` == 'cat' ? x.category : `${req.cookies.get('inv-cat')}`) )
p = k.filter(q => q.order == (`${req.cookies.get('fill')}` === 'false' ? false : true))
k = result
p = k
}
res.render('inventory', {profile: await profileSchema.findOne({userId: user.id}), filled: fill,prod: p, bool: true, user: user, cats: await categorySchema.find({})});
const notifRes = await notificationSchema.find({userId: user.id})
let notif = notifRes.reverse()
res.render('inventory', {profile: await profileSchema.findOne({userId: user.id}), filled: fill,prod: p, bool: true, user: user, cats: await categorySchema.find({}), notifs: notif});
});

router.get('/admin/orders', async (req, res, next) => {
let l
let cookies = req.cookies.get('key')
let user = await oauth.getUser(jwt.verify(cookies, process.env.jwtSecret))
let result = await itemSchema.find({})
res.render('orders', {prod: result, bool: true, user: user});
let result = await itemSchema.find({order: false})
let revRes = result.reverse()
res.render('orders', {prod: revRes, bool: true, user: user, title: 'Pending Orders'});
})

router.get('/admin/orders/fulfil', async (req, res, next) => {
let l
let cookies = req.cookies.get('key')
let user = await oauth.getUser(jwt.verify(cookies, process.env.jwtSecret))
let result = await itemSchema.find({order: true})
let revRes = result.reverse()
res.render('orders', {prod: revRes, bool: true, user: user, title: 'FulFilled Orders'});
})


router.post('/admin/orders', async (req, res, next) => {
itemSchema.findOneAndUpdate({orderId: req.body.orderId}, {$set: {order: req.body.fill == "filled" ? true : false}}, function(err, doc) {
if(err) {
console.log(err.message)
}
res.redirect('/admin/add-product/orders')
})
let cookies = req.cookies.get('key')
let user = await oauth.getUser(jwt.verify(cookies, process.env.jwtSecret))
let result = await itemSchema.findOne({orderId: req.body.orderId})
if(req.body.status == "true") {
await new notificationSchema({
userId: user.id,
notification: `Your order for ${result.itemName} under ${result.category} has been fulfilled`,
time: Date.now()
}).save()
itemSchema.findOne({orderId: `${req.body.orderId}`}, async (err, doc) => {
if (err) throw err;
if (doc) {
console.log(doc)
doc.order = true
doc.save()
}
})
}
else if (req.body.status == "false") {
await new notificationSchema({
userId: user.id,
notification: `Your order for ${result.itemName} under ${result.category} has been queued for pending`,
time: Date.now()
}).save()
itemSchema.findOne({orderId: `${req.body.orderId}`}, async (err, doc) => {
if (err) throw err;
if (doc) {
console.log(doc)
doc.order = false
doc.save()
}
})
}

})

module.exports = router;
5 changes: 4 additions & 1 deletion routes/profile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const express = require('express');
const router = express.Router();
const profileSchema = require('../schemas/profile-schema');
const notificationSchema = require('../schemas/notification-schema');
const DiscordOauth2 = require("discord-oauth2");
require("dotenv").config();
const jwt = require('jsonwebtoken')
Expand All @@ -17,7 +18,9 @@ const oauth = new DiscordOauth2({
router.get('/settings', async (req, res, next) => {
try {
const user = await oauth.getUser(jwt.verify(req.cookies.get('key'), process.env.jwtSecret))
res.render('settings', {user: user, profile: await profileSchema.findOne({userId: user.id})})
const notifRes = await notificationSchema.find({userId: user.id})
let notif = notifRes.reverse()
res.render('settings', {user: user, profile: await profileSchema.findOne({userId: user.id}), notifs: notif})
}catch(err) {
console.log(err)
return res.redirect('/logout')
Expand Down
7 changes: 7 additions & 0 deletions schemas/item-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@ const itemSchema = mongoose.Schema({
userId: {
type: String,
},
userAvatar: {
type: String
},
orderId: {
type: String,
},
id : {
type: Number,
},
date: {
type: String,
},
userName: {
type: String,
},
Expand All @@ -37,6 +43,7 @@ const itemSchema = mongoose.Schema({
},
order: {
type: Boolean,
default: false
},
wallet: {
type: String
Expand Down
16 changes: 16 additions & 0 deletions schemas/notification-schema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const mongoose = require('mongoose')

const notificationSchema = mongoose.Schema({

userId: {
type: String
},
notification: {
type: String
},
time: {
type: Number
}
})

module.exports = mongoose.model('notifs', notificationSchema)
35 changes: 32 additions & 3 deletions views/inventory.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,27 @@
<!-- addon, this makes the background darker when a panel is open-->
<div class="addon"></div>


<div class="panels">
<!-- notification Panel -->
<div class="buyPanel" id="notifPanel">
<p >Notifications</p>
<div class="innerPanel" style="overflow-y: scroll; height: 320px">


<div class="panelBar" ></div>

<% var i =0 %>
<% notifs.forEach(y => { i++; %>
<%= y.notification %>
<br>
<% }) %>
<div class="panelBar"></div>
</div>
<div class="buyButtons">
<button class="buttons no" id="notifClose">Close</button>
</div>
</div>
</div>

<div class="wrapper">
<div class="left-menu">
Expand Down Expand Up @@ -52,10 +72,10 @@
<div class="right-menu rightMenuPadding">
<div class="top-part topPartInventory">
<div class="icons">
<a href="/inventory/inventory.html">
<a href="/inventory">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M10 19.5c0 .829-.672 1.5-1.5 1.5s-1.5-.671-1.5-1.5c0-.828.672-1.5 1.5-1.5s1.5.672 1.5 1.5zm3.5-1.5c-.828 0-1.5.671-1.5 1.5s.672 1.5 1.5 1.5 1.5-.671 1.5-1.5c0-.828-.672-1.5-1.5-1.5zm6.305-15l-3.432 12h-10.428l-2.937-7h11.162l-1.412 5h2.078l1.977-7h-16.813l4.615 11h13.239l3.474-12h1.929l.743-2h-4.195z"/></svg>
</a>
<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg" fill-rule="evenodd" clip-rule="evenodd"><path d="M1 20v-2.946c1.993-.656 2.575-2.158 3.668-6.077.897-3.218 1.891-6.784 4.873-8.023-.027-.147-.041-.299-.041-.454 0-1.38 1.12-2.5 2.5-2.5s2.5 1.12 2.5 2.5c0 .156-.014.309-.042.458 2.987 1.244 3.984 4.813 4.884 8.033 1.103 3.95 1.697 5.423 3.658 6.062v2.947h-7c0 2.208-1.792 4-4 4s-4-1.792-4-4h-7zm14 0h-6c0 1.656 1.344 3 3 3s3-1.344 3-3zm-13-1h20v-1.241c-2.062-.918-2.82-3.633-3.621-6.498-1.066-3.814-2.167-7.758-6.379-7.761-4.21 0-5.308 3.937-6.369 7.745-.8 2.872-1.559 5.593-3.631 6.514v1.241zm11.492-16.345l.008-.155c0-.828-.672-1.5-1.5-1.5s-1.5.672-1.5 1.5l.008.152c.455-.099.949-.152 1.487-.152.542 0 1.039.054 1.497.155z"/></svg>
<svg id="notif" style="cursor:pointer" width="24" height="24" xmlns="http://www.w3.org/2000/svg" fill-rule="evenodd" clip-rule="evenodd"><path d="M1 20v-2.946c1.993-.656 2.575-2.158 3.668-6.077.897-3.218 1.891-6.784 4.873-8.023-.027-.147-.041-.299-.041-.454 0-1.38 1.12-2.5 2.5-2.5s2.5 1.12 2.5 2.5c0 .156-.014.309-.042.458 2.987 1.244 3.984 4.813 4.884 8.033 1.103 3.95 1.697 5.423 3.658 6.062v2.947h-7c0 2.208-1.792 4-4 4s-4-1.792-4-4h-7zm14 0h-6c0 1.656 1.344 3 3 3s3-1.344 3-3zm-13-1h20v-1.241c-2.062-.918-2.82-3.633-3.621-6.498-1.066-3.814-2.167-7.758-6.379-7.761-4.21 0-5.308 3.937-6.369 7.745-.8 2.872-1.559 5.593-3.631 6.514v1.241zm11.492-16.345l.008-.155c0-.828-.672-1.5-1.5-1.5s-1.5.672-1.5 1.5l.008.152c.455-.099.949-.152 1.487-.152.542 0 1.039.054 1.497.155z"/></svg>
<a href="#">
<img src="https://cdn.discordapp.com/avatars/<%= user.id %>/<%= user.avatar %>.png" class="img-profile"/>
</a>
Expand Down Expand Up @@ -217,8 +237,17 @@

<script src="/js/shop.js"></script>
<script>
const backg = document.querySelector(".addon");
let p = 0
document.getElementById('notif').addEventListener("click", () => {
backg.style.display = "block";
document.getElementById("notifPanel").style.display = "block"
})
document.getElementById('notifClose').addEventListener("click", () => {
backg.style.display = "none";
document.getElementById("notifPanel").style.display = "none"
})
for(var j =0; j<`<%- prod.length %>`; j++) { ( function() {
p++;
var t = p
Expand Down
Loading

0 comments on commit 64df518

Please sign in to comment.