mirror of https://github.com/ghostfolio/ghostfolio
committed by
GitHub
11 changed files with 131 additions and 52 deletions
@ -0,0 +1,11 @@ |
|||
import { IsValidAccountBalanceDateConstraint } from './is-valid-account-balance-date'; |
|||
|
|||
describe('IsValidAccountBalanceDateConstraint', () => { |
|||
const constraint = new IsValidAccountBalanceDateConstraint(); |
|||
|
|||
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); |
|||
}); |
|||
}); |
|||
@ -0,0 +1,22 @@ |
|||
import { isValidAccountBalanceDate } from '@ghostfolio/common/helper'; |
|||
|
|||
import { |
|||
ValidatorConstraint, |
|||
ValidatorConstraintInterface |
|||
} from 'class-validator'; |
|||
|
|||
@ValidatorConstraint({ name: 'isValidAccountBalanceDate' }) |
|||
export class IsValidAccountBalanceDateConstraint implements ValidatorConstraintInterface { |
|||
public defaultMessage() { |
|||
return '$property must be a valid date which is not in the future'; |
|||
} |
|||
|
|||
public validate(aDate: unknown) { |
|||
// IsISO8601 refuses a value which is not a string
|
|||
if (typeof aDate !== 'string') { |
|||
return true; |
|||
} |
|||
|
|||
return isValidAccountBalanceDate(aDate); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue