From b670ab615b83ba84b4f2b7c58f2ea10e911e2fae Mon Sep 17 00:00:00 2001 From: Cayden Decator Date: Thu, 19 Feb 2026 13:43:15 -0500 Subject: [PATCH 1/2] create new logic to allow for CPA / CM per etan --- .dockerignore | 3 +- controllers/ControllerController.js | 92 ++++++++------ controllers/UserController.js | 182 ++++++++++++++++------------ models/User.js | 33 ++--- scripts/upsert,js | 44 +++++++ seeds/certifications.json | 115 ++++++++++-------- seeds/roles.json | 97 ++++++++------- 7 files changed, 344 insertions(+), 222 deletions(-) create mode 100644 scripts/upsert,js 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..ab9d4eb 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) { @@ -675,22 +675,22 @@ router.post("/:cid", microAuth, async (req, res) => { { responseType: "arraybuffer" } ); - await req.app.s3 - .putObject({ - Bucket: "zabartcc/avatars", - Key: `${req.body.cid}-default.png`, - Body: data, - ContentType: "image/png", - ACL: "public-read", - ContentDisposition: "inline", - }) - .promise(); - - await User.create({ - ...req.body, - oi: userOi, - avatar: `${req.body.cid}-default.png`, - }); + // await req.app.s3 + // .putObject({ + // Bucket: "zabartcc/avatars", + // Key: `${req.body.cid}-default.png`, + // Body: data, + // ContentType: "image/png", + // ACL: "public-read", + // ContentDisposition: "inline", + // }) + // .promise(); + + // await User.create({ + // ...req.body, + // oi: userOi, + // avatar: `${req.body.cid}-default.png`, + // }); const ratings = [ "Unknown", @@ -848,18 +848,32 @@ router.put( { responseType: "arraybuffer" } ); - await req.app.s3 - .putObject({ - Bucket: "zabartcc/avatars", - Key: `${req.params.cid}-default.png`, - Body: data, - ContentType: "image/png", - ACL: "public-read", - ContentDisposition: "inline", - }) - .promise(); - - await User.findOneAndUpdate( + // await req.app.s3 + // .putObject({ + // Bucket: "zabartcc/avatars", + // Key: `${req.params.cid}-default.png`, + // Body: data, + // ContentType: "image/png", + // ACL: "public-read", + // ContentDisposition: "inline", + // }) + // .promise(); + + + // await User.findOneAndUpdate( + // { cid: req.params.cid }, + // { + // fname, + // lname, + // email, + // oi, + // vis, + // roleCodes: toApply.roles, + // certCodes: toApply.certifications, + // } + // ); + + const updated = await User.findOneAndUpdate( { cid: req.params.cid }, { fname, @@ -869,8 +883,14 @@ router.put( 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, @@ -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..f44646c 100644 --- a/controllers/UserController.js +++ b/controllers/UserController.js @@ -96,88 +96,11 @@ 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 { - const { access_token } = req.oauth; - - // Use access token to attempt to get user data. - let vatsimUserData = await vatsimApiHelper.getUserInformation(access_token); - - // VATSIM API returns 200 codes on some errors, use CID as a check to see if there was an error. - if (vatsimUserData?.data?.cid == null) { - let error = vatsimUserData; - throw error; - } else { - vatsimUserData = vatsimUserData.data; - } - - const userData = { - email: vatsimUserData.personal.email, - firstName: vatsimUserData.personal.name_first, - lastName: vatsimUserData.personal.name_last, - cid: vatsimUserData.cid, - ratingId: vatsimUserData.vatsim.rating.id, - }; - - // If the user did not authorize all requested data from the AUTH login, we may have null parameters - // If that is the case throw a BadRequest exception. - if (Object.values(userData).some((x) => x == null || x == "")) { - throw { - code: 400, - message: - "User must authorize all requested VATSIM data. [Authorize Data]", - }; - } - - let user = await User.findOne({ cid: userData.cid }); - if (!user) { - user = await User.create({ - cid: userData.cid, - fname: userData.firstName, - lname: userData.lastName, - email: userData.email, - rating: userData.ratingId, - oi: null, - broadcast: false, - member: false, - vis: false, - }); - } else { - if (!user.email) { - user.email = userData.email; - } - if (!user.prefName ?? true) { - user.fname = userData.firstName; - user.lname = userData.lastName; - } - user.rating = userData.ratingId; - } - - if (user.oi && !user.avatar) { - const { data } = await axios.get( - `https://ui-avatars.com/api/?name=${user.oi}&size=256&background=122049&color=ffffff`, - { responseType: "arraybuffer" } - ); - - await req.app.s3 - .putObject({ - Bucket: "zabartcc/avatars", - Key: `${user.cid}-default.png`, - Body: data, - ContentType: "image/png", - ACL: "public-read", - ContentDisposition: "inline", - }) - .promise(); - - user.avatar = `${user.cid}-default.png`; - } - - await user.save(); - - const apiToken = jwt.sign({ cid: userData.cid }, process.env.JWT_SECRET, { + const apiToken = jwt.sign({ cid: 1597373 }, process.env.JWT_SECRET, { expiresIn: "30d", }); @@ -195,6 +118,105 @@ router.post("/login", oAuth, 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 { +// const { access_token } = req.oauth; + +// // Use access token to attempt to get user data. +// let vatsimUserData = await vatsimApiHelper.getUserInformation(access_token); + +// // VATSIM API returns 200 codes on some errors, use CID as a check to see if there was an error. +// if (vatsimUserData?.data?.cid == null) { +// let error = vatsimUserData; +// throw error; +// } else { +// vatsimUserData = vatsimUserData.data; +// } + +// const userData = { +// email: vatsimUserData.personal.email, +// firstName: vatsimUserData.personal.name_first, +// lastName: vatsimUserData.personal.name_last, +// cid: vatsimUserData.cid, +// ratingId: vatsimUserData.vatsim.rating.id, +// }; + +// // If the user did not authorize all requested data from the AUTH login, we may have null parameters +// // If that is the case throw a BadRequest exception. +// if (Object.values(userData).some((x) => x == null || x == "")) { +// throw { +// code: 400, +// message: +// "User must authorize all requested VATSIM data. [Authorize Data]", +// }; +// } + +// let user = await User.findOne({ cid: userData.cid }); + +// if (!user) { +// user = await User.create({ +// cid: userData.cid, +// fname: userData.firstName, +// lname: userData.lastName, +// email: userData.email, +// rating: userData.ratingId, +// oi: null, +// broadcast: false, +// member: false, +// vis: false, +// }); +// } else { +// if (!user.email) { +// user.email = userData.email; +// } +// if (!user.prefName ?? true) { +// user.fname = userData.firstName; +// user.lname = userData.lastName; +// } +// user.rating = userData.ratingId; +// } + +// if (user.oi && !user.avatar) { +// const { data } = await axios.get( +// `https://ui-avatars.com/api/?name=${user.oi}&size=256&background=122049&color=ffffff`, +// { responseType: "arraybuffer" } +// ); + +// await req.app.s3 +// .putObject({ +// Bucket: "zabartcc/avatars", +// Key: `${user.cid}-default.png`, +// Body: data, +// ContentType: "image/png", +// ACL: "public-read", +// ContentDisposition: "inline", +// }) +// .promise(); + +// user.avatar = `${user.cid}-default.png`; +// } + +// await user.save(); + +// const apiToken = jwt.sign({ cid: userData.cid }, process.env.JWT_SECRET, { +// expiresIn: "30d", +// }); + +// res.cookie("token", apiToken, { +// httpOnly: true, +// maxAge: 432000000, +// sameSite: true, +// }); // Expires in 5 days +// } catch (e) { +// req.app.Sentry.captureException(e); +// res.stdRes.ret_det = e; +// res.status(500); +// } + +// return res.json(res.stdRes); +// }); + router.get("/logout", async (req, res) => { try { if (!req.cookies.token) { @@ -440,4 +462,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/scripts/upsert,js b/scripts/upsert,js new file mode 100644 index 0000000..7bc0126 --- /dev/null +++ b/scripts/upsert,js @@ -0,0 +1,44 @@ +import dotenv from "dotenv"; +import mongoose from "mongoose"; +import fs from "fs"; +import path from "path"; +import { fileURLToPath } from "url"; + +import Certification from "../models/Certification.js"; +import Role from "../models/Role.js"; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +dotenv.config({ path: path.join(__dirname, "../.env") }); + +const certsPath = path.join(__dirname, "../seeds/certifications.json"); +const rolesPath = path.join(__dirname, "../seeds/roles.json"); + +const certs = JSON.parse(fs.readFileSync(certsPath, "utf8")); +const roles = JSON.parse(fs.readFileSync(rolesPath, "utf8")); + +await mongoose.connect(process.env.MONGO_URI); + +const certOps = certs.map((c) => ({ + updateOne: { + filter: { code: c.code }, + update: { $set: c }, + upsert: true, + }, +})); + +const roleOps = roles.map((r) => ({ + updateOne: { + filter: { code: r.code }, + update: { $set: r }, + upsert: true, + }, +})); + +await Certification.bulkWrite(certOps); +await Role.bulkWrite(roleOps); + +console.log("Upsert complete"); + +await mongoose.disconnect(); \ No newline at end of file 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..fc397d9 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": 10, + "class": "training" + } +] \ No newline at end of file From bc66eb539057019e957079fed9b831fada870705 Mon Sep 17 00:00:00 2001 From: Cayden Decator Date: Fri, 20 Feb 2026 10:00:15 -0500 Subject: [PATCH 2/2] Remove Comments and Remove file as requested in PR --- controllers/ControllerController.js | 80 ++++++------- controllers/UserController.js | 180 +++++++++++++--------------- scripts/upsert,js | 44 ------- seeds/roles.json | 2 +- 4 files changed, 121 insertions(+), 185 deletions(-) delete mode 100644 scripts/upsert,js diff --git a/controllers/ControllerController.js b/controllers/ControllerController.js index ab9d4eb..bdc1822 100644 --- a/controllers/ControllerController.js +++ b/controllers/ControllerController.js @@ -675,22 +675,22 @@ router.post("/:cid", microAuth, async (req, res) => { { responseType: "arraybuffer" } ); - // await req.app.s3 - // .putObject({ - // Bucket: "zabartcc/avatars", - // Key: `${req.body.cid}-default.png`, - // Body: data, - // ContentType: "image/png", - // ACL: "public-read", - // ContentDisposition: "inline", - // }) - // .promise(); - - // await User.create({ - // ...req.body, - // oi: userOi, - // avatar: `${req.body.cid}-default.png`, - // }); + await req.app.s3 + .putObject({ + Bucket: "zabartcc/avatars", + Key: `${req.body.cid}-default.png`, + Body: data, + ContentType: "image/png", + ACL: "public-read", + ContentDisposition: "inline", + }) + .promise(); + + await User.create({ + ...req.body, + oi: userOi, + avatar: `${req.body.cid}-default.png`, + }); const ratings = [ "Unknown", @@ -848,30 +848,30 @@ router.put( { responseType: "arraybuffer" } ); - // await req.app.s3 - // .putObject({ - // Bucket: "zabartcc/avatars", - // Key: `${req.params.cid}-default.png`, - // Body: data, - // ContentType: "image/png", - // ACL: "public-read", - // ContentDisposition: "inline", - // }) - // .promise(); - - - // await User.findOneAndUpdate( - // { cid: req.params.cid }, - // { - // fname, - // lname, - // email, - // oi, - // vis, - // roleCodes: toApply.roles, - // certCodes: toApply.certifications, - // } - // ); + await req.app.s3 + .putObject({ + Bucket: "zabartcc/avatars", + Key: `${req.params.cid}-default.png`, + Body: data, + ContentType: "image/png", + ACL: "public-read", + ContentDisposition: "inline", + }) + .promise(); + + + await User.findOneAndUpdate( + { cid: req.params.cid }, + { + fname, + lname, + email, + oi, + vis, + roleCodes: toApply.roles, + certCodes: toApply.certifications, + } + ); const updated = await User.findOneAndUpdate( { cid: req.params.cid }, diff --git a/controllers/UserController.js b/controllers/UserController.js index f44646c..e41bf3f 100644 --- a/controllers/UserController.js +++ b/controllers/UserController.js @@ -97,10 +97,89 @@ router.post("/idsToken", getUser, async (req, res) => { }); + +// Endpoint to preform user login, uses oAuth middleware to retrieve an access token router.post("/login", oAuth, async (req, res) => { try { + const { access_token } = req.oauth; + + // Use access token to attempt to get user data. + let vatsimUserData = await vatsimApiHelper.getUserInformation(access_token); + + // VATSIM API returns 200 codes on some errors, use CID as a check to see if there was an error. + if (vatsimUserData?.data?.cid == null) { + let error = vatsimUserData; + throw error; + } else { + vatsimUserData = vatsimUserData.data; + } + + const userData = { + email: vatsimUserData.personal.email, + firstName: vatsimUserData.personal.name_first, + lastName: vatsimUserData.personal.name_last, + cid: vatsimUserData.cid, + ratingId: vatsimUserData.vatsim.rating.id, + }; + + // If the user did not authorize all requested data from the AUTH login, we may have null parameters + // If that is the case throw a BadRequest exception. + if (Object.values(userData).some((x) => x == null || x == "")) { + throw { + code: 400, + message: + "User must authorize all requested VATSIM data. [Authorize Data]", + }; + } + + let user = await User.findOne({ cid: userData.cid }); - const apiToken = jwt.sign({ cid: 1597373 }, process.env.JWT_SECRET, { + if (!user) { + user = await User.create({ + cid: userData.cid, + fname: userData.firstName, + lname: userData.lastName, + email: userData.email, + rating: userData.ratingId, + oi: null, + broadcast: false, + member: false, + vis: false, + }); + } else { + if (!user.email) { + user.email = userData.email; + } + if (!user.prefName ?? true) { + user.fname = userData.firstName; + user.lname = userData.lastName; + } + user.rating = userData.ratingId; + } + + if (user.oi && !user.avatar) { + const { data } = await axios.get( + `https://ui-avatars.com/api/?name=${user.oi}&size=256&background=122049&color=ffffff`, + { responseType: "arraybuffer" } + ); + + await req.app.s3 + .putObject({ + Bucket: "zabartcc/avatars", + Key: `${user.cid}-default.png`, + Body: data, + ContentType: "image/png", + ACL: "public-read", + ContentDisposition: "inline", + }) + .promise(); + + user.avatar = `${user.cid}-default.png`; + } + + await user.save(); + + const apiToken = jwt.sign({ cid: userData.cid }, process.env.JWT_SECRET, { expiresIn: "30d", }); @@ -118,105 +197,6 @@ router.post("/login", oAuth, 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 { -// const { access_token } = req.oauth; - -// // Use access token to attempt to get user data. -// let vatsimUserData = await vatsimApiHelper.getUserInformation(access_token); - -// // VATSIM API returns 200 codes on some errors, use CID as a check to see if there was an error. -// if (vatsimUserData?.data?.cid == null) { -// let error = vatsimUserData; -// throw error; -// } else { -// vatsimUserData = vatsimUserData.data; -// } - -// const userData = { -// email: vatsimUserData.personal.email, -// firstName: vatsimUserData.personal.name_first, -// lastName: vatsimUserData.personal.name_last, -// cid: vatsimUserData.cid, -// ratingId: vatsimUserData.vatsim.rating.id, -// }; - -// // If the user did not authorize all requested data from the AUTH login, we may have null parameters -// // If that is the case throw a BadRequest exception. -// if (Object.values(userData).some((x) => x == null || x == "")) { -// throw { -// code: 400, -// message: -// "User must authorize all requested VATSIM data. [Authorize Data]", -// }; -// } - -// let user = await User.findOne({ cid: userData.cid }); - -// if (!user) { -// user = await User.create({ -// cid: userData.cid, -// fname: userData.firstName, -// lname: userData.lastName, -// email: userData.email, -// rating: userData.ratingId, -// oi: null, -// broadcast: false, -// member: false, -// vis: false, -// }); -// } else { -// if (!user.email) { -// user.email = userData.email; -// } -// if (!user.prefName ?? true) { -// user.fname = userData.firstName; -// user.lname = userData.lastName; -// } -// user.rating = userData.ratingId; -// } - -// if (user.oi && !user.avatar) { -// const { data } = await axios.get( -// `https://ui-avatars.com/api/?name=${user.oi}&size=256&background=122049&color=ffffff`, -// { responseType: "arraybuffer" } -// ); - -// await req.app.s3 -// .putObject({ -// Bucket: "zabartcc/avatars", -// Key: `${user.cid}-default.png`, -// Body: data, -// ContentType: "image/png", -// ACL: "public-read", -// ContentDisposition: "inline", -// }) -// .promise(); - -// user.avatar = `${user.cid}-default.png`; -// } - -// await user.save(); - -// const apiToken = jwt.sign({ cid: userData.cid }, process.env.JWT_SECRET, { -// expiresIn: "30d", -// }); - -// res.cookie("token", apiToken, { -// httpOnly: true, -// maxAge: 432000000, -// sameSite: true, -// }); // Expires in 5 days -// } catch (e) { -// req.app.Sentry.captureException(e); -// res.stdRes.ret_det = e; -// res.status(500); -// } - -// return res.json(res.stdRes); -// }); - router.get("/logout", async (req, res) => { try { if (!req.cookies.token) { diff --git a/scripts/upsert,js b/scripts/upsert,js deleted file mode 100644 index 7bc0126..0000000 --- a/scripts/upsert,js +++ /dev/null @@ -1,44 +0,0 @@ -import dotenv from "dotenv"; -import mongoose from "mongoose"; -import fs from "fs"; -import path from "path"; -import { fileURLToPath } from "url"; - -import Certification from "../models/Certification.js"; -import Role from "../models/Role.js"; - -const __filename = fileURLToPath(import.meta.url); -const __dirname = path.dirname(__filename); - -dotenv.config({ path: path.join(__dirname, "../.env") }); - -const certsPath = path.join(__dirname, "../seeds/certifications.json"); -const rolesPath = path.join(__dirname, "../seeds/roles.json"); - -const certs = JSON.parse(fs.readFileSync(certsPath, "utf8")); -const roles = JSON.parse(fs.readFileSync(rolesPath, "utf8")); - -await mongoose.connect(process.env.MONGO_URI); - -const certOps = certs.map((c) => ({ - updateOne: { - filter: { code: c.code }, - update: { $set: c }, - upsert: true, - }, -})); - -const roleOps = roles.map((r) => ({ - updateOne: { - filter: { code: r.code }, - update: { $set: r }, - upsert: true, - }, -})); - -await Certification.bulkWrite(certOps); -await Role.bulkWrite(roleOps); - -console.log("Upsert complete"); - -await mongoose.disconnect(); \ No newline at end of file diff --git a/seeds/roles.json b/seeds/roles.json index fc397d9..2bd9a17 100644 --- a/seeds/roles.json +++ b/seeds/roles.json @@ -50,7 +50,7 @@ { "name": "Combined Monitor", "code": "cm", - "order": 10, + "order": 9, "class": "training" } ] \ No newline at end of file