|
@@ -4,6 +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 GroupChatService extends CrudService {
|
|
|
constructor(ctx) {
|
|
@@ -12,17 +13,19 @@ class GroupChatService extends CrudService {
|
|
|
this.cGroup = this.ctx.model.Group;
|
|
|
this.cDoctor = this.ctx.model.Doctor;
|
|
|
this.cPatient = this.ctx.model.Patient;
|
|
|
+ this.remark = this.ctx.model.Remark;
|
|
|
}
|
|
|
|
|
|
- async query({ groupid, sort = 1 }, { skip, limit }) {
|
|
|
+ async query({ groupid, sort = 1, userid }, { skip, limit }) {
|
|
|
assert(groupid, 'groupid不能为空');
|
|
|
const groupall = await this.model.find({ groupid });
|
|
|
const groups = await this.model.find({ groupid }).sort({ sendtime: sort }).limit(limit)
|
|
|
.skip(skip);
|
|
|
const newgroups = [];
|
|
|
+ const remarks = await this.remark.find({ remarkid: userid });
|
|
|
for (const el of groups) {
|
|
|
let icon;
|
|
|
- const { id, doctorid, doctorname, groupid, groupname, type, sendid, sendname, sendtime, contenttype, content, audiotime } = el;
|
|
|
+ let { id, doctorid, doctorname, groupid, groupname, type, sendid, sendname, sendtime, contenttype, content, audiotime } = el;
|
|
|
if (el.type === '1') {
|
|
|
const patient = await this.cPatient.findById(el.sendid);
|
|
|
if (patient) {
|
|
@@ -33,6 +36,10 @@ class GroupChatService extends CrudService {
|
|
|
const doctor = await this.cDoctor.findById(el.sendid);
|
|
|
if (doctor) icon = doctor.icon;
|
|
|
}
|
|
|
+ const d_r = remarks.find(f => ObjectId(f.benoteid).equals(doctorid));
|
|
|
+ if (d_r) doctorname = d_r.name;
|
|
|
+ const p_r = remarks.find(f => ObjectId(f.benoteid).equals(sendid));
|
|
|
+ if (p_r) sendname = p_r.name;
|
|
|
const group = { id, doctorid, doctorname, groupid, groupname, type, sendid, sendname, sendtime, contenttype, content, icon, audiotime };
|
|
|
newgroups.push(group);
|
|
|
}
|