军团表逻辑
This commit is contained in:
@@ -1,8 +1,19 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType, Ref } from '@typegoose/typegoose';
|
||||
class Reward {
|
||||
@prop({ required: true })
|
||||
id: number;
|
||||
@prop({ required: true })
|
||||
count: number;
|
||||
}
|
||||
|
||||
class TrainBox {
|
||||
|
||||
@prop({ required: true })
|
||||
roleId: string;
|
||||
@prop({ required: true, type: Reward })
|
||||
good: Reward;
|
||||
@prop({ required: true })
|
||||
index: number;
|
||||
}
|
||||
|
||||
class TrainScript {
|
||||
@@ -56,16 +67,21 @@ export default class GuildTrain extends BaseModel {
|
||||
@prop({ required: true, default: false})
|
||||
locked: boolean;
|
||||
|
||||
public static async findGuildTrain(guildCode: string, locked = false, lean = true) {
|
||||
const guildTrain: GuildTrainType[] = await GuildTrainModel.findOne({ guildCode, locked }).lean(lean);
|
||||
public static async findGuildTrain(guildCode: string, select?: string, locked = false, lean = true) {
|
||||
const guildTrains: GuildTrainType[] = await GuildTrainModel.find({ guildCode, locked }).select(select).lean(lean);
|
||||
return guildTrains;
|
||||
}
|
||||
|
||||
public static async findGuildTrainByTrainIds(guildCode: string, trainIds:Array<number>, locked = false, lean = true) {
|
||||
const guildTrains: GuildTrainType[] = await GuildTrainModel.find({ trainId:{ $in:trainIds}, guildCode, locked }).lean(lean);
|
||||
return guildTrains;
|
||||
}
|
||||
|
||||
public static async findTrainByTrainIdNotLock(guildCode: string, trainId: number, select?: string, locked = false, lean = true) {
|
||||
const guildTrain: GuildTrainType = await GuildTrainModel.findOne({ guildCode, trainId, locked }).select(select).lean(lean);
|
||||
return guildTrain;
|
||||
}
|
||||
|
||||
public static async findTrainByTrainIdNotLock(guildCode: string, trainId: number, locked = false, lean = true) {
|
||||
const guildTrain: GuildTrainType = await GuildTrainModel.findOne({ guildCode, trainId, locked }).lean(lean);
|
||||
return guildTrain;
|
||||
}
|
||||
|
||||
public static async updateGuildTrain(guildCode: string, trainId: number, update: GuildTrainTypeParam, lean = true) {
|
||||
const guildTrain: GuildTrainType = await GuildTrainModel.findOneAndUpdate({ guildCode, trainId}, { $set: update }).lean(lean);
|
||||
return guildTrain;
|
||||
@@ -77,10 +93,22 @@ export default class GuildTrain extends BaseModel {
|
||||
return guildTrain;
|
||||
}
|
||||
|
||||
public static async openGuildTrain() {
|
||||
// const bossScript: BossScriptType = await BossScriptModel.findOneAndUpdate({ guildCode },{ranks:[], time: nowSeconds(), bossHp, warId, $inc: { recordNum: 1 }}, {new: true, upsert: true}).lean(lean);
|
||||
public static async openGuildTrain(guildCode: string, trainId: number, trainScripts: Array<TrainScript>, lean = true) {
|
||||
const guildTrain: GuildTrainType = await GuildTrainModel.findOneAndUpdate({ guildCode, trainId },{ trainId, reports: [], locked: false, ranks: [], trainScripts, isComplete: false, guildCode}, {new: true, upsert: true}).lean(lean);
|
||||
return guildTrain;
|
||||
}
|
||||
|
||||
public static async findTrainScriptBoxByIndex(guildCode: string, roleId: string, trainId: number, hid: number, index: number, progress: number, time, locked = false, lean = true) {
|
||||
const guildTrain: GuildTrainType = await GuildTrainModel.findOne({ guildCode, trainId, locked, 'trainScripts.hid': hid,
|
||||
'trainScripts.index':{$ne:index },'trainScripts.roleId':{$ne:roleId }, progress: {$gte: progress}, time:{$gte: time}}).lean(lean);
|
||||
return guildTrain;
|
||||
}
|
||||
|
||||
public static async receiveBoxByIndex(guildCode: string, roleId: string, trainId: number, hid: number, index: number, good: Reward, locked = false, lean = true) {
|
||||
const guildTrain: GuildTrainType = await GuildTrainModel.findOneAndUpdate({ guildCode, trainId, locked, 'trainScripts.hid': hid, },
|
||||
{ $push:{ 'trainScripts.$.trainBoxs': {roleId, index, good} }} ).lean(lean);
|
||||
return guildTrain;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user