From b4cfb6cb9473284394a3ceaa4c064b518cfeecab Mon Sep 17 00:00:00 2001 From: luying Date: Thu, 19 Aug 2021 19:55:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8E=E5=8F=B0=EF=BC=9A=E5=B1=9E=E6=80=A7?= =?UTF-8?q?=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gm-server/app/service/users.ts | 16 ++++++++++++++-- shared/db/Hero.ts | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/gm-server/app/service/users.ts b/gm-server/app/service/users.ts index 414c3ebb1..9db6611f2 100644 --- a/gm-server/app/service/users.ts +++ b/gm-server/app/service/users.ts @@ -1,5 +1,5 @@ import { UserModel } from '@db/User'; -import { RoleModel } from '@db/Role'; +import { CeAttrDataRole, RoleModel } from '@db/Role'; import { HeroModel } from '@db/Hero'; import { EquipModel } from '@db/Equip'; import { ActionPointModel } from '@db/ActionPoint'; @@ -503,8 +503,20 @@ export default class GMUsers extends Service { let heroes = await HeroModel.findByField(field, value); if (heroes) { + let roleMap = new Map(); + for(let { roleId } of heroes) { + if(!roleMap.has(roleId)) { + let role = await RoleModel.findByRoleId(roleId, 'attr'); + roleMap.set(roleId, role.attr); + } + } + let list = heroes.map(cur => { + let cal = new AttributeCal(); + cal.setByDbData(roleMap.get(cur.roleId), cur.attr); + return {...cur, calculatedAttr: cal.getReduceAttributesToArr()} + }) - return ctx.service.utils.resResult(STATUS.SUCCESS, { list: heroes }); + return ctx.service.utils.resResult(STATUS.SUCCESS, { list }); } else { console.error('role list not found'); return ctx.service.utils.resResult(STATUS.INTERNAL_ERR); diff --git a/shared/db/Hero.ts b/shared/db/Hero.ts index 11b6e4513..4a59b2016 100644 --- a/shared/db/Hero.ts +++ b/shared/db/Hero.ts @@ -277,7 +277,7 @@ export default class Hero extends BaseModel { } } //.select('uid tel username') - const user: HeroType[] = await HeroModel.find(searchObj).lean(lean); + const user: HeroType[] = await HeroModel.find(searchObj, {_id: 0}).lean(lean); return user; }