Sfoglia il codice sorgente

修改聊天记录已读

zs 1 anno fa
parent
commit
5dbeea73a1
2 ha cambiato i file con 14 aggiunte e 5 eliminazioni
  1. 2 2
      src/controller/chat.controller.ts
  2. 12 3
      src/service/chat.service.ts

+ 2 - 2
src/controller/chat.controller.ts

@@ -57,8 +57,8 @@ export class ChatController extends BaseController {
 
   @Get('/allRead')
   @verifyToken()
-  async allRead(@Query('group') group: string, @Query('patient') patient: string, @Query('doctor') doctor: string, @Query('speaker') speaker: string) {
-    await this.service.allRead({ group, patient, doctor, speaker });
+  async allRead(@Query('group') group: string, @Query('patient') patient: string, @Query('doctor') doctor: string) {
+    await this.service.allRead({ group, patient, doctor });
     return 'ok';
   }
 

+ 12 - 3
src/service/chat.service.ts

@@ -6,6 +6,8 @@ import { Chat } from '../entity/chat.entity';
 import { cloneDeep, get, head } from 'lodash';
 import { ChatMqService } from './chatMq.service';
 import { Types } from 'mongoose';
+import { JwtService } from '@midwayjs/jwt';
+const assert = require('assert');
 const ObjectId = Types.ObjectId;
 type modelType = ReturnModelType<typeof Chat>;
 @Provide()
@@ -15,11 +17,18 @@ export class ChatService extends BaseService<modelType> {
   @Inject()
   chatMqService: ChatMqService;
 
+  @Inject()
+  jwtService: JwtService;
+
   // 处理已读问题
   async allRead(data) {
-    // 群/病人/医生/发言者
-    const { group, patient, doctor, speaker } = data;
-    const result = await this.model.find({ group, patient, doctor, speaker: { $ne: speaker }, not_read: 1 }).lean();
+    const token = get(this.ctx, 'request.header.token');
+    assert(token, '缺少token信息');
+    const tokenInfo = await this.jwtService.decodeSync(token);
+    const info = { ...data, not_read: 1, speaker: { $ne: get(tokenInfo, '_id') } };
+    let result;
+    if (get(tokenInfo, 'role') === 'Patient') result = await this.model.find({ ...info }).lean();
+    else result = await this.model.find({ ...info, speaker_type: 'Patient' }).lean();
     const ids = result.map(i => new ObjectId(i._id).toString());
     await this.model.updateMany({ _id: ids }, { $set: { not_read: 0 } });
   }