Procházet zdrojové kódy

Merge branch 'master' of http://git.cc-lotus.info/new_train/service-center

liuyu před 5 roky
rodič
revize
e468ba2aa6
4 změnil soubory, kde provedl 27 přidání a 1 odebrání
  1. 10 0
      app/controller/group.js
  2. 2 0
      app/router.js
  3. 14 0
      app/service/group.js
  4. 1 1
      app/service/school.js

+ 10 - 0
app/controller/group.js

@@ -13,6 +13,16 @@ class GroupController extends Controller {
     this.service = this.ctx.service.group;
   }
 
+  async insert() {
+    const res = await this.service.insert(this.ctx.request.body);
+    this.ctx.ok({ msg: 'ok', data: res });
+  }
+
+  async exit() {
+    const res = await this.service.exit(this.ctx.request.body);
+    this.ctx.ok({ msg: 'ok', data: res });
+  }
+
 
 }
 

+ 2 - 0
app/router.js

@@ -97,6 +97,8 @@ module.exports = app => {
   // 分组表设置路由
   router.resources('group', '/api/train/group', controller.group); // index、create、show、destroy
   router.post('group', '/api/train/group/update/:id', controller.group.update);
+  router.post('group', '/api/train/group/insert', controller.group.insert);
+  router.post('group', '/api/train/group/exit', controller.group.exit);
 
   // 职责说明表设置路由
   router.resources('duty', '/api/train/duty', controller.duty); // index、create、show、destroy

+ 14 - 0
app/service/group.js

@@ -13,6 +13,20 @@ class GroupService extends CrudService {
     this.model = this.ctx.model.Group;
   }
 
+  async insert(data) {
+    const { groupid, studentid } = data;
+    const group = await this.model.findById(groupid);
+    group.studentid.push(studentid);
+    await group.save();
+  }
+
+  async exit(data) {
+    const { groupid, studentid } = data;
+    const group = await this.model.findById(groupid);
+    group.studentid.remove(studentid);
+    await group.save();
+  }
+
 }
 
 module.exports = GroupService;

+ 1 - 1
app/service/school.js

@@ -106,7 +106,7 @@ class SchoolService extends CrudService {
       }
       if (!data.school_name) {
         errorcode = '1';
-        data.msg = data.msg + '学校名称不允许为空,';
+        data.msg = data.msg + '学校名称不允许为空,';
       }
       if (!data.phone) {
         errorcode = '1';