Browse Source

添加已读未读接口

zs 1 year ago
parent
commit
f5cacccace
2 changed files with 18 additions and 0 deletions
  1. 7 0
      src/controller/chat.controller.ts
  2. 11 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, @Query('speaker') speaker: string) {
+    await this.service.allRead({ group, patient, doctor, speaker });
+    return 'ok';
+  }
+
   @Post('/:id')
   @verifyToken()
   @Validate()

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

@@ -5,6 +5,8 @@ import { BaseService, PageOptions, SearchBase } from 'free-midway-component';
 import { Chat } from '../entity/chat.entity';
 import { cloneDeep, get, head } from 'lodash';
 import { ChatMqService } from './chatMq.service';
+import { Types } from 'mongoose';
+const ObjectId = Types.ObjectId;
 type modelType = ReturnModelType<typeof Chat>;
 @Provide()
 export class ChatService extends BaseService<modelType> {
@@ -13,6 +15,15 @@ export class ChatService extends BaseService<modelType> {
   @Inject()
   chatMqService: ChatMqService;
 
+  // 处理已读问题
+  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 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;