战力:修复创建武将bug

This commit is contained in:
luying
2022-03-28 17:44:14 +08:00
parent f35af70adc
commit 14b28921af
13 changed files with 379 additions and 393 deletions
+16 -16
View File
@@ -281,22 +281,22 @@ export default class Hero extends BaseModel {
return update
}
public static async createHero(heroInfo: HeroUpdate, lean = true) {
const seqId = await CounterModel.getNewCounter(COUNTER.HID) || -1;
const update = this.getInitInfo(heroInfo.hid, { ...heroInfo, seqId });
const hero: HeroType = await HeroModel.findOneAndUpdate({ roleId: heroInfo.roleId, hid: heroInfo.hid }, update, { upsert: true, new: true }).lean(lean);
return hero;
}
// public static async createHero(heroInfo: HeroUpdate, lean = true) {
// const seqId = await CounterModel.getNewCounter(COUNTER.HID) || -1;
// const update = this.getInitInfo(heroInfo.hid, { ...heroInfo, seqId });
// const hero: HeroType = await HeroModel.findOneAndUpdate({ roleId: heroInfo.roleId, hid: heroInfo.hid }, update, { upsert: true, new: true }).lean(lean);
// return hero;
// }
public static async insertHeroes(roleId: string, roleName: string, serverId: number, heroInfos: HeroUpdate[]) {
let insertInfos: HeroUpdate[] = [];
for(let hero of heroInfos) {
const seqId = await CounterModel.getNewCounter(COUNTER.HID) || -1;
insertInfos.push({ ...hero, seqId, roleId, roleName, serverId })
}
await HeroModel.insertMany(insertInfos);
return <HeroType[]>insertInfos;
}
// public static async insertHeroes(roleId: string, roleName: string, serverId: number, heroInfos: HeroUpdate[]) {
// let insertInfos: HeroUpdate[] = [];
// for(let hero of heroInfos) {
// const seqId = await CounterModel.getNewCounter(COUNTER.HID) || -1;
// insertInfos.push({ ...hero, seqId, roleId, roleName, serverId })
// }
// await HeroModel.insertMany(insertInfos);
// return <HeroType[]>insertInfos;
// }
public static async sumHeroCe(roleId: string) {
let ce: Array<{ ce: number }> = await HeroModel.aggregate([
@@ -323,7 +323,7 @@ export default class Hero extends BaseModel {
public static async updateHeroInfo(roleId: string, hid: number, heroUpdate: HeroUpdate, select?: string, getters = false) {
delete heroUpdate._id;
let result: HeroType = await HeroModel.findOneAndUpdate({ roleId, hid }, { $set: heroUpdate }, { new: true }).select(select).lean({ getters });
let result: HeroType = await HeroModel.findOneAndUpdate({ roleId, hid }, { $set: heroUpdate }, { new: true, upsert: true }).select(select).lean({ getters });
return result;
}