فهرست منبع

Merge branch 'main' of http://git.cc-lotus.info/follow-up/follow_server

lrf 1 سال پیش
والد
کامیت
7979362405
2فایلهای تغییر یافته به همراه27 افزوده شده و 0 حذف شده
  1. 7 0
      src/controller/chat.controller.ts
  2. 20 0
      src/service/chat.service.ts

+ 7 - 0
src/controller/chat.controller.ts

@@ -55,6 +55,13 @@ export class ChatController extends BaseController {
     return result;
   }
 
+  @Get('/allRead')
+  @verifyToken()
+  async allRead(@Query('group') group: string, @Query('patient') patient: string, @Query('doctor') doctor: string) {
+    await this.service.allRead({ group, patient, doctor });
+    return 'ok';
+  }
+
   @Post('/:id')
   @verifyToken()
   @Validate()

+ 20 - 0
src/service/chat.service.ts

@@ -5,6 +5,10 @@ import { BaseService, PageOptions, SearchBase } from 'free-midway-component';
 import { Chat } from '../entity/chat.entity';
 import { cloneDeep } 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()
 export class ChatService extends BaseService<modelType> {
@@ -13,6 +17,22 @@ export class ChatService extends BaseService<modelType> {
   @Inject()
   chatMqService: ChatMqService;
 
+  @Inject()
+  jwtService: JwtService;
+
+  // 处理已读问题
+  async allRead(data) {
+    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 } });
+  }
+
   async sendMq(data) {
     // 队列: /${群组id}/${患者id}
     const { group, patient, _id } = data;