chore(deps): upgrade to Express 5 and remove redundant middleware

- Express 4 → 5.2.1
- Remove method-override (unused with Angular HttpClient) and errorhandler (superseded by exceptions.handler.js)
- Remove asyncHandler wrapper from all controllers — Express 5 propagates async rejections natively
- Remove body-parser (redundant, Express 5 includes it internally)
- Patch/minor updates: cors, dotenv, ejs, express-jwt, express-session, jsonwebtoken, morgan, mysql2, sequelize, underscore
- Dev updates: eslint 9.0→9.39, nodemon 2→3, globals, sequelize-cli
- Fix getUser endpoint to include SkydiverProfile data in response
- docs: add ADR 0013, update README
This commit is contained in:
2026-05-01 20:42:39 +02:00
parent 59401b3c85
commit 96da68e18e
14 changed files with 1114 additions and 814 deletions
+26 -22
View File
@@ -1,10 +1,9 @@
const { UserService, SkydiverProfileService } = require('../services');
const asyncHandler = require("../middlewares/asyncHandler");
const ErrorResponse = require("../utils/errorResponse");
var crypto = require('crypto');
const passport = require('passport');
module.exports.authenticate = asyncHandler(async (req, res, next) => {
module.exports.authenticate = async (req, res, next) => {
try {
passport.authenticate('headerapikey', { session: false }, function (err, application, info) {
if (err) {
@@ -28,9 +27,9 @@ module.exports.authenticate = asyncHandler(async (req, res, next) => {
//res.status(500).json({ message: 'Something went wrong while authenticating.', error: err.message });
return next(new ErrorResponse('Something went wrong while authenticating.', 500, err.message));
}
});
};
module.exports.createUser = asyncHandler(async (req, res, next) => {
module.exports.createUser = async (req, res, next) => {
try {
const { username, firstname, lastname, phone, email, password } = req.body.user;
const userSlug = UserService.slugify(username);
@@ -57,9 +56,9 @@ module.exports.createUser = asyncHandler(async (req, res, next) => {
} catch (err) {
return next(new ErrorResponse('Something went wrong while creating user.', 500, err.message));
}
});
};
module.exports.getAllUsers = asyncHandler(async (req, res, next) => {
module.exports.getAllUsers = async (req, res, next) => {
try {
const users = await UserService.getAllUsers();
@@ -69,24 +68,29 @@ module.exports.getAllUsers = asyncHandler(async (req, res, next) => {
} catch (err) {
return next(new ErrorResponse('Something went wrong while fetching user.', 500, err.message));
}
});
};
module.exports.getUser = asyncHandler(async (req, res, next) => {
module.exports.getUser = async (req, res, next) => {
try {
const user = await UserService.getUserById(req.payload.id);
if (!user) {
return next(new ErrorResponse("Unauthorized", 401, "Authentication required."));
}
const profile = await SkydiverProfileService.getByUserId(req.payload.id);
res.status(200).json({
user: user.toAuthJSON()
user: {
...user.toAuthJSON(),
...(profile ? profile.toJSONFor() : { poids: null, licence: null, bg_image: null }),
}
});
} catch (err) {
return next(new ErrorResponse('Something went wrong while fetching user.', 500, err.message));
}
});
};
module.exports.loginAsUser = asyncHandler(async (req, res, next) => {
module.exports.loginAsUser = async (req, res, next) => {
try {
passport.authenticate('local', { session: false }, function (err, user, info) {
if (err) {
@@ -102,9 +106,9 @@ module.exports.loginAsUser = asyncHandler(async (req, res, next) => {
} catch (err) {
return next(new ErrorResponse('Something went wrong while processing login.', 500, err.message));
}
});
};
module.exports.updateUser = asyncHandler(async (req, res, next) => {
module.exports.updateUser = async (req, res, next) => {
try {
let user = await UserService.getUserById(req.payload.id);
if (!user) {
@@ -142,9 +146,9 @@ module.exports.updateUser = asyncHandler(async (req, res, next) => {
} catch (err) {
return next(new ErrorResponse('Something went wrong while updating user.', 500, err.message));
}
});
};
module.exports.updateUserEmail = asyncHandler(async (req, res, next) => {
module.exports.updateUserEmail = async (req, res, next) => {
try {
let user = await UserService.getUserById(req.payload.id);
if (!user) {
@@ -162,9 +166,9 @@ module.exports.updateUserEmail = asyncHandler(async (req, res, next) => {
} catch (err) {
return next(new ErrorResponse('Something went wrong while updating user.', 500, err.message));
}
});
};
module.exports.updateUserPassword = asyncHandler(async (req, res, next) => {
module.exports.updateUserPassword = async (req, res, next) => {
try {
let user = await UserService.getUserById(req.payload.id);
if (!user) {
@@ -182,9 +186,9 @@ module.exports.updateUserPassword = asyncHandler(async (req, res, next) => {
} catch (err) {
return next(new ErrorResponse('Something went wrong while updating user.', 500, err.message));
}
});
};
module.exports.updateUserRole = asyncHandler(async (req, res, next) => {
module.exports.updateUserRole = async (req, res, next) => {
try {
let user = await UserService.getUserById(req.payload.id);
if (!user) {
@@ -205,9 +209,9 @@ module.exports.updateUserRole = asyncHandler(async (req, res, next) => {
} catch (err) {
return next(new ErrorResponse('Something went wrong while updating user.', 500, err.message));
}
});
};
module.exports.updateUserUsername = asyncHandler(async (req, res, next) => {
module.exports.updateUserUsername = async (req, res, next) => {
try {
let user = await UserService.getUserById(req.payload.id);
if (!user) {
@@ -225,5 +229,5 @@ module.exports.updateUserUsername = asyncHandler(async (req, res, next) => {
} catch (err) {
return next(new ErrorResponse('Something went wrong while updating user.', 500, err.message));
}
});
};