c2-mongoose 2.1.212 → 2.1.214

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.
@@ -51,9 +51,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
51
51
  };
52
52
  Object.defineProperty(exports, "__esModule", { value: true });
53
53
  // import moment from "moment"
54
+ var moment_timezone_1 = __importDefault(require("moment-timezone"));
54
55
  var mongoose_1 = require("mongoose");
55
56
  var Utils_1 = require("../utils/Utils");
56
- var moment_timezone_1 = __importDefault(require("moment-timezone"));
57
+ var BuildSelectPopulateFlowItem_1 = __importDefault(require("./item/BuildSelectPopulateFlowItem"));
57
58
  var BuildSelectSingleFlowItem_1 = __importDefault(require("./item/BuildSelectSingleFlowItem"));
58
59
  var SearchFlow = /** @class */ (function () {
59
60
  function SearchFlow(params) {
@@ -214,7 +215,7 @@ var SearchFlow = /** @class */ (function () {
214
215
  if (!(_a < _b.length)) return [3 /*break*/, 5];
215
216
  populate = _b[_a];
216
217
  _c = result[0];
217
- return [4 /*yield*/, model.populate(result[0].items, __assign(__assign({}, populate), { select: this.projection ? this.projection[populate.path] : undefined }))];
218
+ return [4 /*yield*/, model.populate(result[0].items, __assign(__assign({}, populate), { select: BuildSelectPopulateFlowItem_1.default.build(model, this.projection, populate.path) }))];
218
219
  case 3:
219
220
  _c.items = _d.sent();
220
221
  _d.label = 4;
@@ -308,7 +309,7 @@ var SearchFlow = /** @class */ (function () {
308
309
  if (!(_a < _b.length)) return [3 /*break*/, 5];
309
310
  populate = _b[_a];
310
311
  _c = result[0];
311
- return [4 /*yield*/, model.populate(result[0].items, __assign(__assign({}, populate), { select: this.projection ? this.projection[populate.path] : undefined }))];
312
+ return [4 /*yield*/, model.populate(result[0].items, __assign(__assign({}, populate), { select: BuildSelectPopulateFlowItem_1.default.build(model, this.projection, populate.path) }))];
312
313
  case 3:
313
314
  _c.items = _d.sent();
314
315
  _d.label = 4;
@@ -0,0 +1,6 @@
1
+ import mongoose from "mongoose";
2
+ declare class BuildSelectPopulateFlowItem {
3
+ build(model: mongoose.Model<any>, projection: any, path: string): any;
4
+ }
5
+ declare const _default: BuildSelectPopulateFlowItem;
6
+ export default _default;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var Utils_1 = require("../../utils/Utils");
4
+ var BuildSelectPopulateFlowItem = /** @class */ (function () {
5
+ function BuildSelectPopulateFlowItem() {
6
+ }
7
+ BuildSelectPopulateFlowItem.prototype.build = function (model, projection, path) {
8
+ var campoInfo = model.schema.path(path);
9
+ // Verifique se o tipo do campo é mongoose.Types.ObjectId
10
+ if (campoInfo.instance === "ObjectID") {
11
+ return undefined;
12
+ }
13
+ if ((0, Utils_1.isEmpty)(projection[path]) || isNaN(projection[path]) === false) {
14
+ return undefined;
15
+ }
16
+ return projection[path];
17
+ };
18
+ return BuildSelectPopulateFlowItem;
19
+ }());
20
+ exports.default = new BuildSelectPopulateFlowItem;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.212",
3
+ "version": "2.1.214",
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",
@@ -1,8 +1,9 @@
1
1
  // import moment from "moment"
2
- import mongoose, { ClientSession, PopulateOption, PopulateOptions, Types, model } from "mongoose"
2
+ import moment from "moment-timezone"
3
+ import mongoose, { ClientSession, PopulateOptions, Types } from "mongoose"
3
4
  import { SearchOptions, SearchResponse } from "../types/SearchResponse"
4
5
  import { isEmpty, isNotEmpty } from "../utils/Utils"
5
- import moment from "moment-timezone"
6
+ import BuildSelectPopulateFlowItem from "./item/BuildSelectPopulateFlowItem"
6
7
  import BuildSelectSingleFlowItem from "./item/BuildSelectSingleFlowItem"
7
8
 
8
9
  interface IPopulate {
@@ -204,7 +205,7 @@ abstract class SearchFlow {
204
205
 
205
206
  if (isNotEmpty(this.populate) && Array.isArray(this.populate)) {
206
207
  for (var populate of this.populate) {
207
- result[0].items = await model.populate(result[0].items, { ...populate, select: this.projection ? this.projection[populate.path] : undefined } as PopulateOptions)
208
+ result[0].items = await model.populate(result[0].items, { ...populate, select: BuildSelectPopulateFlowItem.build(model, this.projection, populate.path) } as PopulateOptions)
208
209
  }
209
210
  }
210
211
 
@@ -294,7 +295,7 @@ abstract class SearchFlow {
294
295
 
295
296
  if (isNotEmpty(this.populate) && Array.isArray(this.populate)) {
296
297
  for (var populate of this.populate) {
297
- result[0].items = await model.populate(result[0].items, { ...populate, select: this.projection ? this.projection[populate.path] : undefined } as PopulateOptions)
298
+ result[0].items = await model.populate(result[0].items, { ...populate, select: BuildSelectPopulateFlowItem.build(model, this.projection, populate.path) } as PopulateOptions)
298
299
  }
299
300
  }
300
301
 
@@ -0,0 +1,22 @@
1
+ import mongoose from "mongoose";
2
+ import { isEmpty } from "../../utils/Utils";
3
+
4
+ class BuildSelectPopulateFlowItem {
5
+
6
+ build(model: mongoose.Model<any>, projection: any, path: string) {
7
+
8
+ const campoInfo = model.schema.path(path);
9
+
10
+ // Verifique se o tipo do campo é mongoose.Types.ObjectId
11
+ if (campoInfo.instance === "ObjectID") {
12
+ return undefined
13
+ }
14
+
15
+ if (isEmpty(projection[path]) || isNaN(projection[path]) === false) {
16
+ return undefined
17
+ }
18
+ return projection[path];
19
+ }
20
+ }
21
+
22
+ export default new BuildSelectPopulateFlowItem