Selaa lähdekoodia

修改分组问题

liuyu 5 vuotta sitten
vanhempi
commit
fca7ed298d
1 muutettua tiedostoa jossa 7 lisäystä ja 4 poistoa
  1. 7 4
      app/service/class.js

+ 7 - 4
app/service/class.js

@@ -61,10 +61,13 @@ class ClassService extends CrudService {
 
   // 自动分组
   async groupcreate(termid, batchid, classid) {
-    for (let i = 1; i < 8; i++) {
-      const name = i + '组';
-      const newdata = { name, termid, batchid, classid };
-      await this.gmodel.create(newdata);
+    const group = await this.gmodel.find({ termid, batchid, classid });
+    if (group.length === 0) {
+      for (let i = 1; i < 8; i++) {
+        const name = i + '组';
+        const newdata = { name, termid, batchid, classid };
+        await this.gmodel.create(newdata);
+      }
     }
   }