军团:动态
This commit is contained in:
45
shared/db/GuildRec.ts
Normal file
45
shared/db/GuildRec.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
import { genCode } from '../pubUtils/util';
|
||||
import { GUILD_REC_TYPE } from '../consts';
|
||||
import { nowSeconds } from '../pubUtils/timeUtil';
|
||||
|
||||
@index({ guildCode: 1 })
|
||||
export default class GuildRec extends BaseModel {
|
||||
|
||||
@prop({ required: true })
|
||||
recCode: string;
|
||||
|
||||
@prop({ required: true, select: false })
|
||||
roleId: string;
|
||||
|
||||
@prop({ required: true, select: false })
|
||||
guildCode: string;
|
||||
|
||||
@prop({ required: true, default: GUILD_REC_TYPE.JOIN_GUILD, enum: GUILD_REC_TYPE })
|
||||
type: number;
|
||||
|
||||
@prop({ required: true, type: String, default: [] })
|
||||
params: string[];
|
||||
|
||||
@prop({ required: true, default: nowSeconds() })
|
||||
createTime: number;
|
||||
|
||||
public static async createGuildRec(roleId: string, guildCode: string, type: number, params: string[]) {
|
||||
const doc = new GuildRecModel();
|
||||
const update = Object.assign(doc.toJSON(), { roleId, guildCode, type, params });
|
||||
delete update._id;
|
||||
const recCode = genCode(10);
|
||||
const result: GuildRecType = await GuildRecModel.findOneAndUpdate({ recCode }, params, { upsert: true, new: true }).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async getGuildRec(guildCode: string) {
|
||||
const result: GuildRecType[] = await GuildRecModel.find({ guildCode }).lean();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export const GuildRecModel = getModelForClass(GuildRec);
|
||||
|
||||
export interface GuildRecType extends Pick<DocumentType<GuildRec>, keyof GuildRec> { };
|
||||
Reference in New Issue
Block a user