@mondart/nestjs-common-module 1.1.74 → 1.1.75

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.
@@ -0,0 +1,2 @@
1
+ import { ValidationOptions } from 'class-validator';
2
+ export declare function DependOnProperty(conditionValue: any, relatedProperty: string[], options?: ValidationOptions): (object: object, propertyName: string) => void;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DependOnProperty = DependOnProperty;
4
+ const class_validator_1 = require("class-validator");
5
+ function DependOnProperty(conditionValue, relatedProperty, options) {
6
+ return function (object, propertyName) {
7
+ (0, class_validator_1.registerDecorator)({
8
+ name: 'dependOnProperty',
9
+ target: object.constructor,
10
+ propertyName: propertyName,
11
+ options: options,
12
+ constraints: relatedProperty,
13
+ validator: {
14
+ validate(value, args) {
15
+ if (conditionValue === value) {
16
+ const relatedValues = args.constraints.map((relatedProperty) => args.object[relatedProperty]);
17
+ return (relatedValues.filter((relatedValue) => relatedValue)?.length ===
18
+ relatedProperty?.length);
19
+ }
20
+ return true;
21
+ },
22
+ defaultMessage(args) {
23
+ return `You must fill all of the following properties: ${args.constraints.join(', ')} depending on the ${args.property}: ${args.value}.`;
24
+ },
25
+ },
26
+ });
27
+ };
28
+ }
@@ -2,3 +2,4 @@ export * from './default';
2
2
  export * from './is-id.decorator';
3
3
  export * from './is-not-empty-string.decorator';
4
4
  export * from './is-one-of-property.decorator';
5
+ export * from './depend-on-property.decorator';
@@ -18,3 +18,4 @@ __exportStar(require("./default"), exports);
18
18
  __exportStar(require("./is-id.decorator"), exports);
19
19
  __exportStar(require("./is-not-empty-string.decorator"), exports);
20
20
  __exportStar(require("./is-one-of-property.decorator"), exports);
21
+ __exportStar(require("./depend-on-property.decorator"), exports);