refactor(skydive): replace MongoDB User with MySQL UserService
All skydive routes now fetch users via UserService (MySQL) instead of
mongoose.model('User'). Key changes:
- user._id.toString() → user.id (same UUID, different source)
- User.findOne({ username }) → UserService.getUserByUsername()
- /feed route migrated to async/await using UserService.getUserFollowed()
to resolve the following list from the MySQL Follower table
- jump/file/application author set as user.id (UUID string) instead of
the full Mongoose document
- jump.toJSONFor(null) — following field in responses is now always false
until Jump model is migrated away from MongoDB User dependency
- user.controller: licence/poids/bg_image routed to SkydiverProfileService
fixing the silent Sequelize save bug for those fields
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
const { UserService } = require('../services');
|
||||
const { UserService, SkydiverProfileService } = require('../services');
|
||||
const asyncHandler = require("../middlewares/asyncHandler");
|
||||
const ErrorResponse = require("../utils/errorResponse");
|
||||
var crypto = require('crypto');
|
||||
@@ -129,33 +129,26 @@ module.exports.updateUser = asyncHandler(async (req, res, next) => {
|
||||
if (typeof req.body.user.phone !== 'undefined') {
|
||||
user.phone = req.body.user.phone;
|
||||
}
|
||||
if (typeof req.body.user.licence !== 'undefined') {
|
||||
user.licence = req.body.user.licence;
|
||||
}
|
||||
if (typeof req.body.user.poids !== 'undefined') {
|
||||
user.poids = req.body.user.poids;
|
||||
}
|
||||
if (typeof req.body.user.image !== 'undefined') {
|
||||
user.image = req.body.user.image;
|
||||
}
|
||||
if (typeof req.body.user.bg_image !== 'undefined') {
|
||||
user.bg_image = req.body.user.bg_image;
|
||||
}
|
||||
if (typeof req.body.user.role !== 'undefined') {
|
||||
return next(new ErrorResponse("Forbidden", 403, "A suspected attempt to usurp rights has been detected. The suspicious activity has been reported and xill be investigated."));
|
||||
}
|
||||
|
||||
// Persist changes using the service (service will save instance or update+fetch)
|
||||
const updatedUser = await UserService.updateUserById(user, req.payload.id);
|
||||
|
||||
const skydiverFields = {};
|
||||
if (typeof req.body.user.licence !== 'undefined') skydiverFields.licence = req.body.user.licence;
|
||||
if (typeof req.body.user.poids !== 'undefined') skydiverFields.poids = req.body.user.poids;
|
||||
if (typeof req.body.user.bg_image !== 'undefined') skydiverFields.bg_image = req.body.user.bg_image;
|
||||
if (Object.keys(skydiverFields).length > 0) {
|
||||
await SkydiverProfileService.upsert(req.payload.id, skydiverFields);
|
||||
}
|
||||
|
||||
res.status(200).json({
|
||||
user: updatedUser.toAuthJSON()
|
||||
});
|
||||
/*return user.save().then(function () {
|
||||
return res.json({
|
||||
message: 'User updated successfully.',
|
||||
user: user.toAuthJSON()
|
||||
});
|
||||
});*/
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse('Something went wrong while updating user.', 500, err.message));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user