c2-mongoose 2.1.157 → 2.1.159

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.
@@ -1,7 +1,7 @@
1
1
  import { IFacet } from "../../model/Facet";
2
2
  import SearchFlow from "../SearchFlow";
3
3
  declare class GetStagePaginationFlowItem {
4
- get(facet: IFacet, searcher: SearchFlow): IFacet;
4
+ get(facet: IFacet | undefined, searcher: SearchFlow): IFacet;
5
5
  }
6
6
  declare const _default: GetStagePaginationFlowItem;
7
7
  export default _default;
@@ -4,8 +4,9 @@ var GetStagePaginationFlowItem = /** @class */ (function () {
4
4
  function GetStagePaginationFlowItem() {
5
5
  }
6
6
  GetStagePaginationFlowItem.prototype.get = function (facet, searcher) {
7
+ if (facet === void 0) { facet = { items: [] }; }
7
8
  var facetAfter = facet;
8
- if (!searcher.pageable) {
9
+ if (searcher.pageable === false) {
9
10
  return facetAfter;
10
11
  }
11
12
  facetAfter.items.push({ $skip: ((searcher.page - 1) * searcher.limit) });
@@ -0,0 +1,7 @@
1
+ import { IFacet } from "../../model/Facet";
2
+ import SearchFlow from "../SearchFlow";
3
+ declare class GetStageSortFlowItem {
4
+ get(facet: IFacet | undefined, searcher: SearchFlow): IFacet;
5
+ }
6
+ declare const _default: GetStageSortFlowItem;
7
+ export default _default;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var GetStageSortFlowItem = /** @class */ (function () {
4
+ function GetStageSortFlowItem() {
5
+ }
6
+ GetStageSortFlowItem.prototype.get = function (facet, searcher) {
7
+ var _a;
8
+ if (facet === void 0) { facet = { items: [] }; }
9
+ var facetAfter = facet;
10
+ var sortByDirection = searcher.order === "desc" ? -1 : 1;
11
+ var sortByField = searcher.orderBy || "_id";
12
+ facetAfter.items.push({ $sort: (_a = {}, _a["".concat(sortByField)] = sortByDirection, _a) });
13
+ return facetAfter;
14
+ };
15
+ return GetStageSortFlowItem;
16
+ }());
17
+ exports.default = new GetStageSortFlowItem;
package/dist/index.d.ts CHANGED
@@ -4,9 +4,10 @@ import SearchFlow from "./flow/SearchFlow";
4
4
  import BuildPipelineToCountJoinFlowItem from "./flow/item/BuildPipelineToCountJoinFlowItem";
5
5
  import BuildPipelineToJoinFlowItem from "./flow/item/BuildPipelineToJoinFlowItem";
6
6
  import GetStagePaginationFlowItem from "./flow/item/GetStagePaginationFlowItem";
7
+ import GetStageSortFlowItem from "./flow/item/GetStageSortFlowItem";
7
8
  import { IFacet } from "./model/Facet";
8
9
  import { ILogger, LoggerModel, LoggerSearch, TypeOfOperation } from "./model/Logger";
9
10
  import { Options } from "./types/Options";
10
11
  import { Pagination, SearchResponse } from "./types/SearchResponse";
11
12
  import { initialize } from "./utils/Utils";
12
- export { C2Flow, CrudFlow, ILogger, LoggerModel, LoggerSearch, Options, Pagination, SearchFlow, SearchResponse, TypeOfOperation, initialize, BuildPipelineToCountJoinFlowItem, BuildPipelineToJoinFlowItem, IFacet, GetStagePaginationFlowItem };
13
+ export { C2Flow, CrudFlow, ILogger, LoggerModel, LoggerSearch, Options, Pagination, SearchFlow, SearchResponse, TypeOfOperation, initialize, BuildPipelineToCountJoinFlowItem, BuildPipelineToJoinFlowItem, IFacet, GetStagePaginationFlowItem, GetStageSortFlowItem };
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.GetStagePaginationFlowItem = exports.BuildPipelineToJoinFlowItem = exports.BuildPipelineToCountJoinFlowItem = exports.initialize = exports.TypeOfOperation = exports.SearchFlow = exports.LoggerSearch = exports.LoggerModel = exports.CrudFlow = exports.C2Flow = void 0;
6
+ exports.GetStageSortFlowItem = exports.GetStagePaginationFlowItem = exports.BuildPipelineToJoinFlowItem = exports.BuildPipelineToCountJoinFlowItem = exports.initialize = exports.TypeOfOperation = exports.SearchFlow = exports.LoggerSearch = exports.LoggerModel = exports.CrudFlow = exports.C2Flow = 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"));
@@ -16,6 +16,8 @@ var BuildPipelineToJoinFlowItem_1 = __importDefault(require("./flow/item/BuildPi
16
16
  exports.BuildPipelineToJoinFlowItem = BuildPipelineToJoinFlowItem_1.default;
17
17
  var GetStagePaginationFlowItem_1 = __importDefault(require("./flow/item/GetStagePaginationFlowItem"));
18
18
  exports.GetStagePaginationFlowItem = GetStagePaginationFlowItem_1.default;
19
+ var GetStageSortFlowItem_1 = __importDefault(require("./flow/item/GetStageSortFlowItem"));
20
+ exports.GetStageSortFlowItem = GetStageSortFlowItem_1.default;
19
21
  var Logger_1 = require("./model/Logger");
20
22
  Object.defineProperty(exports, "LoggerModel", { enumerable: true, get: function () { return Logger_1.LoggerModel; } });
21
23
  Object.defineProperty(exports, "LoggerSearch", { enumerable: true, get: function () { return Logger_1.LoggerSearch; } });
@@ -1,6 +1,7 @@
1
1
  interface IFacet {
2
2
  items: {
3
3
  [key: string]: any;
4
+ $sort?: {};
4
5
  $skip?: number;
5
6
  $limit?: number;
6
7
  }[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c2-mongoose",
3
- "version": "2.1.157",
3
+ "version": "2.1.159",
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",
@@ -3,10 +3,10 @@ import SearchFlow from "../SearchFlow"
3
3
 
4
4
  class GetStagePaginationFlowItem {
5
5
 
6
- get(facet: IFacet, searcher: SearchFlow): IFacet {
6
+ get(facet: IFacet = { items: [] }, searcher: SearchFlow): IFacet {
7
7
  let facetAfter: IFacet = facet
8
8
 
9
- if (!searcher.pageable) {
9
+ if (searcher.pageable === false) {
10
10
  return facetAfter
11
11
  }
12
12
 
@@ -0,0 +1,18 @@
1
+ import { IFacet } from "../../model/Facet"
2
+ import SearchFlow from "../SearchFlow"
3
+
4
+ class GetStageSortFlowItem {
5
+
6
+ get(facet: IFacet = { items: [] }, searcher: SearchFlow): IFacet {
7
+ let facetAfter: IFacet = facet
8
+
9
+ let sortByDirection = searcher.order === "desc" ? -1 : 1
10
+ let sortByField = searcher.orderBy || "_id"
11
+
12
+ facetAfter.items.push({ $sort: { [`${sortByField}`]: sortByDirection } })
13
+
14
+ return facetAfter
15
+ }
16
+ }
17
+
18
+ export default new GetStageSortFlowItem
package/src/index.ts CHANGED
@@ -4,6 +4,7 @@ import SearchFlow from "./flow/SearchFlow"
4
4
  import BuildPipelineToCountJoinFlowItem from "./flow/item/BuildPipelineToCountJoinFlowItem"
5
5
  import BuildPipelineToJoinFlowItem from "./flow/item/BuildPipelineToJoinFlowItem"
6
6
  import GetStagePaginationFlowItem from "./flow/item/GetStagePaginationFlowItem"
7
+ import GetStageSortFlowItem from "./flow/item/GetStageSortFlowItem"
7
8
  import { IFacet } from "./model/Facet"
8
9
  import { ILogger, LoggerModel, LoggerSearch, TypeOfOperation } from "./model/Logger"
9
10
  import { Options } from "./types/Options"
@@ -14,6 +15,6 @@ import { initialize } from "./utils/Utils"
14
15
 
15
16
  export {
16
17
  C2Flow, CrudFlow, ILogger, LoggerModel, LoggerSearch, Options, Pagination, SearchFlow, SearchResponse, TypeOfOperation, initialize,
17
- BuildPipelineToCountJoinFlowItem, BuildPipelineToJoinFlowItem, IFacet, GetStagePaginationFlowItem
18
+ BuildPipelineToCountJoinFlowItem, BuildPipelineToJoinFlowItem, IFacet, GetStagePaginationFlowItem, GetStageSortFlowItem
18
19
  }
19
20
 
@@ -1,6 +1,7 @@
1
1
  interface IFacet {
2
2
  items: {
3
3
  [key: string]: any,
4
+ $sort?: {},
4
5
  $skip?: number,
5
6
  $limit?: number,
6
7
  }[],