45 lines
1.8 KiB
TypeScript
45 lines
1.8 KiB
TypeScript
import BaseModel from './BaseModel';
|
|
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
|
import { CounterModel } from './Counter';
|
|
import { COUNTER } from '../consts';
|
|
|
|
@index({ id: 1 })
|
|
export default class PVPConfig extends BaseModel {
|
|
@prop({ required: true, default: 1 })
|
|
id: number;
|
|
@prop({ required: true })
|
|
warId: number; // 地图
|
|
@prop({ required: true, default: 1 })
|
|
seasonNum: number; // 赛季
|
|
@prop({ required: true })
|
|
seasonEndTime: number; //赛季结束的时间
|
|
@prop({ required: false })
|
|
settleGuildWeeklyTime: number;
|
|
|
|
public static async findCurPVPConfig() {
|
|
let seasonNum = await CounterModel.getCounter(COUNTER.PVP_SEASON_NUM);
|
|
const result: PVPConfigType = await PVPConfigModel.findOne({ seasonNum }).lean(true);
|
|
return result;
|
|
}
|
|
|
|
public static async findPVPConfig(seasonNum: number) {
|
|
const result: PVPConfigType = await PVPConfigModel.findOne({ seasonNum }).lean(true);
|
|
return result;
|
|
}
|
|
|
|
public static async createPVPConfig(seasonNum: number, seasonEndTime: number, warId: number) {
|
|
const result: PVPConfigType = await PVPConfigModel.findOneAndUpdate({ seasonNum }, { warId, seasonEndTime }, { upsert: true, new: true }).lean(true);
|
|
return result;
|
|
}
|
|
|
|
public static async updatePVPConfig(seasonNum: number, update: { warId?: number, settleGuildWeeklyTime?: number }) {
|
|
const result: PVPConfigType = await PVPConfigModel.findOneAndUpdate({ seasonNum }, update, { new: true }).lean(true);
|
|
return result;
|
|
}
|
|
}
|
|
|
|
export const PVPConfigModel = getModelForClass(PVPConfig);
|
|
|
|
export interface PVPConfigType extends Pick<DocumentType<PVPConfig>, keyof PVPConfig> {
|
|
id: number;
|
|
}; |