Pārlūkot izejas kodu

添加患者姓名查询

lrf 1 gadu atpakaļ
vecāks
revīzija
ba720ae0ff
2 mainītis faili ar 12 papildinājumiem un 4 dzēšanām
  1. 2 2
      src/controller/chat.controller.ts
  2. 10 2
      src/service/chat.service.ts

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

@@ -11,8 +11,8 @@ export class ChatController extends BaseController {
   service: ChatService;
 
   @Get('/lcl')
-  async getLastChatRecordList(@Query('doctor') doctor: string, @Query('skip') skip: number, @Query('limit') limit: number) {
-    const result = await this.service.getLastChatRecordList(doctor, skip, limit);
+  async getLastChatRecordList(@Query('doctor') doctor: string, @Query('name') name: string, @Query('skip') skip: number, @Query('limit') limit: number) {
+    const result = await this.service.getLastChatRecordList(doctor, skip, limit, name);
     return result;
   }
 

+ 10 - 2
src/service/chat.service.ts

@@ -29,8 +29,13 @@ export class ChatService extends BaseService<modelType> {
 
   /**
    * 根据医护.查找最后发送消息记录
+   * @param doctor 医生id
+   * @param skip 分页
+   * @param limit 分页
+   * @param name 患者姓名,查询用
+   * @returns
    */
-  async getLastChatRecordList(doctor: string, skip: number, limit: number) {
+  async getLastChatRecordList(doctor: string, skip?: number, limit?: number, name?: string) {
     const pipes = [];
     const query = { doctor };
     pipes.push({ $match: query });
@@ -72,8 +77,11 @@ export class ChatService extends BaseService<modelType> {
       },
     });
     pipes.push({ $unwind: '$dInfo' });
-    if (skip && skip >= 0) pipes.push({ $skip: skip });
+    if (name) {
+      pipes.push({ $match: { 'pInfo.name': name } });
+    }
     pipes.push({ $project: this.lastChatRecordListItem });
+    if (skip && skip >= 0) pipes.push({ $skip: skip });
     if (limit && limit > 0) pipes.push({ $limit: limit });
     const result = await this.model.aggregate(pipes);
     return result;