|
@@ -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 ChatService extends CrudService {
|
|
|
constructor(ctx) {
|
|
@@ -12,15 +13,17 @@ class ChatService extends CrudService {
|
|
|
this.cDoctor = this.ctx.model.Doctor;
|
|
|
this.cPatient = this.ctx.model.Patient;
|
|
|
this.cRoom = this.ctx.model.Room;
|
|
|
+ this.remark = this.ctx.model.Remark;
|
|
|
}
|
|
|
|
|
|
- async query({ sendid, receiveid, type, sort = 1 }, { skip, limit }) {
|
|
|
+ async query({ sendid, receiveid, type, sort = 1, userid }, { skip, limit }) {
|
|
|
assert(sendid, 'sendid不能为空');
|
|
|
assert(receiveid, 'receiveid不能为空');
|
|
|
const chatsall = await this.model.find({ $or: [{ sendid, receiveid }, { sendid: receiveid, receiveid: sendid }] });
|
|
|
const chats = await this.model.find({ $or: [{ sendid, receiveid }, { sendid: receiveid, receiveid: sendid }] }).sort({ sendtime: sort }).limit(limit)
|
|
|
.skip(skip);
|
|
|
const newchats = [];
|
|
|
+ const remarks = await this.remark.find({ remarkid: userid });
|
|
|
for (const el of chats) {
|
|
|
let icon;
|
|
|
if (el.type === '1') {
|
|
@@ -31,7 +34,11 @@ class ChatService extends CrudService {
|
|
|
const doctor = await this.cDoctor.findById(el.sendid);
|
|
|
if (doctor) icon = doctor.icon;
|
|
|
}
|
|
|
- const { id, type, sendid, sendname, receiveid, receivename, sendtime, contenttype, content, status, audiotime } = el;
|
|
|
+ let { id, type, sendid, sendname, receiveid, receivename, sendtime, contenttype, content, status, audiotime } = el;
|
|
|
+ const s_r = remarks.find(f => ObjectId(f.benoteid).equals(sendid));
|
|
|
+ if (s_r) sendname = s_r.name;
|
|
|
+ const r_r = remarks.find(f => ObjectId(f.benoteid).equals(receiveid));
|
|
|
+ if (r_r) receivename = r_r.name;
|
|
|
newchats.push({ id, type, sendid, sendname, receiveid, receivename, sendtime, contenttype, content, status, icon, audiotime });
|
|
|
}
|
|
|
const result = { total: chatsall.length, data: newchats };
|