Browse Source

Avoid exception in constraint for value which is not a string

pull/8177/head
Thomas Kaul 1 day ago
parent
commit
d42685025d
  1. 6
      libs/common/src/lib/validator-constraints/is-not-in-the-future.spec.ts
  2. 7
      libs/common/src/lib/validator-constraints/is-not-in-the-future.ts

6
libs/common/src/lib/validator-constraints/is-not-in-the-future.spec.ts

@ -26,4 +26,10 @@ describe('IsNotInTheFutureConstraint', () => {
it('Refuses a date in the future', () => {
expect(constraint.validate('2026-09-05')).toBe(false);
});
it('Leaves a value which is not a string to IsISO8601', () => {
expect(constraint.validate(undefined)).toBe(true);
expect(constraint.validate(null)).toBe(true);
expect(constraint.validate(123)).toBe(true);
});
});

7
libs/common/src/lib/validator-constraints/is-not-in-the-future.ts

@ -15,7 +15,12 @@ export class IsNotInTheFutureConstraint implements ValidatorConstraintInterface
return '$property must not be a date in the future';
}
public validate(aDate: string) {
public validate(aDate: unknown) {
// IsISO8601 refuses a value which is not a string
if (typeof aDate !== 'string') {
return true;
}
return !isAccountBalanceInFuture({ date: resetHours(parseISO(aDate)) });
}
}

Loading…
Cancel
Save