Skip to content

Commit 99cd6dd

Browse files
authored
build: Upgrading dependencies for compatibility with Node 20 and general maintenance (#926)
1 parent d435e1d commit 99cd6dd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+7904
-8295
lines changed

.github/workflows/node.js.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121

2222
strategy:
2323
matrix:
24-
node-version: [14.x]
24+
node-version: [20.x]
2525
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
2626

2727
steps:

.nvmrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v14
1+
20.10.0

app.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const volunteerRouter = require("./routes/api/volunteer");
3333
const roleRouter = require("./routes/api/role");
3434

3535
const app = express();
36-
Services.db.connect(app);
36+
Services.db.connect();
3737

3838
let corsOptions = {};
3939

@@ -72,7 +72,7 @@ app.use(
7272
// Cookie Options
7373
maxAge: 48 * 60 * 60 * 1000, //Logged in for 48 hours
7474
sameSite: process.env.COOKIE_SAME_SITE,
75-
secureProxy: true
75+
secureProxy: !Services.env.isTest()
7676
})
7777
);
7878
app.use(passport.initialize());
@@ -115,7 +115,7 @@ app.use((err, req, res, next) => {
115115
const message = err.message ? err.message : "Internal Server Error";
116116
//Only show bad error when we're not in deployment
117117
let errorContents;
118-
if (status === 500 && Services.env.isProduction) {
118+
if (status === 500 && Services.env.isProduction()) {
119119
errorContents = {};
120120
} else if (err.error) {
121121
errorContents = err.error;

constants/role.constant.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const Constants = {
66
const mongoose = require("mongoose");
77

88
const accountRole = {
9-
_id: mongoose.Types.ObjectId("00000000e285ec4f6ec7e5c2"),
9+
_id: new mongoose.Types.ObjectId("00000000e285ec4f6ec7e5c2"),
1010
name: "account",
1111
routes: [
1212
Constants.Routes.authRoutes.login,
@@ -37,7 +37,6 @@ const hackerRole = {
3737
Constants.Routes.hackerRoutes.patchSelfById,
3838
Constants.Routes.hackerRoutes.patchSelfConfirmationById,
3939
Constants.Routes.hackerRoutes.getSelf,
40-
Constants.Routes.hackerRoutes.postDiscord,
4140

4241
Constants.Routes.travelRoutes.getSelf,
4342
Constants.Routes.travelRoutes.getSelfById,

constants/testMongoId.constant.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
const mongoose = require("mongoose");
44

5-
const team1Id = mongoose.Types.ObjectId();
6-
const team2Id = mongoose.Types.ObjectId();
7-
const team3Id = mongoose.Types.ObjectId();
5+
const team1Id = new mongoose.Types.ObjectId();
6+
const team2Id = new mongoose.Types.ObjectId();
7+
const team3Id = new mongoose.Types.ObjectId();
88

9-
const hackerAId = mongoose.Types.ObjectId();
10-
const hackerBId = mongoose.Types.ObjectId();
11-
const hackerCId = mongoose.Types.ObjectId();
12-
const hackerDId = mongoose.Types.ObjectId();
13-
const hackerEId = mongoose.Types.ObjectId();
14-
const hackerFId = mongoose.Types.ObjectId();
15-
const hackerGId = mongoose.Types.ObjectId();
16-
const hackerHId = mongoose.Types.ObjectId();
9+
const hackerAId = new mongoose.Types.ObjectId();
10+
const hackerBId = new mongoose.Types.ObjectId();
11+
const hackerCId = new mongoose.Types.ObjectId();
12+
const hackerDId = new mongoose.Types.ObjectId();
13+
const hackerEId = new mongoose.Types.ObjectId();
14+
const hackerFId = new mongoose.Types.ObjectId();
15+
const hackerGId = new mongoose.Types.ObjectId();
16+
const hackerHId = new mongoose.Types.ObjectId();
1717

1818
module.exports = {
1919
team1Id: team1Id,

controllers/auth.controller.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ const Success = require("../constants/success.constant");
55
module.exports = {
66
onSuccessfulLogin: function(req, res) {
77
return res.status(200).json({
8-
message: Success.LOGIN,
8+
message: Success.AUTH_LOGIN,
99
data: {}
1010
});
1111
},
1212
logout: function(req, res) {
1313
req.logout();
1414
return res.status(200).json({
15-
message: Success.LOGOUT,
15+
message: Success.AUTH_LOGOUT,
1616
data: {}
1717
});
1818
},

docs/standards.md

+15-15
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Things to take note of:
8282
message: string,
8383
error: any
8484
}
85-
```
85+
```
8686
* **Wrapping async functions**: Asynchronous middleware must be wrapped with `Util.asyncMiddleware(...)`. This is so that if a `Promise` is rejected, the reject reason is handled gracefully. To understand how this works, please look at the code for `asyncMiddleware`.
8787
* **Organization of import statements**: We organize our import statements according to their general function. If a file is a `Service` (such as `user.service.js`), then we place it inside of the `Service` object. This is to make code readability better.
8888

@@ -201,9 +201,9 @@ Things to take note of:
201201
* **`activate` function**: Every route file contains one exported function, called `activate`. This takes as input an `ExpressRouter`, to which we will attach the sub router to. We will also define all of the sub-routes in this function.
202202
* **Chaining middlewares in a route**: We chain middlewares together by placing them one after another as arguments to the http request of the route.
203203
* **Ordering of middleware**:
204-
* If input is expected, validation of that input should be done promptly. Therefore validators are generally the first middlewares.
204+
* If input is expected, validation of that input should be done promptly. Therefore validators are generally the first middlewares.
205205
* The first middleware should be the validator for the inputted data of a route. In this case, we have the validator for a new account.
206-
* The next middleware should be `Middleware.parseBody.middleware` to parse the validated information. This middleware also places the data inside of `req.body`. If validation fails, it fails the request.
206+
* The next middleware should be `Middleware.parseBody.middleware` to parse the validated information. This middleware also places the data inside of `req.body`. If validation fails, it fails the request.
207207
* The following middlewares will depend on what type of route it is. In this case, we are creating a new item in our database, so we want to create a new `Account` object. This is what `Middleware.Account.parseAccount` does.
208208
* Finally, we want to interact with the database. This is done either in the `Controller` function, or in another `middleware` function.
209209
* the last middleware should always be a `Controller` (since we want to respond to the user of the api).
@@ -233,7 +233,7 @@ function findById(id) {
233233
_id: id
234234
};
235235

236-
return Account.findById(query, logger.queryCallbackFactory(TAG, "account", query));
236+
return logger.logQuery(TAG, "account", query, Account.findById(query));
237237
}
238238
...
239239
module.exports = {
@@ -242,7 +242,7 @@ module.exports = {
242242
```
243243
244244
Things to take note of:
245-
* **async & await**: When the service call is to a mongoose model, they generally return a mongoose query. These can be handled as a promise, and Mongoose has further documentation on it [here](https://mongoosejs.com/docs/api.html). We handle then by using `await` on the service call. For example, a middleware function that uses `findById` would be:
245+
* **async & await**: When the service call is to a mongoose model, they generally return a mongoose query. These can be handled as a promise, and Mongoose has further documentation on it [here](https://mongoosejs.com/docs/api.html). We handle then by using `await` on the service call. For example, a middleware function that uses `findById` would be:
246246
```javascript
247247
async function getById(req, res, next) {
248248
const acc = await Services.Account.findById(req.body.id);
@@ -256,14 +256,14 @@ Things to take note of:
256256

257257
req.body.account = acc;
258258
return next();
259-
}
259+
}
260260
```
261-
It's important to:
261+
It's important to:
262262
* Use `await` when calling the service function
263263
* Put `async` in the method head
264264
* Check the output of the service function call for any errors. In the code snippet we need to check for a scenario where the account is not found, which is a 404 error. A full list of the current error messages are in [error.constant.js](../constants/error.constant.js).
265265
More information on asynchronous functions can be found [here](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function).
266-
* **queryCallbackFactory**: The query callback factory returns a function that uses winston to log the success or failure of the service call. The callback factory is used for mongoose service calls.
266+
* **logQuery**: This function wraps the query's `then` method and uses winston to log the success or failure of the mongoose service call.
267267
268268
### Test files
269269
@@ -281,7 +281,7 @@ We repopulate the test server before each test to ensure consistency. [setup.spe
281281
282282
##### Motivation
283283
284-
We wanted to have a scalable way to create new entities that properly reference each other. The biggest challenge lied in creating enough accounts that can be properly referenced during specific tests.
284+
We wanted to have a scalable way to create new entities that properly reference each other. The biggest challenge lied in creating enough accounts that can be properly referenced during specific tests.
285285
286286
##### Util.js
287287
@@ -309,7 +309,7 @@ let hackerAccounts = {
309309
};
310310
```
311311
312-
In this example the `new` accounts are accounts that exist, but the hacker objects have not been created. The `stored.team` accounts are those linked to a hacker object that is in a team. The `stored.noTeam` accounts link to a hacker that is not in a team. The `invalid` accounts are created accounts that are linked to a hacker object that does not fit with the Hacker schema. The invalid accounts are used to test fail cases. The value for each key is an array of account objects.
312+
In this example the `new` accounts are accounts that exist, but the hacker objects have not been created. The `stored.team` accounts are those linked to a hacker object that is in a team. The `stored.noTeam` accounts link to a hacker that is not in a team. The `invalid` accounts are created accounts that are linked to a hacker object that does not fit with the Hacker schema. The invalid accounts are used to test fail cases. The value for each key is an array of account objects.
313313
314314
On the other end of the account-hacker link, [hacker.util.js](../tests/util/hacker.test.util.js) contains the hacker data in the form of hacker objects. These hacker objects have an `accountId` attribute which references an account's `_id`. The matching between the hacker object and the respective account object it needs to link to is also done by nomenclature. For example, a hacker on a team would be called `TeamHackerX` where X is a number. This hacker's account object would be within the array specified by `hackerAccounts.stored.team`. The specific account object is referenced by its index in the array. That index is the same as the value X in the name of the hacker object.
315315
@@ -335,7 +335,7 @@ function stringValidator(fieldLocation, fieldname, optional = true) {
335335
```
336336
It's important to note the use of `setProperValidationChainBuilder` to parse the input value from the appropriate input location. This is consistent across generic validators. It is also important to create a validator for situations where the input is optional.
337337
338-
A validator example, using generic validator functions.
338+
A validator example, using generic validator functions.
339339
```javascript
340340
"use strict";
341341
const VALIDATOR = require("./validator.helper");
@@ -358,7 +358,7 @@ module.exports = {
358358
};
359359
```
360360
361-
A route would use a validator in the following manner:
361+
A route would use a validator in the following manner:
362362
```javascript
363363
accountRouter.route("/:id").patch(
364364
...
@@ -377,8 +377,8 @@ A route would use a validator in the following manner:
377377
{
378378
"A": "foo",
379379
"B": true,
380-
"C": {
381-
"bar": "baz"
380+
"C": {
381+
"bar": "baz"
382382
}
383383
}
384384
```
@@ -429,4 +429,4 @@ We use apidoc.js to generate documentation for the API. This documentation is fo
429429
430430
For more info on how to write your own documentation, see their docs: <http://apidocjs.com/>.
431431
432-
To update the docs, run: `npm run docs`. Make sure that the version number for each route is correct!
432+
To update the docs, run: `npm run docs`. Make sure that the version number for each route is correct!

middlewares/account.middleware.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function parsePatch(req, res, next) {
4646
*/
4747
function parseAccount(req, res, next) {
4848
const accountDetails = {
49-
_id: mongoose.Types.ObjectId(),
49+
_id: new mongoose.Types.ObjectId(),
5050
firstName: req.body.firstName,
5151
lastName: req.body.lastName,
5252
pronoun: req.body.pronoun,

middlewares/hacker.middleware.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function parsePatch(req, res, next) {
4848
*/
4949
function parseHacker(req, res, next) {
5050
const hackerDetails = {
51-
_id: mongoose.Types.ObjectId(),
51+
_id: new mongoose.Types.ObjectId(),
5252
accountId: req.body.accountId,
5353
application: req.body.application,
5454
teamId: req.body.teamId
@@ -127,17 +127,13 @@ function validateConfirmedStatus(account) {
127127
message: Constants.Error.ACCOUNT_404_MESSAGE,
128128
data: { account: account }
129129
};
130-
}
131-
/*
132-
else if (!account.confirmed) {
130+
} else if (!account.confirmed) {
133131
return {
134132
status: 403,
135133
message: Constants.Error.ACCOUNT_403_MESSAGE,
136134
data: { account: { id: account.id, confirmed: account.confirmed } }
137135
};
138-
}
139-
*/
140-
else if (account.accountType !== Constants.General.HACKER) {
136+
} else if (account.accountType !== Constants.General.HACKER) {
141137
return {
142138
status: 409,
143139
message: Constants.Error.ACCOUNT_TYPE_409_MESSAGE,
@@ -841,7 +837,7 @@ async function checkDuplicateAccountLinks(req, res, next) {
841837
*/
842838
async function findSelf(req, res, next) {
843839
if (
844-
req.user.accountType != Constants.General.HACKER /*|| !req.user.confirmed*/
840+
req.user.accountType != Constants.General.HACKER|| !req.user.confirmed
845841
) {
846842
return next({
847843
status: 409,

middlewares/role.middleware.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const Constants = {
1919
*/
2020
function parseRole(req, res, next) {
2121
const roleDetails = {
22-
_id: mongoose.Types.ObjectId(),
22+
_id: new mongoose.Types.ObjectId(),
2323
name: req.body.name,
2424
routes: req.body.routes
2525
};

middlewares/sponsor.middleware.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function parsePatch(req, res, next) {
4949
*/
5050
function parseSponsor(req, res, next) {
5151
const sponsorDetails = {
52-
_id: mongoose.Types.ObjectId(),
52+
_id: new mongoose.Types.ObjectId(),
5353
accountId: req.body.accountId,
5454
tier: req.body.tier,
5555
company: req.body.company,

middlewares/team.middleware.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ async function populateMemberAccountsById(req, res, next) {
445445
*/
446446
function parseTeam(req, res, next) {
447447
const teamDetails = {
448-
_id: mongoose.Types.ObjectId(),
448+
_id: new mongoose.Types.ObjectId(),
449449
name: req.body.name,
450450
members: req.body.members,
451451
devpostURL: req.body.devpostURL,
@@ -492,7 +492,7 @@ function parsePatch(req, res, next) {
492492

493493
async function parseNewTeam(req, res, next) {
494494
const teamDetails = {
495-
_id: mongoose.Types.ObjectId(),
495+
_id: new mongoose.Types.ObjectId(),
496496
name: req.body.name,
497497
members: [],
498498
devpostURL: req.body.devpostURL,

middlewares/travel.middleware.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function parsePatch(req, res, next) {
4040
*/
4141
function parseTravel(req, res, next) {
4242
const travelDetails = {
43-
_id: mongoose.Types.ObjectId(),
43+
_id: new mongoose.Types.ObjectId(),
4444
accountId: req.body.accountId,
4545
hackerId: req.body.hackerId
4646
};

middlewares/validators/validator.helper.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ function applicationValidator(fieldLocation, fieldname, optional = true) {
478478
// typeof app.shortAnswer.question2 === "string";
479479
// hasValid.previousHackathons =
480480
// !!app.shortAnswer.previousHackathons &&
481-
// typeof app.shortAnswer.previousHackathons === "number";
481+
// typeof app.shortAnswer.previousHackathons === "number";
482482
// hasValid.team =
483483
// !app.team || mongoose.Types.ObjectId.isValid(app.team);
484484

@@ -534,7 +534,7 @@ function applicationValidator(fieldLocation, fieldname, optional = true) {
534534
);
535535
hasValid.previousHackathons = app.shortAnswer.hasOwnProperty(
536536
"previousHackathons"
537-
);
537+
);
538538
}
539539
hasValid.accommodation = app.hasOwnProperty("accommodation");
540540
if (hasValid.accommodation) {
@@ -584,7 +584,7 @@ function applicationValidator(fieldLocation, fieldname, optional = true) {
584584
// typeof app.shortAnswer.question2 === "string";
585585
// hasValid.previousHackathons =
586586
// !!app.shortAnswer.previousHackathons &&
587-
// typeof app.shortAnswer.previousHackathons === "number";
587+
// typeof app.shortAnswer.previousHackathons === "number";
588588
// hasValid.team =
589589
// !app.team || mongoose.Types.ObjectId.isValid(app.team);
590590
return (

middlewares/volunteer.middleware.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const Constants = {
2424
*/
2525
function parseVolunteer(req, res, next) {
2626
const volunteerDetails = {
27-
_id: mongoose.Types.ObjectId(),
27+
_id: new mongoose.Types.ObjectId(),
2828
accountId: req.body.accountId
2929
};
3030

models/account.model.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ const AccountSchema = new mongoose.Schema({
5555
}
5656
});
5757

58-
AccountSchema.methods.toJSON = function() {
59-
const as = this.toObject();
58+
AccountSchema.methods.toJSON = function(options) {
59+
const as = this.toObject(options);
6060
delete as.__v;
6161
as.id = as._id;
6262
delete as._id;

models/accountConfirmationToken.model.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ const AccountConfirmationSchema = new mongoose.Schema({
2626
}
2727
});
2828

29-
AccountConfirmationSchema.methods.toJSON = function() {
30-
const resetObj = this.toObject();
31-
delete resetObj.__v;
32-
resetObj.id = resetObj._id;
33-
delete resetObj._id;
34-
return resetObj;
29+
AccountConfirmationSchema.methods.toJSON = function(options) {
30+
const acs = this.toObject(options);
31+
delete acs.__v;
32+
acs.id = acs._id;
33+
delete acs._id;
34+
return acs;
3535
};
3636

3737
module.exports = mongoose.model(

models/bus.model.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ const BusSchema = new mongoose.Schema({
4141
}
4242
});
4343

44-
BusSchema.methods.toJSON = function() {
45-
const bs = this.toObject();
44+
BusSchema.methods.toJSON = function(options) {
45+
const bs = this.toObject(options);
4646
delete bs.__v;
4747
bs.id = bs._id;
4848
delete bs._id;

0 commit comments

Comments
 (0)