c2-mongoose 2.1.249 → 2.1.251

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,16 +7,16 @@ export interface IPopulate {
7
7
  populate: IPopulate;
8
8
  }
9
9
  declare class SearcherFlow<D> {
10
- private model;
10
+ model: mongoose.Model<any>;
11
11
  [key: string]: any;
12
- private searchText;
13
- private orderSense;
14
- private orderBy;
15
- private page;
16
- private limit;
17
- private pageable;
18
- private select;
19
- private populate;
12
+ searchText: string;
13
+ orderSense: string;
14
+ orderBy: string;
15
+ page: number;
16
+ limit: number;
17
+ pageable: boolean;
18
+ select: string[];
19
+ populate: string[];
20
20
  filters: any;
21
21
  constructor(repository: mongoose.Model<any>);
22
22
  prepareSearch(search: any): void;
@@ -92,6 +92,7 @@ var SearcherFlow = /** @class */ (function () {
92
92
  switch (_b.label) {
93
93
  case 0:
94
94
  stagesItems = [];
95
+ stagesPaging = [];
95
96
  if ((0, Utils_1.isNotEmpty)(options.pipelines)) {
96
97
  stagesItems.push.apply(stagesItems, options.pipelines);
97
98
  }
@@ -104,35 +105,34 @@ var SearcherFlow = /** @class */ (function () {
104
105
  stagesItems.push({ $project: BuildSelectSingleFlowItem_1.default.build(this.model, this.select) });
105
106
  }
106
107
  stagesItems.push({ $sort: this.buildOrdenation() });
108
+ if ((0, Utils_1.isNotEmpty)(options.pipelines)) {
109
+ stagesPaging.push.apply(stagesPaging, options.pipelines);
110
+ }
111
+ if ((0, Utils_1.isNotEmpty)(options.unions)) {
112
+ stagesPaging.push.apply(stagesPaging, options.unions);
113
+ }
114
+ stagesPaging.push({ $match: this.filters });
115
+ stagesPaging.push({ $count: "total" });
116
+ stagesPaging.push({
117
+ $addFields: {
118
+ page: this.pageable === true ? this.page : 1,
119
+ limit: this.pageable === true ? this.limit : '$total',
120
+ totalPages: this.pageable === true ? {
121
+ $cond: {
122
+ if: { $eq: ['$total', 0] },
123
+ then: 0,
124
+ else: { $ceil: { $divide: ['$total', this.limit] } }
125
+ }
126
+ } : 1,
127
+ startIndex: this.pageable === true ? { $subtract: [{ $multiply: [this.page, this.limit] }, this.limit - 1] } : 1,
128
+ endIndex: this.pageable === true ? { $multiply: [this.page, this.limit] } : '$total'
129
+ }
130
+ });
107
131
  }
108
132
  if (this.pageable === true) {
109
133
  stagesItems.push({ $skip: ((this.page - 1) * this.limit) || 0 });
110
134
  stagesItems.push({ $limit: this.limit });
111
135
  }
112
- stagesPaging = [];
113
- if ((0, Utils_1.isNotEmpty)(options.pipelines)) {
114
- stagesPaging.push.apply(stagesPaging, options.pipelines);
115
- }
116
- if ((0, Utils_1.isNotEmpty)(options.unions)) {
117
- stagesPaging.push.apply(stagesPaging, options.unions);
118
- }
119
- stagesPaging.push({ $match: this.filters });
120
- stagesPaging.push({ $count: "total" });
121
- stagesPaging.push({
122
- $addFields: {
123
- page: this.pageable === true ? this.page : 1,
124
- limit: this.pageable === true ? this.limit : '$total',
125
- totalPages: this.pageable === true ? {
126
- $cond: {
127
- if: { $eq: ['$total', 0] },
128
- then: 0,
129
- else: { $ceil: { $divide: ['$total', this.limit] } }
130
- }
131
- } : 1,
132
- startIndex: this.pageable === true ? { $subtract: [{ $multiply: [this.page, this.limit] }, this.limit - 1] } : 1,
133
- endIndex: this.pageable === true ? { $multiply: [this.page, this.limit] } : '$total'
134
- }
135
- });
136
136
  stagesMetadata = [];
137
137
  if ((0, Utils_1.isNotEmpty)(options.metadata)) {
138
138
  stagesMetadata.push.apply(stagesMetadata, options.metadata);
package/dist/index.d.ts CHANGED
@@ -6,10 +6,11 @@ import AddStagePaginationFlowItem from "./flow/item/AddStagePaginationFlowItem";
6
6
  import AddStageSortFlowItem from "./flow/item/AddStageSortFlowItem";
7
7
  import BuildPipelineToCountJoinFlowItem from "./flow/item/BuildPipelineToCountJoinFlowItem";
8
8
  import BuildPipelineToJoinFlowItem from "./flow/item/BuildPipelineToJoinFlowItem";
9
+ import BuildSelectSingleFlowItem from "./flow/item/BuildSelectSingleFlowItem";
9
10
  import ConvertToSearchResponseFlowItem from "./flow/item/ConvertToSearchResponseFlowItem";
10
11
  import { IFacet } from "./model/Facet";
11
12
  import { ILogger, LoggerModel, LoggerSearch, TypeOfOperation } from "./model/Logger";
12
13
  import { Options } from "./types/Options";
13
14
  import { Pagination, SearchResponse } from "./types/SearchResponse";
14
15
  import { initialize } from "./utils/Utils";
15
- export { SearcherFlow, AddStagePaginationFlowItem, AddStageSortFlowItem, BuildPipelineToCountJoinFlowItem, BuildPipelineToJoinFlowItem, C2Flow, ConvertToSearchResponseFlowItem, CrudFlow, IFacet, ILogger, LoggerModel, LoggerSearch, Options, Pagination, SearchFlow, SearchResponse, TypeOfOperation, initialize };
16
+ export { SearcherFlow, BuildSelectSingleFlowItem, AddStagePaginationFlowItem, AddStageSortFlowItem, BuildPipelineToCountJoinFlowItem, BuildPipelineToJoinFlowItem, C2Flow, ConvertToSearchResponseFlowItem, CrudFlow, IFacet, ILogger, LoggerModel, LoggerSearch, Options, Pagination, SearchFlow, SearchResponse, TypeOfOperation, initialize };
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.initialize = exports.TypeOfOperation = exports.SearchFlow = exports.LoggerSearch = exports.LoggerModel = exports.CrudFlow = exports.ConvertToSearchResponseFlowItem = exports.C2Flow = exports.BuildPipelineToJoinFlowItem = exports.BuildPipelineToCountJoinFlowItem = exports.AddStageSortFlowItem = exports.AddStagePaginationFlowItem = exports.SearcherFlow = void 0;
6
+ exports.initialize = exports.TypeOfOperation = exports.SearchFlow = exports.LoggerSearch = exports.LoggerModel = exports.CrudFlow = exports.ConvertToSearchResponseFlowItem = exports.C2Flow = exports.BuildPipelineToJoinFlowItem = exports.BuildPipelineToCountJoinFlowItem = exports.AddStageSortFlowItem = exports.AddStagePaginationFlowItem = exports.BuildSelectSingleFlowItem = exports.SearcherFlow = void 0;
7
7
  var C2Flow_1 = __importDefault(require("./flow/C2Flow"));
8
8
  exports.C2Flow = C2Flow_1.default;
9
9
  var CrudFlow_1 = __importDefault(require("./flow/CrudFlow"));
@@ -20,6 +20,8 @@ var BuildPipelineToCountJoinFlowItem_1 = __importDefault(require("./flow/item/Bu
20
20
  exports.BuildPipelineToCountJoinFlowItem = BuildPipelineToCountJoinFlowItem_1.default;
21
21
  var BuildPipelineToJoinFlowItem_1 = __importDefault(require("./flow/item/BuildPipelineToJoinFlowItem"));
22
22
  exports.BuildPipelineToJoinFlowItem = BuildPipelineToJoinFlowItem_1.default;
23
+ var BuildSelectSingleFlowItem_1 = __importDefault(require("./flow/item/BuildSelectSingleFlowItem"));
24
+ exports.BuildSelectSingleFlowItem = BuildSelectSingleFlowItem_1.default;
23
25
  var ConvertToSearchResponseFlowItem_1 = __importDefault(require("./flow/item/ConvertToSearchResponseFlowItem"));
24
26
  exports.ConvertToSearchResponseFlowItem = ConvertToSearchResponseFlowItem_1.default;
25
27
  var Logger_1 = require("./model/Logger");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.249",
3
+ "version": "2.1.251",
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",
@@ -13,18 +13,18 @@ export interface IPopulate {
13
13
 
14
14
  class SearcherFlow<D> {
15
15
 
16
- private model: mongoose.Model<any>
16
+ public model: mongoose.Model<any>
17
17
 
18
18
  [key: string]: any
19
- private searchText: string = ""
20
- private orderSense: string = "desc"
21
- private orderBy: string = "_id"
22
- private page: number = 1
23
- private limit: number = 50
24
- private pageable: boolean = true
25
-
26
- private select: string[] = []
27
- private populate: string[] = []
19
+ public searchText: string = ""
20
+ public orderSense: string = "desc"
21
+ public orderBy: string = "_id"
22
+ public page: number = 1
23
+ public limit: number = 50
24
+ public pageable: boolean = true
25
+
26
+ public select: string[] = []
27
+ public populate: string[] = []
28
28
  public filters: any = undefined
29
29
 
30
30
  constructor(repository: mongoose.Model<any>) {
@@ -44,7 +44,7 @@ class SearcherFlow<D> {
44
44
  async search(options: SearchOptions): Promise<SearchResponse<D>> {
45
45
 
46
46
  let stagesItems: any[] = []
47
-
47
+ let stagesPaging: any[] = []
48
48
  if (isNotEmpty(options.pipelines)) {
49
49
  stagesItems.push(...options.pipelines)
50
50
  }
@@ -52,13 +52,38 @@ class SearcherFlow<D> {
52
52
  stagesItems.push(...options.unions)
53
53
  }
54
54
 
55
- if (isEmpty(options.pipelines)){
55
+ if (isEmpty(options.pipelines)) {
56
56
  stagesItems.push({ $match: this.filters })
57
-
57
+
58
58
  if (isNotEmpty(this.select)) {
59
59
  stagesItems.push({ $project: BuildSelectSingleFlowItem.build(this.model, this.select) })
60
60
  }
61
61
  stagesItems.push({ $sort: this.buildOrdenation() })
62
+
63
+ if (isNotEmpty(options.pipelines)) {
64
+ stagesPaging.push(...options.pipelines)
65
+ }
66
+ if (isNotEmpty(options.unions)) {
67
+ stagesPaging.push(...options.unions)
68
+ }
69
+
70
+ stagesPaging.push({ $match: this.filters })
71
+ stagesPaging.push({ $count: "total" })
72
+ stagesPaging.push({
73
+ $addFields: {
74
+ page: this.pageable === true ? this.page : 1,
75
+ limit: this.pageable === true ? this.limit : '$total',
76
+ totalPages: this.pageable === true ? {
77
+ $cond: {
78
+ if: { $eq: ['$total', 0] },
79
+ then: 0,
80
+ else: { $ceil: { $divide: ['$total', this.limit] } }
81
+ }
82
+ } : 1,
83
+ startIndex: this.pageable === true ? { $subtract: [{ $multiply: [this.page, this.limit] }, this.limit - 1] } : 1,
84
+ endIndex: this.pageable === true ? { $multiply: [this.page, this.limit] } : '$total'
85
+ }
86
+ })
62
87
  }
63
88
 
64
89
  if (this.pageable === true) {
@@ -66,33 +91,6 @@ class SearcherFlow<D> {
66
91
  stagesItems.push({ $limit: this.limit })
67
92
  }
68
93
 
69
-
70
- let stagesPaging: any[] = []
71
- if (isNotEmpty(options.pipelines)) {
72
- stagesPaging.push(...options.pipelines)
73
- }
74
- if (isNotEmpty(options.unions)) {
75
- stagesPaging.push(...options.unions)
76
- }
77
-
78
- stagesPaging.push({ $match: this.filters })
79
- stagesPaging.push({ $count: "total" })
80
- stagesPaging.push({
81
- $addFields: {
82
- page: this.pageable === true ? this.page : 1,
83
- limit: this.pageable === true ? this.limit : '$total',
84
- totalPages: this.pageable === true ? {
85
- $cond: {
86
- if: { $eq: ['$total', 0] },
87
- then: 0,
88
- else: { $ceil: { $divide: ['$total', this.limit] } }
89
- }
90
- } : 1,
91
- startIndex: this.pageable === true ? { $subtract: [{ $multiply: [this.page, this.limit] }, this.limit - 1] } : 1,
92
- endIndex: this.pageable === true ? { $multiply: [this.page, this.limit] } : '$total'
93
- }
94
- })
95
-
96
94
  let stagesMetadata: any[] = []
97
95
  if (isNotEmpty(options.metadata)) {
98
96
  stagesMetadata.push(...options.metadata)
@@ -154,7 +152,7 @@ class SearcherFlow<D> {
154
152
  };
155
153
  }
156
154
 
157
- extractFieldsOfType(schema: Schema, typing = 'String', parent = ''): string[]{
155
+ extractFieldsOfType(schema: Schema, typing = 'String', parent = ''): string[] {
158
156
  let fieldsTyped: string[] = []
159
157
  Object.keys(schema.paths).forEach((field: string) => {
160
158
  if (schema.paths[field].instance === typing) {
package/src/index.ts CHANGED
@@ -6,6 +6,7 @@ import AddStagePaginationFlowItem from "./flow/item/AddStagePaginationFlowItem"
6
6
  import AddStageSortFlowItem from "./flow/item/AddStageSortFlowItem"
7
7
  import BuildPipelineToCountJoinFlowItem from "./flow/item/BuildPipelineToCountJoinFlowItem"
8
8
  import BuildPipelineToJoinFlowItem from "./flow/item/BuildPipelineToJoinFlowItem"
9
+ import BuildSelectSingleFlowItem from "./flow/item/BuildSelectSingleFlowItem"
9
10
  import ConvertToSearchResponseFlowItem from "./flow/item/ConvertToSearchResponseFlowItem"
10
11
  import { IFacet } from "./model/Facet"
11
12
  import { ILogger, LoggerModel, LoggerSearch, TypeOfOperation } from "./model/Logger"
@@ -15,5 +16,5 @@ import { initialize } from "./utils/Utils"
15
16
 
16
17
  (global as any).LoggerRepository = undefined
17
18
 
18
- export { SearcherFlow, AddStagePaginationFlowItem, AddStageSortFlowItem, BuildPipelineToCountJoinFlowItem, BuildPipelineToJoinFlowItem, C2Flow, ConvertToSearchResponseFlowItem, CrudFlow, IFacet, ILogger, LoggerModel, LoggerSearch, Options, Pagination, SearchFlow, SearchResponse, TypeOfOperation, initialize }
19
+ export { SearcherFlow, BuildSelectSingleFlowItem, AddStagePaginationFlowItem, AddStageSortFlowItem, BuildPipelineToCountJoinFlowItem, BuildPipelineToJoinFlowItem, C2Flow, ConvertToSearchResponseFlowItem, CrudFlow, IFacet, ILogger, LoggerModel, LoggerSearch, Options, Pagination, SearchFlow, SearchResponse, TypeOfOperation, initialize }
19
20