lrf402788946 %!s(int64=4) %!d(string=hai) anos
pai
achega
6a6b799d27
Modificáronse 3 ficheiros con 20 adicións e 1 borrados
  1. 5 0
      app/controller/group.js
  2. 1 0
      app/router.js
  3. 14 1
      app/service/group.js

+ 5 - 0
app/controller/group.js

@@ -55,6 +55,11 @@ class GroupController extends Controller {
     await this.service.delete({ id });
     this.ctx.ok({ msg: 'deleted' });
   }
+
+  async exit() {
+    await this.service.exit(this.ctx.request.body);
+    this.ctx.ok();
+  }
 }
 
 module.exports = GroupController;

+ 1 - 0
app/router.js

@@ -18,6 +18,7 @@ module.exports = app => {
   router.resources('nurse', '/api/visit/nurse', controller.nurse); // index、create、show、destroy
   router.post('nurse', '/api/visit/nurse/:id', controller.nurse.update);
   router.post('nurse', '/api/visit/nurse/login', controller.nurse.login);
+  router.post('/api/visit/group/exit', controller.group.exit);
   router.resources('group', '/api/visit/group', controller.group); // index、create、show、destroy
   router.get('/api/visit/group/:id/info', controller.group.info);
   router.post('/api/visit/group/:id/info', controller.group.info);

+ 14 - 1
app/service/group.js

@@ -4,7 +4,7 @@ const assert = require('assert');
 const _ = require('lodash');
 const { CrudService } = require('naf-framework-mongoose/lib/service');
 const { BusinessError, ErrorCode } = require('naf-core').Error;
-
+const { ObjectId } = require('mongoose').Types;
 class GroupService extends CrudService {
   constructor(ctx) {
     super(ctx, 'group');
@@ -115,6 +115,19 @@ class GroupService extends CrudService {
     return await this.model.findById(groupid, '+patients');
   }
 
+  /**
+   * 退群
+   * @param {Object} params 群组id,病人id
+   */
+  async exit({ groupid, patientid }) {
+    const group = await this.model.findById(groupid, '+patients');
+    if (!group) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到指定群组');
+    const patient = group.patients.find(f => ObjectId(f.patientid).equals(patientid));
+    if (!patient) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到指定病人');
+    await group.patients.id(patient._id).remove();
+    await group.save();
+  }
+
 }
 
 module.exports = GroupService;