ソースを参照

增加学生删除班级接口

liuyu 4 年 前
コミット
352404ac17
3 ファイル変更18 行追加0 行削除
  1. 6 0
      app/controller/student.js
  2. 1 0
      app/router.js
  3. 11 0
      app/service/student.js

+ 6 - 0
app/controller/student.js

@@ -31,6 +31,12 @@ class StudentController extends Controller {
     this.ctx.ok({ data });
   }
 
+  // 删除学生班级
+  async deleteclass() {
+    const data = await this.service.deleteclass(this.ctx.request.body);
+    this.ctx.ok({ data });
+  }
+
 }
 
 module.exports = CrudController(StudentController, meta);

+ 1 - 0
app/router.js

@@ -40,6 +40,7 @@ module.exports = app => {
   router.resources('student', '/api/train/student', controller.student); // index、create、show、destroy
   router.post('student', '/api/train/student/update/:id', controller.student.update);
   router.post('student', '/api/train/student/upjob', controller.student.upjob);
+  router.post('student', '/api/train/student/deleteclass', controller.student.deleteclass); // 删除学生班级
 
   // 班主任表设置路由
   router.resources('headteacher', '/api/train/headteacher', controller.headteacher); // index、create、show、destroy

+ 11 - 0
app/service/student.js

@@ -89,6 +89,17 @@ class StudentService extends CrudService {
     return await student.save();
   }
 
+  // 根据学生id删除班级
+  async deleteclass(data) {
+    for (const el of data) {
+      const student = await this.model.findById(el);
+      if (student) {
+        student.classid = '';
+        await student.save();
+      }
+    }
+  }
+
 }
 
 module.exports = StudentService;