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
+3 -1
View File
@@ -26,7 +26,9 @@ AeronefSchema.methods.toJSONFor = function(user){
imat: this.imat,
createdAt: this.createdAt,
updatedAt: this.updatedAt,
author: this.author.toProfileJSONFor(user)
author: this.author && typeof this.author.toProfileJSONFor === 'function'
? this.author.toProfileJSONFor(user)
: (user && typeof user.toProfileJSONFor === 'function' ? user.toProfileJSONFor() : this.author ?? null)
};
};
+6 -2
View File
@@ -32,7 +32,9 @@ ApplicationSchema.methods.toJSONFor = function (user) {
description: this.description,
createdAt: this.createdAt,
updatedAt: this.updatedAt,
author: this.author.toProfileJSONFor(user)
author: this.author && typeof this.author.toProfileJSONFor === 'function'
? this.author.toProfileJSONFor(user)
: (user && typeof user.toProfileJSONFor === 'function' ? user.toProfileJSONFor() : this.author ?? null)
};
};
@@ -44,7 +46,9 @@ ApplicationSchema.methods.toAuthJSON = function () {
description: this.description,
createdAt: this.createdAt,
updatedAt: this.updatedAt,
author: this.author.toJSONFor()
author: this.author && typeof this.author.toJSONFor === 'function'
? this.author.toJSONFor()
: this.author ?? null
};
};
+3 -1
View File
@@ -26,7 +26,9 @@ CanopySchema.methods.toJSONFor = function(user){
taille: this.taille,
createdAt: this.createdAt,
updatedAt: this.updatedAt,
author: this.author.toProfileJSONFor(user)
author: this.author && typeof this.author.toProfileJSONFor === 'function'
? this.author.toProfileJSONFor(user)
: (user && typeof user.toProfileJSONFor === 'function' ? user.toProfileJSONFor() : this.author ?? null)
};
};
+3 -1
View File
@@ -26,7 +26,9 @@ DropzoneSchema.methods.toJSONFor = function(user){
oaci: this.oaci,
createdAt: this.createdAt,
updatedAt: this.updatedAt,
author: this.author.toProfileJSONFor(user)
author: this.author && typeof this.author.toProfileJSONFor === 'function'
? this.author.toProfileJSONFor(user)
: (user && typeof user.toProfileJSONFor === 'function' ? user.toProfileJSONFor() : this.author ?? null)
};
};
+1 -1
View File
@@ -81,7 +81,7 @@ JumpSchema.methods.toJSONFor = function(user) {
updatedAt: this.updatedAt,
author: this.author && typeof this.author.toProfileJSONFor === 'function'
? this.author.toProfileJSONFor(user)
: this.author ?? null
: (user && typeof user.toProfileJSONFor === 'function' ? user.toProfileJSONFor() : this.author ?? null)
};
};
+3 -1
View File
@@ -35,7 +35,9 @@ JumpFileSchema.methods.toJSONFor = function(user){
type: this.type,
createdAt: this.createdAt,
updatedAt: this.updatedAt,
author: this.author.toProfileJSONFor(user)
author: this.author && typeof this.author.toProfileJSONFor === 'function'
? this.author.toProfileJSONFor(user)
: (user && typeof user.toProfileJSONFor === 'function' ? user.toProfileJSONFor() : this.author ?? null)
};
};
+3 -1
View File
@@ -100,7 +100,9 @@ X2DataLogSchema.methods.toJSONForUser = function(user) {
createdOn: this.createdOn,
createdAt: this.createdAt,
updatedAt: this.updatedAt,
author: this.author.toProfileJSONFor(user)
author: this.author && typeof this.author.toProfileJSONFor === 'function'
? this.author.toProfileJSONFor(user)
: (user && typeof user.toProfileJSONFor === 'function' ? user.toProfileJSONFor() : this.author ?? null)
};
};
+3 -1
View File
@@ -48,7 +48,9 @@ HWClanSchema.methods.toJSONFor = function() {
topDungeon: this.topDungeon,
createdAt: this.createdAt,
updatedAt: this.updatedAt,
author: this.author.toJSONFor()
author: this.author && typeof this.author.toJSONFor === 'function'
? this.author.toJSONFor()
: this.author ?? null
};
};
+3 -1
View File
@@ -128,7 +128,9 @@ HWMemberSchema.methods.toJSONFor = function() {
serverId: this.serverId,
createdAt: this.createdAt,
updatedAt: this.updatedAt,
author: this.author.toJSONFor()
author: this.author && typeof this.author.toJSONFor === 'function'
? this.author.toJSONFor()
: this.author ?? null
};
};
+2
View File
@@ -16,6 +16,7 @@ const TagModel = require('./models/mysql/Tag');
const TagListModel = require('./models/mysql/TagList');
const UserModel = require('./models/mysql/User');
const UserRoleXrefModel = require('./models/mysql/UserRoleXref');
const SkydiverProfileModel = require('./models/mysql/SkydiverProfile');
const DB = {
sequelize,
@@ -35,6 +36,7 @@ const DB = {
Tag: TagModel(sequelize, DataTypes),
TagList: TagListModel(sequelize, DataTypes),
UserRoleXref: UserRoleXrefModel(sequelize, DataTypes),
SkydiverProfile: SkydiverProfileModel(),
};
module.exports = DB;