Files
adastra_api/src/routes/api/skydive/dropzones.routes.js
T
julien 5bcecd01f9 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
2026-04-26 00:05:57 +02:00

70 lines
2.4 KiB
JavaScript

var router = require('express').Router(),
mongoose = require('mongoose'),
Jump = mongoose.model('Jump');
const auth = require('../../../middlewares/auth'),
queries = require('../../queries');
const { UserService } = require('../../../services');
router.get('/allByOaci', auth.required, function (req, res, next) {
UserService.getUserById(req.payload.id).then(function (user) {
if (!user) {
return res.status(401).json({ errors: { "Unauthorized": "autentification requise" } });
}
let limit = 25;
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 = queries.getDropZonesByOaciQuery(user.id);
Jump.aggregate(query)
.skip(Number(offset))
.limit(Number(limit))
.exec()
.then(function (result) {
let dropzones = result.map(function (data) {
return { lieu: data._id.lieu, oaci: data._id.oaci, count: data.count };
});
return res.json({
dropzones: dropzones,
dropzonesCount: dropzones.length
});
}).catch(next);
}).catch(next);
});
router.get('/allByOaciByYear', auth.required, function (req, res, next) {
UserService.getUserById(req.payload.id).then(function (user) {
if (!user) {
return res.status(401).json({ errors: { "Unauthorized": "autentification requise" } });
}
let limit = 25;
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 = queries.getDropZonesByOaciByYearQuery(user.id);
Jump.aggregate(query)
.skip(Number(offset))
.limit(Number(limit))
.exec()
.then(function (result) {
let dropzones = result.map(function (data) {
return { lieu: data._id.lieu, oaci: data._id.oaci, year: data._id.year, count: data.count };
});
return res.json({
dropzones: dropzones,
dropzonesCount: dropzones.length
});
}).catch(next);
}).catch(next);
});
module.exports = router;