|
@@ -3,9 +3,32 @@ import { InjectEntityModel } from '@midwayjs/typegoose';
|
|
|
import { ReturnModelType } from '@typegoose/typegoose';
|
|
|
import { BaseService } from 'free-midway-component';
|
|
|
import { Car } from '../entity/car.entity';
|
|
|
+import { get, isNumber } from 'lodash';
|
|
|
type modelType = ReturnModelType<typeof Car>;
|
|
|
@Provide()
|
|
|
export class CarService extends BaseService<modelType> {
|
|
|
@InjectEntityModel(Car)
|
|
|
model: modelType;
|
|
|
+ async queryList(filter) {
|
|
|
+ const { skip = 0, limit, ...info } = filter;
|
|
|
+ const pipes: any[] = [
|
|
|
+ { $match: info },
|
|
|
+ {
|
|
|
+ $facet: {
|
|
|
+ total: [{ $count: 'count' }],
|
|
|
+ rows: [],
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ $project: {
|
|
|
+ data: '$rows',
|
|
|
+ total: { $arrayElemAt: ['$total.count', 0] },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ];
|
|
|
+ if (isNumber(skip) && skip > -1) pipes.push({ $skip: skip });
|
|
|
+ if (isNumber(limit) && limit > 0) pipes.push({ $limit: limit });
|
|
|
+ const result = await this.model.aggregate(pipes);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
}
|