Skip to content

Commit

Permalink
Solo cert page updates
Browse files Browse the repository at this point in the history
  • Loading branch information
tomcoombs2000 committed Jan 27, 2024
1 parent 8034fe7 commit ff65dc9
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 3 deletions.
28 changes: 25 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,37 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch via NPM",
"request": "launch",
"runtimeArgs": [
"run-script",
"debug"
],
"runtimeExecutable": "npm",
"skipFiles": [
"<node_internals>/**"
],
"type": "node"
},
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}"
},
{
"type": "node-terminal",
"name": "JavaScript Debug Terminal",
"request": "launch",
"cwd": "${workspaceFolder}"
},
{
"type": "node-terminal",
"name": "JavaScript Debug Terminal",
"request": "launch",
"cwd": "${workspaceFolder}"
}
]
}
94 changes: 94 additions & 0 deletions controllers/TrainingController.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,100 @@ router.delete('/request/:id', getUser, async (req, res) => {
return res.json(res.stdRes);
});

router.get('/solo', getUser,
//auth(['atm', 'datm', 'ta', 'ins', 'mtr', 'wm']),
async (req, res) => {
try {
const users = await User.find({vis: false, cid: { "$nin": [995625] }}).select('-email -idsToken -discordInfo').sort({
rating: 'desc',
lname: 'asc',

fname: 'asc'
}).populate({
path: 'certifications',
options: {
sort: {order: 'desc'}
}
}).lean({virtuals: true});

const certed = {
users: []
}

users.forEach(user => {
const hasTwrsCert = user.certifications.some(cert => cert.code === 'twrs');
if (hasTwrsCert) {
certed.users.push(user);
}
});

res.stdRes.data = certed;
} catch(e) {
req.app.Sentry.captureException(e);
res.stdRes.ret_det = e;
}

return res.json(res.stdRes);
});

router.post('/solo/:id', getUser,
//auth(['atm', 'datm', 'ta', 'ins', 'mtr', 'wm']),
async (req, res) => {
try {
const updateUser = await User.findOne({cid: req.params.id }).select('-email -idsToken -discordInfo').lean({virtuals: true});

const pos = req.body.position.slice(-3);
if (pos==="TWR")
updateUser.certCodes.push('twrs');
else if (pos==='APP')
updateUser.certCodes.push('apps');
else if (pos==='CTR')
updateUser.certCodes.push('miazmas')

await User.findOneAndUpdate({cid: req.params.id}, {
certCodes: updateUser.certCodes,
towersoloExpiration: req.body.expDate
});
return res.json(res.stdRes);
} catch(e) {
req.app.Sentry.captureException(e);
res.stdRes.ret_det = e;
}

return res.json(res.stdRes);
});

router.post('/solodelete/:id', getUser,
//auth(['atm', 'datm', 'ta', 'ins', 'mtr', 'wm']),
async (req, res) => {
try {
const updateUser = await User.findOne({cid: req.params.id }).select('-email -idsToken -discordInfo').lean({virtuals: true});

const pos = req.body.position.slice(-3);
var indexToDelete;
// Find the index of 'twrs' in the array

if (pos === 'TWR') indexToDelete = updateUser.certCodes.indexOf('twrs');
else if (pos === 'APP') indexToDelete = updateUser.certCodes.indexOf('apps');
else if (pos === 'CTR') indexToDelete = updateUser.certCodes.indexOf('miazmas');

// Check if index is found in the array
if (indexToDelete !== -1)
updateUser.certCodes.splice(indexToDelete, 1);

await User.findOneAndUpdate({cid: req.params.id}, {
certCodes: updateUser.certCodes,
towersoloExpiration: ''
});
return res.json(res.stdRes);
} catch(e) {
req.app.Sentry.captureException(e);
res.stdRes.ret_det = e;
}

return res.json(res.stdRes);
});

router.get('/request/:date', getUser, auth(['atm', 'datm', 'ta', 'ins', 'mtr', 'wm']), async (req, res) => {
try {
const d = new Date(`${req.params.date.slice(0,4)}-${req.params.date.slice(4,6)}-${req.params.date.slice(6,8)}`);
Expand Down
1 change: 1 addition & 0 deletions models/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const userSchema = new m.Schema({
},
idsToken: String,
certCodes: [],
towersoloExpiration: Date,
roleCodes: [],
trainingMilestones: [{
type: m.Schema.Types.ObjectId, ref: 'TrainingMilestone'
Expand Down

0 comments on commit ff65dc9

Please sign in to comment.