|
@@ -2,7 +2,7 @@ import { ReturnModelType } from '@typegoose/typegoose';
|
|
|
import { AnyParamConstructor } from '@typegoose/typegoose/lib/types';
|
|
|
import { Application, Context } from '@midwayjs/koa';
|
|
|
import { App, Inject } from '@midwayjs/decorator';
|
|
|
-import _ = require('lodash');
|
|
|
+import { cloneDeep, get } from 'lodash'
|
|
|
import { FrameworkErrorEnum, ServiceError } from '../error/service.error';
|
|
|
import { GetModel } from '../util/getModel';
|
|
|
import { SearchBase } from '../interface/SearchBase';
|
|
@@ -29,7 +29,7 @@ export abstract class BaseService<T extends AnyParamConstructor<any>> {
|
|
|
* @returns {Promise<object>} 返回列表
|
|
|
*/
|
|
|
async query(filter: SearchBase, pageOptions: PageOptions = {}, resultOptions: ResultOptions = { lean: true, populate: true }): Promise<Array<any>> {
|
|
|
- const dup = _.cloneDeep(filter.getFilter());
|
|
|
+ const dup = cloneDeep(filter.getFilter());
|
|
|
const { lean, populate } = resultOptions;
|
|
|
let refs = [];
|
|
|
if (populate) refs = this.getRefs();
|
|
@@ -46,7 +46,7 @@ export abstract class BaseService<T extends AnyParamConstructor<any>> {
|
|
|
* @returns {number} 数据总数
|
|
|
*/
|
|
|
async count(filter: SearchBase): Promise<number> {
|
|
|
- const dup = _.cloneDeep(filter.getFilter());
|
|
|
+ const dup = cloneDeep(filter.getFilter());
|
|
|
const total = await this.model.count(dup);
|
|
|
return total;
|
|
|
}
|
|
@@ -99,7 +99,7 @@ export abstract class BaseService<T extends AnyParamConstructor<any>> {
|
|
|
*/
|
|
|
async updateMany(filter: SearchBase, body: object): Promise<string> {
|
|
|
if (!body) throw new ServiceError('缺少修改信息', FrameworkErrorEnum.NEED_BODY);
|
|
|
- const dup = _.cloneDeep(filter.getFilter());
|
|
|
+ const dup = cloneDeep(filter.getFilter());
|
|
|
await this.model.updateMany(dup, body);
|
|
|
return 'ok';
|
|
|
}
|
|
@@ -123,7 +123,7 @@ export abstract class BaseService<T extends AnyParamConstructor<any>> {
|
|
|
async deleteMany(filter: SearchBase): Promise<string> {
|
|
|
const keys = Object.keys(filter);
|
|
|
if (keys.length <= 0) throw new ServiceError('暂不提供清库服务', FrameworkErrorEnum.SERVICE_FAULT);
|
|
|
- const dup = _.cloneDeep(filter.getFilter());
|
|
|
+ const dup = cloneDeep(filter.getFilter());
|
|
|
await this.model.deleteMany(dup);
|
|
|
return 'ok';
|
|
|
}
|
|
@@ -151,11 +151,11 @@ export abstract class BaseService<T extends AnyParamConstructor<any>> {
|
|
|
* 获取本服务默认表的ref关系
|
|
|
*/
|
|
|
getRefs(): Array<PopulateOptions> {
|
|
|
- const schema: any = _.get(this.model, 'schema.tree');
|
|
|
+ const schema: any = get(this.model, 'schema.tree');
|
|
|
const refs = [];
|
|
|
for (const key in schema) {
|
|
|
const f = schema[key];
|
|
|
- const ref = _.get(f, 'ref');
|
|
|
+ const ref = get(f, 'ref');
|
|
|
if (ref) {
|
|
|
const model = GetModel(ref);
|
|
|
const path = key;
|