c2-mongoose 2.0.3 → 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, 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,13 +106,13 @@ var CrudFlow = /** @class */ (function (_super) {
106
106
  }
107
107
  });
108
108
  }); };
109
- _this.getOne = function (model, sort) {
110
- if (sort === void 0) { sort = undefined; }
109
+ _this.getOne = function (model, params) {
110
+ if (params === void 0) { params = {}; }
111
111
  return __awaiter(_this, void 0, void 0, function () {
112
112
  var data;
113
113
  return __generator(this, function (_a) {
114
114
  switch (_a.label) {
115
- case 0: return [4 /*yield*/, _super.prototype.findOne.call(this, this.repository, model, sort)];
115
+ case 0: return [4 /*yield*/, _super.prototype.findOne.call(this, this.repository, model, params)];
116
116
  case 1:
117
117
  data = _a.sent();
118
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, 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,13 +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, sort) {
264
- if (sort === void 0) { sort = undefined; }
263
+ SearchFlow.prototype.findOne = function (repository, model, params) {
264
+ if (params === void 0) { params = {}; }
265
265
  return __awaiter(this, void 0, void 0, function () {
266
266
  return __generator(this, function (_a) {
267
267
  switch (_a.label) {
268
268
  case 0: return [4 /*yield*/, repository.findOne(model)
269
- .sort(sort)];
269
+ .sort(params.sort)
270
+ .select(params.select)
271
+ .populate(params.populate)];
270
272
  case 1: return [2 /*return*/, _a.sent()];
271
273
  }
272
274
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.0.3",
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, sort = undefined): Promise<D> => {
31
- const data = await super.findOne(this.repository, model, 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,9 +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, sort = undefined) {
136
+ public async findOne(repository: mongoose.Model<any>, model: any, params: any = {}) {
137
137
  return await repository.findOne(model)
138
- .sort(sort)
138
+ .sort(params.sort)
139
+ .select(params.select)
140
+ .populate(params.populate)
139
141
  }
140
142
 
141
143
  public sumBy = async (model: mongoose.Model<any>, _sum: any, _by: any): Promise<any[]> => {