后台:添加武将,装备,道具

This commit is contained in:
luying
2021-01-28 12:01:26 +08:00
parent 72a089b179
commit b880962f02
12 changed files with 428 additions and 58 deletions
+19
View File
@@ -232,6 +232,11 @@ export default class Hero extends BaseModel {
return result;
}
public static async deleteHero(roleId: string, hid: number) {
let result = await HeroModel.deleteMany({roleId, hid});
return result;
}
public static async updateHeroInfo(roleId: string, hid:number, heroUpdate:heroUpdate, select?: string, lean = true) {
delete heroUpdate._id;
let result: HeroType = await HeroModel.findOneAndUpdate({roleId, hid}, {$set:heroUpdate}, {new: true}).select(select).lean(lean);
@@ -245,6 +250,20 @@ export default class Hero extends BaseModel {
{new: true}).lean(lean);
return hero;
}
public static async findByField(field: string, value?: number|string, lean = true) {
let searchObj = {};
if(field != 'all') {
if(field == 'roleName') {
searchObj['roleName'] = { $regex: new RegExp(value.toString(), 'i') }
} else {
searchObj[field] = value;
}
}
//.select('uid tel username')
const user: HeroType[] = await HeroModel.find(searchObj).lean(lean);
return user;
}
}
export const HeroModel = getModelForClass(Hero);