sea-backend-helpers 1.1.0 → 1.4.0

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.
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * as Utils from "./utils";
2
2
  export * as Decorators from "./decorators";
3
+ export * as Validators from "./validators";
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAGjC,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAGjC,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC;AAG3C,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC"}
package/dist/index.js CHANGED
@@ -33,8 +33,10 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.Decorators = exports.Utils = void 0;
36
+ exports.Validators = exports.Decorators = exports.Utils = void 0;
37
37
  // Utils
38
38
  exports.Utils = __importStar(require("./utils"));
39
39
  // Decorators
40
40
  exports.Decorators = __importStar(require("./decorators"));
41
+ // Validators
42
+ exports.Validators = __importStar(require("./validators"));
@@ -1,2 +1,3 @@
1
1
  export { IsArrayValuesInConstraint } from "./is-array-values-in";
2
+ export { IsDateRangeWithinLimit } from "./is-date-range-within-limit";
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC"}
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IsArrayValuesInConstraint = void 0;
3
+ exports.IsDateRangeWithinLimit = exports.IsArrayValuesInConstraint = void 0;
4
4
  var is_array_values_in_1 = require("./is-array-values-in");
5
5
  Object.defineProperty(exports, "IsArrayValuesInConstraint", { enumerable: true, get: function () { return is_array_values_in_1.IsArrayValuesInConstraint; } });
6
+ var is_date_range_within_limit_1 = require("./is-date-range-within-limit");
7
+ Object.defineProperty(exports, "IsDateRangeWithinLimit", { enumerable: true, get: function () { return is_date_range_within_limit_1.IsDateRangeWithinLimit; } });
@@ -0,0 +1,3 @@
1
+ import { ValidationOptions } from "class-validator";
2
+ export declare function IsDateRangeWithinLimit(startKey: string, endKey: string, maxDays: number, validationOptions?: ValidationOptions): (object: Object, propertyName: string) => void;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/validators/is-date-range-within-limit/index.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,iBAAiB,EAElB,MAAM,iBAAiB,CAAC;AAGzB,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,iBAAiB,CAAC,EAAE,iBAAiB,YAEZ,MAAM,gBAAgB,MAAM,UAiCtD"}
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.IsDateRangeWithinLimit = IsDateRangeWithinLimit;
7
+ // validators/date-range-limit.validator.ts
8
+ const class_validator_1 = require("class-validator");
9
+ const moment_1 = __importDefault(require("moment"));
10
+ function IsDateRangeWithinLimit(startKey, endKey, maxDays, validationOptions) {
11
+ return function (object, propertyName) {
12
+ (0, class_validator_1.registerDecorator)({
13
+ name: "IsDateRangeWithinLimit",
14
+ target: object.constructor,
15
+ propertyName,
16
+ constraints: [startKey, endKey, maxDays],
17
+ options: validationOptions,
18
+ validator: {
19
+ validate(_, args) {
20
+ const [startKey, endKey, maxDays] = args.constraints;
21
+ const obj = args.object;
22
+ const start = obj[startKey];
23
+ const end = obj[endKey];
24
+ if (!start || !end)
25
+ return true;
26
+ const startMoment = (0, moment_1.default)(start);
27
+ const endMoment = (0, moment_1.default)(end);
28
+ if (!startMoment.isValid() || !endMoment.isValid())
29
+ return false;
30
+ const diff = endMoment.diff(startMoment, "days");
31
+ return diff >= 0 && diff <= maxDays;
32
+ },
33
+ defaultMessage(args) {
34
+ const [startKey, endKey, maxDays] = args.constraints;
35
+ return `The date range between "${startKey}" and "${endKey}" must not exceed ${maxDays} days.`;
36
+ },
37
+ },
38
+ });
39
+ };
40
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "sea-backend-helpers",
3
3
  "description": "SEA Backend helpers library",
4
- "version": "1.1.0",
4
+ "version": "1.4.0",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
7
7
  "build": "tsc --build",
@@ -26,13 +26,15 @@
26
26
  "moment": "^2.30.1",
27
27
  "reflect-metadata": "^0.1.13",
28
28
  "rxjs": "^7.0.0",
29
- "sea-backend-helpers": "file:"
29
+ "sea-backend-helpers": "file:",
30
+ "sea-platform-helpers": "^1.2.0"
30
31
  },
31
32
  "peerDependencies": {
32
33
  "@nestjs/common": "^10.0.0",
33
34
  "@nestjs/jwt": "^10.0.0"
34
35
  },
35
36
  "devDependencies": {
36
- "@types/bcrypt": "^5.0.2"
37
+ "@types/bcrypt": "^5.0.2",
38
+ "@types/numeral": "^2.0.5"
37
39
  }
38
40
  }