diff --git a/.dockerignore b/.dockerignore index 5171c54..8e480e4 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,3 @@ node_modules -npm-debug.log \ No newline at end of file +npm-debug.log +.env \ No newline at end of file diff --git a/controllers/ControllerController.js b/controllers/ControllerController.js index 810460d..bdc1822 100644 --- a/controllers/ControllerController.js +++ b/controllers/ControllerController.js @@ -104,11 +104,11 @@ router.get("/staff", async (req, res) => { lname: "asc", fname: "asc", }) /*.populate({ - path: 'roles', - options: { - sort: {order: 'asc'} - } - })*/ + path: 'roles', + options: { + sort: {order: 'asc'} + } + })*/ .lean(); if (!users) { @@ -859,6 +859,7 @@ router.put( }) .promise(); + await User.findOneAndUpdate( { cid: req.params.cid }, { @@ -872,6 +873,25 @@ router.put( } ); + const updated = await User.findOneAndUpdate( + { cid: req.params.cid }, + { + fname, + lname, + email, + oi, + vis, + roleCodes: toApply.roles, + certCodes: toApply.certifications, + }, + { new: true } + ).lean(); + + console.log("updated user found:", !!updated); + console.log("updated certCodes:", updated?.certCodes); + console.log("updated roleCodes:", updated?.roleCodes); + + await req.app.dossier.create({ by: res.user.cid, affected: req.params.cid, @@ -1010,4 +1030,4 @@ const random = (str, len) => { return ret; }; -export default router; +export default router; \ No newline at end of file diff --git a/controllers/UserController.js b/controllers/UserController.js index 1dfa3a6..e41bf3f 100644 --- a/controllers/UserController.js +++ b/controllers/UserController.js @@ -96,6 +96,8 @@ router.post("/idsToken", getUser, async (req, res) => { return res.json(res.stdRes); }); + + // Endpoint to preform user login, uses oAuth middleware to retrieve an access token router.post("/login", oAuth, async (req, res) => { try { @@ -440,4 +442,4 @@ router.put("/profile", getUser, async (req, res) => { return res.json(res.stdRes); }); -export default router; +export default router; \ No newline at end of file diff --git a/models/User.js b/models/User.js index 72817f4..b2d39cd 100644 --- a/models/User.js +++ b/models/User.js @@ -56,46 +56,47 @@ userSchema.plugin(softDelete, { userSchema.plugin(mlv); -userSchema.virtual('isMem').get(function() { +userSchema.virtual('isMem').get(function () { return !!this.member; }); -userSchema.virtual('isMgt').get(function() { - if(!this.roleCodes) return false; +userSchema.virtual('isMgt').get(function () { + if (!this.roleCodes) return false; const search = ['atm', 'datm']; return this.roleCodes.some(r => search.includes(r)); }); -userSchema.virtual('isSenior').get(function() { - if(!this.roleCodes) return false; +userSchema.virtual('isSenior').get(function () { + if (!this.roleCodes) return false; const search = ['atm', 'datm', 'ta']; return this.roleCodes.some(r => search.includes(r)); }); -userSchema.virtual('isStaff').get(function() { - if(!this.roleCodes) return false; - const search = ['atm', 'datm', 'ta', 'ec', 'wm', 'fe']; +userSchema.virtual('isStaff').get(function () { + if (!this.roleCodes) return false; + const search = ['atm', 'datm', 'ta', 'ec', 'wm', 'fe',]; return this.roleCodes.some(r => search.includes(r)); }); -userSchema.virtual('isIns').get(function() { - if(!this.roleCodes) return false; +userSchema.virtual('isIns').get(function () { + if (!this.roleCodes) return false; const search = ['atm', 'datm', 'ta', 'ins', 'mtr']; return this.roleCodes.some(r => search.includes(r)); }); -userSchema.virtual('ratingShort').get(function() { +userSchema.virtual('ratingShort').get(function () { return zab.ratings[this.rating]; }); -userSchema.virtual('ratingLong').get(function() { +userSchema.virtual('ratingLong').get(function () { return zab.ratingsLong[this.rating]; }); -userSchema.virtual('roles', { - ref: 'Role', - localField: 'roleCodes', - foreignField: 'code' +userSchema.virtual("roles", { + ref: "Role", + localField: "roleCodes", + foreignField: "code", + justOne: false, }); userSchema.virtual('certifications', { diff --git a/seeds/certifications.json b/seeds/certifications.json index 82e2fec..cb61685 100644 --- a/seeds/certifications.json +++ b/seeds/certifications.json @@ -1,49 +1,68 @@ [ -{ - "name": "KPHX GND", - "code": "kphxground", - "order": 4, - "class": "tier-one" -}, -{ - "name": "KPHX TWR", - "code": "kphxtower", - "order": 3, - "class": "tier-one" -}, -{ - "name": "P50", - "code": "p50", - "order": 2, - "class": "tier-one" -}, -{ - "name": "Enroute", - "code": "enroute", - "order": 1, - "class": "tier-one" -}, -{ - "name": "KABQ", - "code": "kabq", - "order": 1, - "class": "tier-two" -}, -{ - "name": "KFLG", - "code": "kflg", - "order": 2, - "class": "tier-two" -}, -{ - "name": "KLUF", - "code": "kluf", - "order": 3, - "class": "tier-two" -}, -{ - "name": "KSAF", - "code": "ksaf", - "order": 4, - "class": "tier-two" -}] \ No newline at end of file + { + "name": "KPHX GND", + "code": "kphxground", + "order": 4, + "class": "tier-one" + }, + { + "name": "KPHX TWR", + "code": "kphxtower", + "order": 3, + "class": "tier-one" + }, + { + "name": "P50", + "code": "p50", + "order": 2, + "class": "tier-one" + }, + { + "name": "Enroute", + "code": "enroute", + "order": 1, + "class": "tier-one" + }, + { + "name": "KABQ", + "code": "kabq", + "order": 1, + "class": "tier-two" + }, + { + "name": "KFLG", + "code": "kflg", + "order": 2, + "class": "tier-two" + }, + { + "name": "KLUF", + "code": "kluf", + "order": 3, + "class": "tier-two" + }, + { + "name": "KSAF", + "code": "ksaf", + "order": 4, + "class": "tier-two" + }, + { + "name": "Local Data", + "code": "CPALocal", + "order": 1, + "class": "cpa" + }, + { + "name": "Terminal Data", + "code": "CPATerminal", + "order": 2, + "class": "cpa" + }, + { + "name": "Enroute Data", + "code": "CPAEnroute", + "order": 3, + "class": "cpa" + } +] \ No newline at end of file diff --git a/seeds/roles.json b/seeds/roles.json index ffb26fc..2bd9a17 100644 --- a/seeds/roles.json +++ b/seeds/roles.json @@ -1,41 +1,56 @@ -[{ - "name": "Air Traffic Manager", - "code": "atm", - "order": 1, - "class": "senior" -},{ - "name": "Deputy Air Traffic Manager", - "code": "datm", - "order": 2, - "class": "senior" -},{ - "name": "Training Administrator", - "code": "ta", - "order": 3, - "class": "senior" -},{ - "name": "Events Coordinator", - "code": "ec", - "order": 4, - "class": "junior" -},{ - "name": "Webmaster", - "code": "wm", - "order": 5, - "class": "junior" -},{ - "name": "Facilities Engineer", - "code": "fe", - "order": 6, - "class": "junior" -},{ - "name": "Instructor", - "code": "ins", - "order": 7, - "class": "training" -},{ - "name": "Mentor", - "code": "mtr", - "order": 8, - "class": "training" -}] \ No newline at end of file +[ + { + "name": "Air Traffic Manager", + "code": "atm", + "order": 1, + "class": "senior" + }, + { + "name": "Deputy Air Traffic Manager", + "code": "datm", + "order": 2, + "class": "senior" + }, + { + "name": "Training Administrator", + "code": "ta", + "order": 3, + "class": "senior" + }, + { + "name": "Events Coordinator", + "code": "ec", + "order": 4, + "class": "junior" + }, + { + "name": "Webmaster", + "code": "wm", + "order": 5, + "class": "junior" + }, + { + "name": "Facilities Engineer", + "code": "fe", + "order": 6, + "class": "junior" + }, + { + "name": "Instructor", + "code": "ins", + "order": 7, + "class": "training" + }, + { + "name": "Mentor", + "code": "mtr", + "order": 8, + "class": "training" + }, + { + "name": "Combined Monitor", + "code": "cm", + "order": 9, + "class": "training" + } +] \ No newline at end of file