c2-mongoose 2.0.3 → 2.0.4

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