c2-mongoose 2.1.401 → 2.1.403

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.
@@ -3,6 +3,8 @@ import { IForeingData } from "./item/OneToManyFlowItem";
3
3
  export interface IParams {
4
4
  [key: string]: any;
5
5
  mainFilter: any;
6
+ preSteps?: any[];
7
+ posSteps?: any[];
6
8
  }
7
9
  declare class SearcherV3Flow {
8
10
  exec(params: IParams, model: mongoose.Model<any>, oneToMany?: IForeingData[]): Promise<any>;
@@ -49,34 +49,40 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
49
49
  };
50
50
  Object.defineProperty(exports, "__esModule", { value: true });
51
51
  var MatchFlowItem_1 = __importDefault(require("../v3/item/MatchFlowItem"));
52
+ var BuildPaginationDataFlowItem_1 = __importDefault(require("./item/BuildPaginationDataFlowItem"));
52
53
  var GroupFlowItem_1 = __importDefault(require("./item/GroupFlowItem"));
54
+ var OneToManyFlowItem_1 = __importDefault(require("./item/OneToManyFlowItem"));
53
55
  var PopulateFlowItem_1 = __importDefault(require("./item/PopulateFlowItem"));
54
- var SortFlowItem_1 = __importDefault(require("./item/SortFlowItem"));
55
56
  var ProjectFlowItem_1 = __importDefault(require("./item/ProjectFlowItem"));
