Files
ZYZ/shared/db/GuildTrainReport.ts

51 lines
2.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
class Report {
@prop({ required: true })
roleName: string;
@prop({ required: true })
trainId: number;//挑战的试炼关
@prop({ required: true })
hid: number;//据点
@prop({ required: true })
score: number;
@prop({ required: true })
time: number;
@prop({ required: true })
difficulty: number;
@prop({ required: true })
type: number;//1失败 2成功3表示系统战报即被成功压制
}
@index({guildCode: 1, trainId: 1})
export default class GuildTrainReport extends BaseModel {
@prop({ required: true })
guildCode: string;
@prop({ required: true })
trainId: number;
@prop({ required: true, default: [], type: Report, _id: false })
reports: Report[];
public static async pushGuildTrainReports(guildCode: string, trainId: number, reports: Array<Report>, lean = true) {
const guildTrainReport: GuildTrainReportType = await GuildTrainReportModel.findOneAndUpdate({ guildCode, trainId },
{ $push: {reports:{ $each:reports } } },{new: true}).lean(lean);
return guildTrainReport;
}
public static async resetGuildTrainReport(guildCode: string, trainId: number, lean = true) {
const guildTrainReport: GuildTrainReportType = await GuildTrainReportModel.findOneAndUpdate({ guildCode, trainId },
{ $set: {reports:[], guildCode, trainId } }, {new: true, upsert: true}).lean(lean);
return guildTrainReport;
}
public static async findGuildTrainByTrainIds(guildCode: string, trainIds:Array<number>, lean = true) {
const guildTrains: GuildTrainReportType[] = await GuildTrainReportModel.find({ trainId:{ $in:trainIds}, guildCode }).lean(lean);
return guildTrains;
}
}
export const GuildTrainReportModel = getModelForClass(GuildTrainReport);
export interface GuildTrainReportType extends Pick<DocumentType<GuildTrainReport>, keyof GuildTrainReport> { };