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:
2026-04-26 00:05:57 +02:00
parent ad7fc4384a
commit 5bcecd01f9
9 changed files with 148 additions and 446 deletions
+7 -78
View File
@@ -1,9 +1,9 @@
var router = require('express').Router(),
mongoose = require('mongoose'),
Jump = mongoose.model('Jump'),
User = mongoose.model('User');
Jump = mongoose.model('Jump');
const auth = require('../../../middlewares/auth'),
queries = require('../../queries');
const { UserService } = require('../../../services');
router.get('/allByImat', auth.required, function (req, res, next) {
@@ -15,41 +15,31 @@ router.get('/allByImat', auth.required, function (req, res, next) {
if (typeof req.query.offset !== 'undefined') {
offset = req.query.offset;
}
User.findById(req.payload.id).then(function (user) {
UserService.getUserById(req.payload.id).then(function (user) {
if (!user) {
return res.status(401).json({ errors: { "Unauthorized": "autentification requise" } });
}
let query = queries.getAeronefsByImatQuery(user._id.toString());
let query = queries.getAeronefsByImatQuery(user.id);
Promise.all([
Jump.aggregate(query)
.skip(Number(offset))
.limit(Number(limit))
.exec()
//Aeronef.count(query)
]).then(function (results) {
let aeronefs = results[0];
//let aeronefsCount = results[1];
return res.json({
aeronefs: aeronefs.map(function (data) {
return { aeronef: data._id.aeronef, imat: data._id.imat, count: data.count };
}),
aeronefsCount: aeronefs.length
});
/*
return res.json({
aeronefs: aeronefs.map(function (aeronef) {
return aeronef.toJSONFor(user);
}),
aeronefsCount: aeronefsCount
});
*/
}).catch(next);
}).catch(next);
});
router.get('/allByImatByYear', auth.required, function (req, res, next) {
User.findById(req.payload.id).then(function (user) {
UserService.getUserById(req.payload.id).then(function (user) {
if (!user) {
return res.status(401).json({ errors: { "Unauthorized": "autentification requise" } });
}
@@ -61,7 +51,7 @@ router.get('/allByImatByYear', auth.required, function (req, res, next) {
if (typeof req.query.offset !== 'undefined') {
offset = req.query.offset;
}
let query = queries.getAeronefsByImatByYearQuery(user._id.toString());
let query = queries.getAeronefsByImatByYearQuery(user.id);
Jump.aggregate(query)
.skip(Number(offset))
@@ -77,67 +67,6 @@ router.get('/allByImatByYear', auth.required, function (req, res, next) {
});
}).catch(next);
}).catch(next);
/*
let limit = 50;
let offset = 0;
if (typeof req.query.limit !== 'undefined') {
limit = req.query.limit;
}
if (typeof req.query.offset !== 'undefined') {
offset = req.query.offset;
}
let query = [
{
'$match': {
'$expr': {
'$eq': [ '$author' , { '$toObjectId': user._id.toString() } ]
}
}
}, {
'$project': {
'_id': 0,
'aeronef': 1,
'imat': 1,
'year': {
'$year': '$date'
}
}
}, {
'$group': {
'_id': {
'aeronef': '$aeronef',
'imat': '$imat',
'year': '$year'
},
'count': {
'$sum': 1
}
}
}, {
'$sort': {
'_id': 1
}
}
];
Promise.all([
req.payload ? User.findById(req.payload.id) : null,
Jump.aggregate(query)
.skip(Number(offset))
.limit(Number(limit))
.exec()
]).then(function (results) {
let user = results[0];
let aeronefs = results[1];
if (!user) {
return res.status(401).json({ errors: { "Unauthorized": "autentification requise" } });
}
return res.json({
aeronefs: aeronefs,
aeronefsCount: aeronefs.length
});
}).catch(next);
*/
});
module.exports = router;