|
@@ -46,26 +46,43 @@ class MatchSmallGroupScheduleService extends CrudService {
|
|
|
}
|
|
|
|
|
|
async beforeQuery(filter) {
|
|
|
-
|
|
|
- const { user_id } = filter;
|
|
|
+
|
|
|
+
|
|
|
+ const user_name = _.get(filter, 'user_name');
|
|
|
+ let user_id = _.get(filter, 'user_id');
|
|
|
|
|
|
- if (!user_id) return filter;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- let probablyList = [ user_id ];
|
|
|
-
|
|
|
+ if (!user_id && !user_name) return filter;
|
|
|
const usualCondition = _.pick(filter, [ 'match_id', 'group_id', 'project_id' ]);
|
|
|
-
|
|
|
- const teamApplyList = await this.teamApplyModel.find({ ...usualCondition, status: '1', $or: [{ one_member_id: user_id }, { two_member_id: user_id }] }, { _id: 1 });
|
|
|
- const teamApplyIds = teamApplyList.map(i => i._id);
|
|
|
- probablyList.push(...teamApplyIds);
|
|
|
-
|
|
|
- delete filter.user_id;
|
|
|
-
|
|
|
- probablyList = probablyList.map(i => ObjectId(i).toString());
|
|
|
- filter.$or = [{ player_one: { $in: probablyList } }, { player_two: { $in: probablyList } }];
|
|
|
+
|
|
|
+ if (user_name) {
|
|
|
+
|
|
|
+ const baseUser = await this.baseUserModel.findOne({ name: new RegExp(user_name) }, { _id: 1 });
|
|
|
+ if (!baseUser) delete filter.user_name;
|
|
|
+ delete filter.user_name;
|
|
|
+ const baseUserId = baseUser._id;
|
|
|
+ const raceUser = await this.userModel.findOne({ user_id: baseUserId, type: '0' });
|
|
|
+ if (raceUser) user_id = raceUser._id;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (user_id) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ let probablyList = [ user_id ];
|
|
|
+
|
|
|
+
|
|
|
+ const teamApplyList = await this.teamApplyModel.find({ ...usualCondition, status: '1', $or: [{ one_member_id: user_id }, { two_member_id: user_id }] }, { _id: 1 });
|
|
|
+ const teamApplyIds = teamApplyList.map(i => i._id);
|
|
|
+ probablyList.push(...teamApplyIds);
|
|
|
+
|
|
|
+ delete filter.user_id;
|
|
|
+
|
|
|
+ probablyList = probablyList.map(i => ObjectId(i).toString());
|
|
|
+ filter.$or = [{ player_one: { $in: probablyList } }, { player_two: { $in: probablyList } }];
|
|
|
+ }
|
|
|
return filter;
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
turnFilter(filter) {
|
|
@@ -137,30 +154,30 @@ class MatchSmallGroupScheduleService extends CrudService {
|
|
|
}
|
|
|
const { refMods, populate } = await this.getRefMods();
|
|
|
|
|
|
- let res = await this.model.findOne(filter, projection).populate(populate).exec();
|
|
|
- res = JSON.parse(JSON.stringify(res));
|
|
|
- for (const obj of refMods) {
|
|
|
- const { col, prop, type } = obj;
|
|
|
- if (!prop) continue;
|
|
|
- if (_.isArray(prop)) {
|
|
|
- for (const p of prop) {
|
|
|
- if (type === 'String') res[`${col}_${p}`] = _.get(res, `${col}.${p}`);
|
|
|
- if (type === 'Array') {
|
|
|
- const list = [];
|
|
|
- const oList = _.get(res, `${col}`);
|
|
|
- for (const d of oList) {
|
|
|
- const obj = { _id: d._id };
|
|
|
- obj[p] = _.get(d, p);
|
|
|
- list.push(obj);
|
|
|
- }
|
|
|
- res[`${col}_${p}`] = list;
|
|
|
- }
|
|
|
- }
|
|
|
- res[col] = _.get(res, `${col}._id`);
|
|
|
- }
|
|
|
- }
|
|
|
- res = await this.afterFetch(filter, res);
|
|
|
- return res;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
async afterFetch(filter, d) {
|
|
|
const { player_type, player_one, player_two, referee_id } = d;
|
|
@@ -187,6 +204,65 @@ class MatchSmallGroupScheduleService extends CrudService {
|
|
|
|
|
|
return d;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ async checkSchema(ref) {
|
|
|
+ const schema = this.findModel(ref);
|
|
|
+ for (const key in schema) {
|
|
|
+ const { ref, refPath } = schema[key];
|
|
|
+ if (!ref && !refPath) continue;
|
|
|
+ const obj = { };
|
|
|
+ if (ref) {
|
|
|
+ const arr = ref.split('.');
|
|
|
+ obj.ref = _.upperFirst(_.last(arr));
|
|
|
+ if (arr.length > 0) {
|
|
|
+
|
|
|
+ arr.pop();
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ findModel(modelName, path) {
|
|
|
+
|
|
|
+ const modelPath = [];
|
|
|
+ if (path) modelPath.push(...path.split('.'));
|
|
|
+ modelPath.push(_.upperFirst(modelName));
|
|
|
+ const modelPathStr = modelPath.join('.');
|
|
|
+ const m = _.get(this.ctx.model, modelPathStr);
|
|
|
+ if (m) return _.get(m, 'prototype.schema.obj');
|
|
|
+ let returnData;
|
|
|
+
|
|
|
+ modelPath.pop();
|
|
|
+ const dir = modelPath.join('.');
|
|
|
+ const rootModel = _.get(this.ctx.model, dir, this.ctx.model);
|
|
|
+ for (const mn in rootModel) {
|
|
|
+ const type = typeof rootModel[mn];
|
|
|
+ if (type === 'object') {
|
|
|
+
|
|
|
+ returnData = this.findModel(modelName, mn);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return returnData;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
module.exports = MatchSmallGroupScheduleService;
|