|
@@ -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;
|