|
@@ -5,12 +5,15 @@ import { BaseService } from 'free-midway-component';
|
|
|
import { Group } from '../entity/group.entity';
|
|
|
import { Types } from 'mongoose';
|
|
|
import { get, isNumber, omit } from 'lodash';
|
|
|
+import { Chat } from '../entity/chat.entity';
|
|
|
const ObjectId = Types.ObjectId;
|
|
|
type modelType = ReturnModelType<typeof Group>;
|
|
|
@Provide()
|
|
|
export class GroupService extends BaseService<modelType> {
|
|
|
@InjectEntityModel(Group)
|
|
|
model: modelType;
|
|
|
+ @InjectEntityModel(Chat)
|
|
|
+ chatModel: ReturnModelType<typeof Chat>;
|
|
|
|
|
|
/**
|
|
|
* 根据群组id,分页查询病人(只有名字)
|
|
@@ -57,4 +60,17 @@ export class GroupService extends BaseService<modelType> {
|
|
|
});
|
|
|
return afterDealList;
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 患者查群组列表时,返回患者的每个群组未读信息数量
|
|
|
+ * @param groupList 群组列表
|
|
|
+ * @param paitentId 患者id
|
|
|
+ */
|
|
|
+ async checkNotRead(groupList: Array<object>, paitentId: string) {
|
|
|
+ for (const g of groupList) {
|
|
|
+ const group = get(g, '_id');
|
|
|
+ const notRead = await this.chatModel.count({ group, speaker: { $ne: paitentId }, not_read: 1 });
|
|
|
+ g['notRead'] = notRead;
|
|
|
+ }
|
|
|
+ return groupList;
|
|
|
+ }
|
|
|
}
|