c2-mongoose 2.0.4 → 2.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,7 +7,7 @@ declare class CrudFlow<D> extends SearchFlow {
7
7
  delete: (id: string, session?: any) => Promise<void>;
8
8
  update: (id: string, data: D, session?: any) => Promise<D>;
9
9
  find: (search: SearchFlow) => Promise<SearchResponse<D>>;
10
- getOne: (model: D, select: undefined, populate: string | [] | any, sort?: undefined) => Promise<D>;
10
+ getOne: (model: D, params?: any) => Promise<D>;
11
11
  get: (id: string, pop?: string, sel?: string) => Promise<D>;
12
12
  }
13
13
  export default CrudFlow;
@@ -106,14 +106,13 @@ var CrudFlow = /** @class */ (function (_super) {
106
106
  }
107
107
  });
108
108
  }); };
109
- _this.getOne = function (model, select, populate, sort) {
110
- if (select === void 0) { select = undefined; }
111
- if (sort === void 0) { sort = undefined; }
109
+ _this.getOne = function (model, params) {
110
+ if (params === void 0) { params = {}; }
112
111
  return __awaiter(_this, void 0, void 0, function () {
113
112
  var data;
114
113
  return __generator(this, function (_a) {
115
114
  switch (_a.label) {
116
- case 0: return [4 /*yield*/, _super.prototype.findOne.call(this, this.repository, model, select, populate, sort)];
115
+ case 0: return [4 /*yield*/, _super.prototype.findOne.call(this, this.repository, model, params)];
117
116
  case 1:
118
117
  data = _a.sent();
119
118
  return [2 /*return*/, data];
@@ -19,7 +19,7 @@ declare abstract class SearchFlow {
19
19
  private searchNoPageable;
20
20
  private result;
21
21
  count: (model: mongoose.Model<any>) => Promise<number>;
22
- findOne(repository: mongoose.Model<any>, model: any, select: undefined, populate: string | [] | any, sort?: undefined): Promise<any>;
22
+ findOne(repository: mongoose.Model<any>, model: any, params?: any): Promise<any>;
23
23
  sumBy: (model: mongoose.Model<any>, _sum: any, _by: any) => Promise<any[]>;
24
24
  buildDefaultFilters: (objectSearch: any) => any;
25
25
  addFilterModel: (model: any, filters: any) => void;
@@ -260,16 +260,15 @@ var SearchFlow = /** @class */ (function () {
260
260
  this.limit = params.limit || 25;
261
261
  this.buildPopulate();
262
262
  }
263
- SearchFlow.prototype.findOne = function (repository, model, select, populate, sort) {
264
- if (select === void 0) { select = undefined; }
265
- if (sort === void 0) { sort = undefined; }
263
+ SearchFlow.prototype.findOne = function (repository, model, params) {
264
+ if (params === void 0) { params = {}; }
266
265
  return __awaiter(this, void 0, void 0, function () {
267
266
  return __generator(this, function (_a) {
268
267
  switch (_a.label) {
269
268
  case 0: return [4 /*yield*/, repository.findOne(model)
270
- .sort(sort)
271
- .select(select)
272
- .populate(populate)];
269
+ .sort(params.sort)
270
+ .select(params.select)
271
+ .populate(params.populate)];
273
272
  case 1: return [2 /*return*/, _a.sent()];
274
273
  }
275
274
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "description": "Lib to make any search in database mongoose and use as basic crud",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -27,8 +27,8 @@ class CrudFlow<D> extends SearchFlow {
27
27
  return await search.search(this.repository)
28
28
  }
29
29
 
30
- public getOne = async (model: D, select = undefined, populate: string | [] | any, sort = undefined): Promise<D> => {
31
- const data = await super.findOne(this.repository, model, select, populate, sort)
30
+ public getOne = async (model: D, params: any = {}): Promise<D> => {
31
+ const data = await super.findOne(this.repository, model, params)
32
32
  return data as D
33
33
  }
34
34
 
@@ -133,11 +133,11 @@ abstract class SearchFlow {
133
133
  return await model.countDocuments(this.filters).exec()
134
134
  }
135
135
 
136
- public async findOne(repository: mongoose.Model<any>, model: any, select = undefined, populate: string | [] | any, sort = undefined) {
136
+ public async findOne(repository: mongoose.Model<any>, model: any, params: any = {}) {
137
137
  return await repository.findOne(model)
138
- .sort(sort)
139
- .select(select)
140
- .populate(populate)
138
+ .sort(params.sort)
139
+ .select(params.select)
140
+ .populate(params.populate)
141
141
  }
142
142
 
143
143
  public sumBy = async (model: mongoose.Model<any>, _sum: any, _by: any): Promise<any[]> => {