lrf 2 лет назад
Родитель
Сommit
369141a66c
1 измененных файлов с 18 добавлено и 0 удалено
  1. 18 0
      app/service/matchSmallGroupSchedule.js

+ 18 - 0
app/service/matchSmallGroupSchedule.js

@@ -22,6 +22,24 @@ class MatchSmallGroupScheduleService extends CrudService {
       }
       }
     }
     }
   }
   }
+
+  async beforeCreate(body) {
+    // 检查数据是否有重复,如果符合检查重复条件,就把之前的删了,用新来的
+    const { match_id, group_id, project_id, team_id, player_one, player_two } = body;
+    const query = {
+      match_id,
+      group_id,
+      project_id,
+      team_id,
+      $or: [
+        { player_one, player_two },
+        { player_one: player_two, player_two: player_one },
+      ],
+    };
+    const d = await this.model.findOne(query);
+    if (d) await this.model.deleteOne(query);
+    return body;
+  }
 }
 }
 
 
 module.exports = MatchSmallGroupScheduleService;
 module.exports = MatchSmallGroupScheduleService;