diff --git a/shared/db/UserGuildApply.ts b/shared/db/UserGuildApply.ts index ce53b4e16..c416cfc63 100644 --- a/shared/db/UserGuildApply.ts +++ b/shared/db/UserGuildApply.ts @@ -28,10 +28,7 @@ export default class UserGuildApply extends BaseModel { // 创建申请或邀请 public static async createUserGuildApply(role: RoleType, guild: GuildType, type: number) { const applyCode = genCode(10); - const doc = new UserGuildApplyModel(); - const update = Object.assign(doc.toJSON(), { applyCode, roleId: role.roleId, role: role._id, guildCode: guild.code, guild: guild._id, type }); - delete update._id; - const result: UserGuildApplyType = await UserGuildApplyModel.findOneAndUpdate({ applyCode }, update, { upsert: true, new: true }).lean(); + const result: UserGuildApplyType = await UserGuildApplyModel.findOneAndUpdate({ roleId: role.roleId, guildCode: guild.code, type }, { $set: { roleId: role.roleId, role: role._id, guildCode: guild.code, guild: guild._id }, $setOnInsert: { applyCode }}, { upsert: true, new: true }).lean(); return result; }