|
@@ -4,6 +4,7 @@ const { BusinessError, ErrorCode } = require('naf-core').Error;
|
|
const _ = require('lodash');
|
|
const _ = require('lodash');
|
|
const assert = require('assert');
|
|
const assert = require('assert');
|
|
const user = require('../model/race/user');
|
|
const user = require('../model/race/user');
|
|
|
|
+const { ObjectId } = require('mongoose').Types;
|
|
|
|
|
|
//
|
|
//
|
|
class MatchTeamGroupService extends CrudService {
|
|
class MatchTeamGroupService extends CrudService {
|
|
@@ -185,6 +186,42 @@ class MatchTeamGroupService extends CrudService {
|
|
return res;
|
|
return res;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ async afterQuery(filter, data) {
|
|
|
|
+ data = JSON.parse(JSON.stringify(data));
|
|
|
|
+ for (const d of data) {
|
|
|
|
+ const { person, person_type } = d;
|
|
|
|
+ if (person_type === 'User') {
|
|
|
|
+ // 单人
|
|
|
|
+ const conn = this.app.mongooseDB.get('base');
|
|
|
|
+ const schema = _.get(this.ctx.model, 'Base.User.schema');
|
|
|
|
+ const m = conn.model('User', schema);
|
|
|
|
+ const users = await this.userModel.find({ _id: person }).populate({ path: 'user_id', model: m, select: 'name' });
|
|
|
|
+ const parr = person.map(i => {
|
|
|
|
+ const r = users.find(f => ObjectId(f._id).equals(i));
|
|
|
|
+ if (r) return { id: r._id, name: _.get(r, 'user_id.name') };
|
|
|
|
+ return i;
|
|
|
|
+ });
|
|
|
|
+ d.person = parr;
|
|
|
|
+ } else if (person_type === 'TeamApply') {
|
|
|
|
+ console.log(person);
|
|
|
|
+ // 组队
|
|
|
|
+ const teamApplys = await this.teamApplyModel.find({ _id: person });
|
|
|
|
+ const parr = [];
|
|
|
|
+ for (const p of parr) {
|
|
|
|
+ const r = teamApplys.find(f => ObjectId(f._id).equals(p));
|
|
|
|
+ console.log(r);
|
|
|
|
+ if (r) {
|
|
|
|
+ const { one_member_name, two_member_name } = r;
|
|
|
|
+ parr.push({ id: p, name: `${one_member_name}-${two_member_name}` });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ d.person = parr;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return data;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 根据该赛事状态,判断是否可以操作
|
|
* 根据该赛事状态,判断是否可以操作
|
|
* 赛事状态为 1,2可以组队, 其余状态不能组队,不能修改
|
|
* 赛事状态为 1,2可以组队, 其余状态不能组队,不能修改
|