Files
adastra_api/src/database/models/mongo/herowars/Clan.js
T
julien 66821427be 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
2026-04-26 04:27:47 +02:00

58 lines
1.7 KiB
JavaScript

var mongoose = require('mongoose');
var uniqueValidator = require('mongoose-unique-validator');
var HWClanSchema = new mongoose.Schema({
id: { type: String, unique: true },
country: String,
description: String,
disbanding: Boolean,
frameId: Number,
icon: {
flagColor1: Number,
flagColor2: Number,
flagShape: Number,
iconColor: Number,
iconShape: Number,
},
level: String,
members: [{ type: mongoose.Schema.Types.ObjectId, ref: 'HWMember' }],
membersCount: Number,
minLevel: String,
ownerId: String,
/*roleNames: { type: mongoose.Schema.Types.ObjectId, ref: 'HWClanRoles' },*/
serverId: String,
title: String,
topActivity: String,
topDungeon: String,
author: { type: String }
}, {timestamps: true, toJSON: {virtuals: true}});
HWClanSchema.plugin(uniqueValidator, { message: 'is already taken' });
HWClanSchema.methods.toJSONFor = function() {
return {
id: this.id,
country: this.country,
description: this.description,
disbanding: this.disbanding,
frameId: this.frameId,
icon: this.icon,
level: this.level,
members: this.members,
membersCount: this.membersCount,
minLevel: this.minLevel,
ownerId: this.ownerId,
serverId: this.serverId,
title: this.title,
topActivity: this.topActivity,
topDungeon: this.topDungeon,
createdAt: this.createdAt,
updatedAt: this.updatedAt,
author: this.author && typeof this.author.toJSONFor === 'function'
? this.author.toJSONFor()
: this.author ?? null
};
};
mongoose.model('HWClan', HWClanSchema);