@mondart/nestjs-common-module 2.4.0 → 2.4.1

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,4 +1,4 @@
1
1
  import { ValidationOptions } from 'class-validator';
2
2
  type DateComparisonOperator = '<' | '<=' | '>' | '>=';
3
- export declare function IsDateRangeValid(relatedPropertyNameOrCurrent: string, operator: DateComparisonOperator, validationOptions?: ValidationOptions): (object: any, propertyName: string) => void;
3
+ export declare function IsDateRangeValid(relatedPropertyNameOrCurrent: string, operator: DateComparisonOperator, timezone?: string, validationOptions?: ValidationOptions): (object: any, propertyName: string) => void;
4
4
  export {};
@@ -8,32 +8,39 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.IsDateRangeValid = IsDateRangeValid;
10
10
  const class_validator_1 = require("class-validator");
11
+ const moment = require("moment-timezone");
11
12
  let IsDateRangeValidConstraint = class IsDateRangeValidConstraint {
12
13
  validate(from, args) {
13
- const [relatedPropertyNameOrCurrent, operator] = args.constraints;
14
+ const [relatedPropertyNameOrCurrent, operator, timezone] = args.constraints;
14
15
  let compareTo;
15
16
  if (relatedPropertyNameOrCurrent === 'current') {
16
- compareTo = new Date();
17
- compareTo.setHours(0, 0, 0, 0);
17
+ compareTo = moment
18
+ .tz(timezone || moment.tz.guess())
19
+ .startOf('day')
20
+ .toDate();
21
+ console.log('Compare To Date:', compareTo);
18
22
  }
19
23
  else {
20
24
  compareTo = args.object[relatedPropertyNameOrCurrent];
21
- compareTo =
22
- typeof compareTo === 'string' ? new Date(compareTo) : compareTo;
25
+ compareTo = moment(compareTo)
26
+ .tz(timezone || moment.tz.guess())
27
+ .startOf('day')
28
+ .toDate();
23
29
  }
24
30
  if (!from || !compareTo) {
25
31
  return true;
26
32
  }
27
- from = typeof from === 'string' ? new Date(from) : from;
33
+ const convertedFrom = moment(from).endOf('day').toDate();
34
+ console.log('From Date:', from);
28
35
  switch (operator) {
29
36
  case '<':
30
- return from.getTime() < compareTo.getTime();
37
+ return convertedFrom.getTime() < compareTo.getTime();
31
38
  case '<=':
32
- return from.getTime() <= compareTo.getTime();
39
+ return convertedFrom.getTime() <= compareTo.getTime();
33
40
  case '>':
34
- return from.getTime() > compareTo.getTime();
41
+ return convertedFrom.getTime() > compareTo.getTime();
35
42
  case '>=':
36
- return from.getTime() >= compareTo.getTime();
43
+ return convertedFrom.getTime() >= compareTo.getTime();
37
44
  default:
38
45
  return false;
39
46
  }
@@ -49,13 +56,13 @@ let IsDateRangeValidConstraint = class IsDateRangeValidConstraint {
49
56
  IsDateRangeValidConstraint = __decorate([
50
57
  (0, class_validator_1.ValidatorConstraint)({ async: false })
51
58
  ], IsDateRangeValidConstraint);
52
- function IsDateRangeValid(relatedPropertyNameOrCurrent, operator, validationOptions) {
59
+ function IsDateRangeValid(relatedPropertyNameOrCurrent, operator, timezone, validationOptions) {
53
60
  return (object, propertyName) => {
54
61
  (0, class_validator_1.registerDecorator)({
55
62
  target: object.constructor,
56
63
  propertyName: propertyName,
57
64
  options: validationOptions,
58
- constraints: [relatedPropertyNameOrCurrent, operator],
65
+ constraints: [relatedPropertyNameOrCurrent, operator, timezone],
59
66
  validator: IsDateRangeValidConstraint,
60
67
  });
61
68
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mondart/nestjs-common-module",
3
- "version": "2.4.0",
3
+ "version": "2.4.1",
4
4
  "description": "",
5
5
  "author": {
6
6
  "name": "Mondart"
@@ -46,6 +46,7 @@
46
46
  "express-basic-auth": "^1.2.1",
47
47
  "kafkajs": "^2.2.4",
48
48
  "nestjs-paginate": "^11.1.0",
49
+ "moment-timezone": "^0.6.0",
49
50
  "npm": "^10.8.1",
50
51
  "reflect-metadata": "^0.2.0",
51
52
  "rxjs": "^7.8.1",