-
Notifications
You must be signed in to change notification settings - Fork 2
/
common-validator.js
71 lines (57 loc) · 1.75 KB
/
common-validator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const config = require('../../../config')
/**
* This file defines all generic validation tests used in the application. This file can and should be used by the
* three higher level validators: FieldValidator, FieldSetValidator, and UrlPathValidator.
*/
const validator = require('validator')
const SQL_MAX_INT = 2147483647
const SQL_DEC_8_COMMA_2 = 999999.99
const moment = require('moment')
const dateFormatter = require('../date-formatter')
exports.isNullOrUndefined = function (value) {
return !value
}
exports.isNumeric = function (value) {
return validator.isNumeric(value) || validator.isDecimal(value)
}
exports.isCurrency = function (value) {
return validator.isCurrency(value)
}
exports.isGreaterThanZero = function (value) {
return value > 0
}
exports.isGreaterThanOrEqualToZero = function (value) {
return value >= 0
}
exports.isGreaterThanMinimumClaim = function (value) {
return value >= 0 && value !== null
}
exports.isLessThanMaximumDifferentApprovedAmount = function (value) {
return value <= parseInt(config.MAX_APPROVED_DIFFERENT_AMOUNT) && value !== null
}
exports.isEmail = function (value) {
return validator.isEmail(value)
}
exports.isLessThanLength = function (value, length) {
return validator.isLength(value, { max: length })
}
exports.isInteger = function (value) {
return validator.isInt(value)
}
exports.isMaxIntOrLess = function (value) {
return value <= SQL_MAX_INT
}
exports.isMaxCostOrLess = function (value) {
return value <= SQL_DEC_8_COMMA_2
}
exports.isValidDate = function (date) {
if (this.isNullOrUndefined(date)) {
return false
}
return date instanceof moment &&
date.isValid()
}
exports.isDateInTheFuture = function (date) {
return this.isValidDate(date) &&
date > dateFormatter.now()
}