lrf402788946 4 лет назад
Родитель
Сommit
4d7185e1a4
3 измененных файлов с 34 добавлено и 2 удалено
  1. 9 2
      app/service/score.js
  2. 11 0
      app/service/uploadquestion.js
  3. 14 0
      app/service/uploadtask.js

+ 9 - 2
app/service/score.js

@@ -15,8 +15,15 @@ class ScoreService extends CrudService {
   }
   }
 
 
   async create(data) {
   async create(data) {
-    const { teacherid, score } = data;
-    const res = await this.model.create(data);
+    const { lessonid, stuid, teacherid, score } = data;
+    let res = await this.model.findOne({ stuid, lessonid, teacherid });
+    if (res) {
+      if (score) res.score = score;
+      res = await res.save();
+    } else {
+      res = await this.model.create(data);
+    }
+    // const res = await this.model.create(data);
     this.computedScore({ teacherid });
     this.computedScore({ teacherid });
     return res;
     return res;
   }
   }

+ 11 - 0
app/service/uploadquestion.js

@@ -98,6 +98,17 @@ class UploadquestionService extends CrudService {
     return { data, total };
     return { data, total };
   }
   }
 
 
+  async create(data) {
+    const { questionnaireid, studentid, answers } = data;
+    let res = await this.model.findOne({ questionnaireid, studentid });
+    if (res) {
+      if (answers) res.answers = answers;
+      res = await res.save();
+    } else {
+      res = await this.model.create(data);
+    }
+  }
+
 }
 }
 
 
 module.exports = UploadquestionService;
 module.exports = UploadquestionService;

+ 14 - 0
app/service/uploadtask.js

@@ -29,6 +29,20 @@ class UploadtaskService extends CrudService {
     }
     }
     return { data, total };
     return { data, total };
   }
   }
+  async create(data) {
+    const { studentid, lessonid } = data;
+    let res = await this.model.findOne({ studentid, lessonid });
+    if (res) {
+      // 存在数据,但是页面还是创建提交,需要进行修改
+      if (_.get(data, 'picurl')) res.picurl = _.get(data, 'picurl');
+      if (_.get(data, 'taskid')) res.taskid = _.get(data, 'taskid');
+      if (_.get(data, 'answers')) res.picurl = _.get(data, 'answers');
+      res = await res.save();
+    } else {
+      res = await this.model.create(data);
+    }
+    return res;
+  }
 }
 }
 
 
 module.exports = UploadtaskService;
 module.exports = UploadtaskService;