|
@@ -3,7 +3,7 @@ import { InjectEntityModel } from '@midwayjs/typegoose';
|
|
|
import { ReturnModelType } from '@typegoose/typegoose';
|
|
|
import { BaseService, PageOptions, SearchBase } from 'free-midway-component';
|
|
|
import { Chat } from '../entity/chat.entity';
|
|
|
-import { cloneDeep } from 'lodash';
|
|
|
+import { cloneDeep, get, head } from 'lodash';
|
|
|
type modelType = ReturnModelType<typeof Chat>;
|
|
|
@Provide()
|
|
|
export class ChatService extends BaseService<modelType> {
|
|
@@ -50,6 +50,8 @@ export class ChatService extends BaseService<modelType> {
|
|
|
|
|
|
pipes.push({ $addFields: { 'l.gid': { $toObjectId: '$l.group' }, 'l.pid': { $toObjectId: '$l.patient' }, 'l.did': { $toObjectId: '$l.doctor' }, 'l.notRead': '$notRead' } });
|
|
|
pipes.push({ $replaceRoot: { newRoot: '$l' } });
|
|
|
+
|
|
|
+
|
|
|
pipes.push({
|
|
|
$lookup: {
|
|
|
from: 'group',
|
|
@@ -78,12 +80,13 @@ export class ChatService extends BaseService<modelType> {
|
|
|
});
|
|
|
pipes.push({ $unwind: '$dInfo' });
|
|
|
if (name) {
|
|
|
- pipes.push({ $match: { 'pInfo.name': name } });
|
|
|
+ pipes.push({ $match: { 'pInfo.name': new RegExp(name) } });
|
|
|
}
|
|
|
pipes.push({ $project: this.lastChatRecordListItem });
|
|
|
+ const totalResult = await this.model.aggregate([...pipes, { $count: 'total' }]);
|
|
|
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;
|
|
|
+ return { data: result, total: get(head(totalResult), 'total') };
|
|
|
}
|
|
|
}
|