56
- var BuildPaginationDataFlowItem_1 = __importDefault(require("./item/BuildPaginationDataFlowItem"));
57
- var OneToManyFlowItem_1 = __importDefault(require("./item/OneToManyFlowItem"));
57
+ var SortFlowItem_1 = __importDefault(require("./item/SortFlowItem"));
58
58
  var SearcherV3Flow = /** @class */ (function () {
59
59
  function SearcherV3Flow() {
60
60
  }
61
61
  SearcherV3Flow.prototype.exec = function (params, model, oneToMany) {
62
- var _a, _b, _c;
62
+ var _a, _b, _c, _d, _e;
63
63
  if (oneToMany === void 0) { oneToMany = []; }
64
64
  return __awaiter(this, void 0, void 0, function () {
65
65
  var facet, pipelineFacetPaging, pipelineFacetItems, mainFilters, result, ret;
66
- return __generator(this, function (_d) {
67
- switch (_d.label) {
66
+ return __generator(this, function (_f) {
67
+ switch (_f.label) {
68
68
  case 0:
69
69
  params.page = Number((_a = params.page) !== null && _a !== void 0 ? _a : 1);
70
70
  params.limit = Number((_b = params.limit) !== null && _b !== void 0 ? _b : 50);
71
71
  facet = {};
72
72
  pipelineFacetPaging = [];
73
73
  pipelineFacetItems = [];
74
+ if ((_c = params.preSteps) === null || _c === void 0 ? void 0 : _c.length) {
75
+ pipelineFacetItems = __spreadArray(__spreadArray([], pipelineFacetItems, true), params.preSteps, true);
76
+ }
74
77
  pipelineFacetItems = __spreadArray(__spreadArray([], pipelineFacetItems, true), GroupFlowItem_1.default.execute(params.groupBy, params.sumFields, params.groupDetailed, model), true);
75
78
  pipelineFacetItems = __spreadArray(__spreadArray([], pipelineFacetItems, true), PopulateFlowItem_1.default.execute(params.populate, model), true);
76
79
  pipelineFacetItems = __spreadArray(__spreadArray([], pipelineFacetItems, true), OneToManyFlowItem_1.default.execute(oneToMany, params.populate), true);
77
80
  pipelineFacetItems = __spreadArray(__spreadArray([], pipelineFacetItems, true), MatchFlowItem_1.default.execute(params, model), true);
78
81
  pipelineFacetItems = __spreadArray(__spreadArray([], pipelineFacetItems, true), SortFlowItem_1.default.execute(params.orderBy, params.orderSense), true);
79
82
  pipelineFacetItems = __spreadArray(__spreadArray([], pipelineFacetItems, true), ProjectFlowItem_1.default.execute(params.select), true);
83
+ if ((_d = params.posSteps) === null || _d === void 0 ? void 0 : _d.length) {
84
+ pipelineFacetItems = __spreadArray(__spreadArray([], pipelineFacetItems, true), params.posSteps, true);
85
+ }
80
86
  if (params.pageable !== false) {
81
87
  pipelineFacetItems = __spreadArray(__spreadArray([], pipelineFacetItems, true), [
82
88
  { $skip: (params.page - 1) * (params.limit) },
@@ -98,11 +104,11 @@ var SearcherV3Flow = /** @class */ (function () {
98
104
  }
99
105
  }).read('secondaryPreferred')];
100
106
  case 1:
101
- result = _d.sent();
107
+ result = _f.sent();
102
108
  ret = {};
103
109
  ret.items = result[0].items;
104
110
  if (params.pageable !== false) {
105
- ret.paging = (_c = result[0].paging[0]) !== null && _c !== void 0 ? _c : {
111
+ ret.paging = (_e = result[0].paging[0]) !== null && _e !== void 0 ? _e : {
106
112
  page: 1,
107
113
  limit: 50,
108
114
  total: 0,
@@ -50,7 +50,9 @@ var BuildAndQueriesFlowItem = /** @class */ (function () {
50
50
  'searchTextFields',
51
51
  'sort',
52
52
  'isPageable',
53
- 'searchPageable'
53
+ 'searchPageable',
54
+ 'preSteps',
55
+ 'posSteps',
54
56
  ].includes(key)) {
55
57
  return;
56
58
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.401",
3
+ "version": "2.1.403",
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,15 +1,17 @@
1
1
  import mongoose from "mongoose"
2
2
  import MatchFlowItem from "../v3/item/MatchFlowItem"
3
+ import BuildPaginationDataFlowItem from "./item/BuildPaginationDataFlowItem"
3
4
  import GroupFlowItem from "./item/GroupFlowItem"
5
+ import OneToManyFlowItem, { IForeingData } from "./item/OneToManyFlowItem"
4
6
  import PopulateFlowItem from "./item/PopulateFlowItem"
5
- import SortFlowItem from "./item/SortFlowItem"
6
7
  import ProjectFlowItem from "./item/ProjectFlowItem"
7
- import BuildPaginationDataFlowItem from "./item/BuildPaginationDataFlowItem"
8
- import OneToManyFlowItem, { IForeingData } from "./item/OneToManyFlowItem"
8
+ import SortFlowItem from "./item/SortFlowItem"
9
9
 
10
10
  export interface IParams {
11
11
  [key: string]: any
12
12
  mainFilter: any
13
+ preSteps?: any[]
14
+ posSteps?: any[]
13
15
  }
14
16
 
15
17
  class SearcherV3Flow {
@@ -23,6 +25,10 @@ class SearcherV3Flow {
23
25
  const facet: any = {}
24
26
  let pipelineFacetPaging: any[] = []
25
27
  let pipelineFacetItems: any[] = []
28
+
29
+ if (params.preSteps?.length) {
30
+ pipelineFacetItems = [...pipelineFacetItems, ...params.preSteps]
31
+ }
26
32
  pipelineFacetItems = [...pipelineFacetItems, ...GroupFlowItem.execute(params.groupBy, params.sumFields, params.groupDetailed, model)]
27
33
  pipelineFacetItems = [...pipelineFacetItems, ...PopulateFlowItem.execute(params.populate, model)]
28
34
  pipelineFacetItems = [...pipelineFacetItems, ...OneToManyFlowItem.execute(oneToMany, params.populate)]
@@ -30,6 +36,10 @@ class SearcherV3Flow {
30
36
  pipelineFacetItems = [...pipelineFacetItems, ...SortFlowItem.execute(params.orderBy, params.orderSense)]
31
37
  pipelineFacetItems = [...pipelineFacetItems, ...ProjectFlowItem.execute(params.select)]
32
38
 
39
+ if (params.posSteps?.length) {
40
+ pipelineFacetItems = [...pipelineFacetItems, ...params.posSteps]
41
+ }
42
+
33
43
  if (params.pageable !== false) {
34
44
  pipelineFacetItems = [
35
45
  ...pipelineFacetItems,
@@ -48,7 +58,7 @@ class SearcherV3Flow {
48
58
  facet.items = pipelineFacetItems
49
59
 
50
60
  const mainFilters = params.mainFilter ? [...MatchFlowItem.execute(params.mainFilter, model)] : []
51
-
61
+
52
62
  let result = await model.aggregate([
53
63
  ...mainFilters,
54
64
  {
@@ -32,7 +32,10 @@ class BuildAndQueriesFlowItem {
32
32
  'searchTextFields',
33
33
  'sort',
34
34
  'isPageable',
35
- 'searchPageable'].includes(key)) {
35
+ 'searchPageable',
36
+ 'preSteps',
37
+ 'posSteps',
38
+ ].includes(key)) {
36
39
  return
37
40
  }
38
41