|
@@ -85,32 +85,6 @@ class MatchSmallGroupScheduleService extends CrudService {
|
|
|
return filter;
|
|
|
}
|
|
|
|
|
|
- turnFilter(filter) {
|
|
|
- const str = /^%\S*%$/;
|
|
|
-
|
|
|
- let keys = Object.keys(filter).filter(f => !f.includes('$'));
|
|
|
- for (const key of keys) {
|
|
|
- const res = key.match(str);
|
|
|
- if (res) {
|
|
|
- const newKey = key.slice(1, key.length - 1);
|
|
|
- if (!ObjectId.isValid(filter[key])) filter[newKey] = new RegExp(filter[key]);
|
|
|
- delete filter[key];
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- keys = Object.keys(filter).filter(f => !f.includes('$'));
|
|
|
- for (const key of keys) {
|
|
|
- if (_.isArray(filter[key])) {
|
|
|
- filter[key] = { $in: filter[key] };
|
|
|
- } else if (filter[key] === 'true' || filter[key] === 'false') {
|
|
|
-
|
|
|
- filter[key] = filter[key] === 'true';
|
|
|
- }
|
|
|
- }
|
|
|
- return filter;
|
|
|
- }
|
|
|
-
|
|
|
async afterQuery(filter, data) {
|
|
|
data = JSON.parse(JSON.stringify(data));
|
|
|
for (const d of data) {
|
|
@@ -125,10 +99,10 @@ class MatchSmallGroupScheduleService extends CrudService {
|
|
|
d.player_two_name = _.get(user2, 'name');
|
|
|
d.player_two = _.get(d, 'player_two._id');
|
|
|
} else if (player_type === 'TeamApply') {
|
|
|
- d.player_one_name = `${_.get(d, 'player_one.one_member_name')}-${_.get(d, 'player_one.two_member_name')}`;
|
|
|
- d.player_one = _.get(d, 'player_one._id');
|
|
|
- d.player_two_name = `${_.get(d, 'player_two.one_member_name')}-${_.get(d, 'player_two.two_member_name')}`;
|
|
|
- d.player_two = _.get(d, 'player_two._id');
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
const referee = await this.userModel.findById(referee_id).populate({
|
|
@@ -203,6 +177,26 @@ class MatchSmallGroupScheduleService extends CrudService {
|
|
|
|
|
|
return d;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ resetPopulate(schema) {
|
|
|
+ const arr = [];
|
|
|
+ for (const key in schema) {
|
|
|
+ const e = schema[key];
|
|
|
+ const { ref, refPath } = e;
|
|
|
+ if (!ref && !refPath) continue;
|
|
|
+ const refValue = ref || refPath;
|
|
|
+ const obj = { path: key };
|
|
|
+ const modelPath = this.formatModelPath(refValue);
|
|
|
+ const model = this.getModel(modelPath);
|
|
|
+ obj.model = model;
|
|
|
+ const msch = this.getSchema(modelPath);
|
|
|
+ const popu = this.resetPopulate(msch);
|
|
|
+ if (popu.length > 0) obj.populate = popu;
|
|
|
+ arr.push(obj);
|
|
|
+ }
|
|
|
+ return arr;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
module.exports = MatchSmallGroupScheduleService;
|