武将重生:完成接口

This commit is contained in:
luying
2022-02-28 15:15:00 +08:00
parent cf920c0c80
commit bf73985623
8 changed files with 141 additions and 24 deletions
+8 -3
View File
@@ -248,11 +248,16 @@ export default class Hero extends BaseModel {
return hero;
}
public static async createHero(heroInfo: HeroUpdate, lean = true) {
public static getInitInfo(heroInfo: HeroUpdate = {}): HeroUpdate {
const doc = new HeroModel();
const seqId = await CounterModel.getNewCounter(COUNTER.HID) || -1;
const update = Object.assign(doc.toJSON(), heroInfo, { seqId });
const update = { ...doc.toJSON(), ...heroInfo};
delete update._id;
return update
}
public static async createHero(heroInfo: HeroUpdate, lean = true) {
const seqId = await CounterModel.getNewCounter(COUNTER.HID) || -1;
const update = this.getInitInfo({ ...heroInfo, seqId });
const hero: HeroType = await HeroModel.findOneAndUpdate({ roleId: heroInfo.roleId, hid: heroInfo.hid }, update, { upsert: true, new: true }).lean(lean);
return hero;
}