fix(skydive): migrate author field from ObjectId to UUID string

- Register SkydiverProfile model in mysql.js (fixes startup crash on association)
- Replace $toObjectId with direct string match in all 12 aggregation queries
- Guard toJSONFor on all Mongo models to fall back to MySQL user.toProfileJSONFor()
  when author is a UUID string (restores username/image in API responses)
- Pass user to toJSONFor() everywhere instead of null
- Remove dead .populate('author') calls (author: String has no ref)
- Fix ownership check in /last route: compare author string to req.payload.id
  instead of the now-absent author.username property
This commit is contained in:
2026-04-26 04:27:47 +02:00
parent da1f9437ab
commit 66821427be
17 changed files with 64 additions and 120 deletions
@@ -10,7 +10,6 @@ mailer.setApiKey(process.env.SENDGRID_API_KEY);
// Preload application objects on routes with ':application'
router.param('application', function (req, res, next, slug) {
Application.findOne({ slug: slug })
.populate('author')
.then(function (application) {
if (!application) {
return res.sendStatus(404);
@@ -52,7 +51,6 @@ router.get('/', auth.required, function (req, res, next) {
.skip(Number(offset))
.limit(Number(limit))
.sort({ createdAt: 'desc' })
.populate('author')
.exec(),
Application.countDocuments(query).exec(),
req.payload ? UserService.getUserById(req.payload.id) : null
@@ -117,8 +115,7 @@ router.post('/', auth.required, function (req, res, next) {
*/
router.get('/:application', auth.required, function (req, res, next) {
Promise.all([
req.payload ? UserService.getUserById(req.payload.id) : null,
req.application.populate('author')
req.payload ? UserService.getUserById(req.payload.id) : null
]).then(function (results) {
let user = results[0];
return res.json({ application: req.application.toJSONFor(user) });