|
@@ -9,13 +9,53 @@ class MatchService extends CrudService {
|
|
|
constructor(ctx) {
|
|
|
super(ctx, 'match');
|
|
|
this.model = this.ctx.model.Race.Match;
|
|
|
+ this.matchGroupModel = this.ctx.model.Race.MatchGroup;
|
|
|
+ this.matchProjectModel = this.ctx.model.Race.MatchProject;
|
|
|
+ this.matchSignModel = this.ctx.model.Race.MatchSign;
|
|
|
}
|
|
|
/**
|
|
|
- *
|
|
|
- * @param {*} param0
|
|
|
+ * 查询这个赛事下所有的东西
|
|
|
+ * @param {Object} params 地址栏路径参数
|
|
|
*/
|
|
|
async getAll({ id }) {
|
|
|
+ let data = await this.model.findById(id);
|
|
|
+ if (!data) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到赛事信息');
|
|
|
+ // 基础模块 user表文档
|
|
|
+ const conn = this.app.mongooseDB.get('base');
|
|
|
+ const schema = _.get(this.ctx.model, 'Base.User.schema');
|
|
|
+ const m = conn.model('User', schema);
|
|
|
|
|
|
+ data = JSON.parse(JSON.stringify(data));
|
|
|
+ const match_id = data._id;
|
|
|
+ let groups = await this.matchGroupModel.find({ match_id });
|
|
|
+ groups = JSON.parse(JSON.stringify(groups));
|
|
|
+ for (const group of groups) {
|
|
|
+ const { _id: group_id } = group;
|
|
|
+ let projects = await this.matchProjectModel.find({ match_id, group_id });
|
|
|
+ projects = JSON.parse(JSON.stringify(projects));
|
|
|
+ for (const project of projects) {
|
|
|
+ const { _id: project_id } = project;
|
|
|
+ let signs = await this.matchSignModel.find({ match_id, group_id, project_id }).populate({
|
|
|
+ path: 'user_id',
|
|
|
+ populate: {
|
|
|
+ path: 'user_id',
|
|
|
+ model: m,
|
|
|
+ },
|
|
|
+ });
|
|
|
+ signs = JSON.parse(JSON.stringify(signs));
|
|
|
+ const users = [];
|
|
|
+ for (const sign of signs) {
|
|
|
+ const userObj = _.get(sign, 'user_id.user_id');
|
|
|
+ const user = _.pick(userObj, [ 'icon', 'name' ]);
|
|
|
+ user._id = _.get(sign, 'user_id._id');
|
|
|
+ users.push(user);
|
|
|
+ }
|
|
|
+ project.user = users;
|
|
|
+ }
|
|
|
+ group.project = projects;
|
|
|
+ }
|
|
|
+ data.group = groups;
|
|
|
+ return data;
|
|
|
}
|
|
|
}
|
|
|
|