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:
@@ -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)
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -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
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -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)
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -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)
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -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)
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -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)
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -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)
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -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
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -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
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user