liuyu пре 4 година
родитељ
комит
fa7d455fc7
3 измењених фајлова са 20 додато и 0 уклоњено
  1. 6 0
      app/controller/class.js
  2. 1 0
      app/router.js
  3. 13 0
      app/service/class.js

+ 6 - 0
app/controller/class.js

@@ -26,6 +26,12 @@ class ClassController extends Controller {
     const res = await this.service.uptea(this.ctx.request.body);
     this.ctx.ok({ data: res });
   }
+
+  // 根据班级id与学生id修改学生班级
+  async studentupclass() {
+    const res = await this.service.studentupclass(this.ctx.params, this.ctx.request.body);
+    this.ctx.ok({ data: res });
+  }
 }
 
 module.exports = CrudController(ClassController, meta);

+ 1 - 0
app/router.js

@@ -58,6 +58,7 @@ module.exports = app => {
   router.post('class', '/api/train/class/update/:id', controller.class.update);
   router.post('class', '/api/train/class/divide', controller.class.divide);
   router.post('class', '/api/train/class/uptea', controller.class.uptea);
+  router.post('class', '/api/train/class/upstuclass/:id', controller.class.studentupclass); // 学生修改班级
 
   // 部门表设置路由
   router.resources('department', '/api/train/department', controller.department); // index、create、show、destroy

+ 13 - 0
app/service/class.js

@@ -57,6 +57,19 @@ class ClassService extends CrudService {
     }
   }
 
+  // 根据传入的学生列表和班级id更新学生信息
+  async studentupclass({ id }, data) {
+    assert(id, '班级id为必填项');
+    // 循环学生id
+    for (const stuid of data) {
+      const student = await this.stumodel.findById(stuid);
+      if (student) {
+        student.classid = id;
+        await student.save();
+      }
+    }
+  }
+
   async notice(data) {
     for (const classid of data.classids) {
       // 根据班级id找到需要通知的班级