Explorar o código

修改分组问题

liuyu %!s(int64=5) %!d(string=hai) anos
pai
achega
fca7ed298d
Modificáronse 1 ficheiros con 7 adicións e 4 borrados
  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);
+      }
     }
   }