aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators/misc.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/custom-validators/misc.ts')
-rw-r--r--server/helpers/custom-validators/misc.ts18
1 files changed, 16 insertions, 2 deletions
diff --git a/server/helpers/custom-validators/misc.ts b/server/helpers/custom-validators/misc.ts
index 3ef38fce1..1b7e00431 100644
--- a/server/helpers/custom-validators/misc.ts
+++ b/server/helpers/custom-validators/misc.ts
@@ -1,6 +1,7 @@
1import 'multer' 1import 'multer'
2import * as validator from 'validator' 2import * as validator from 'validator'
3import { sep } from 'path' 3import { sep } from 'path'
4import toBoolean = require('validator/lib/toBoolean')
4 5
5function exists (value: any) { 6function exists (value: any) {
6 return value !== undefined && value !== null 7 return value !== undefined && value !== null
@@ -46,9 +47,21 @@ function isBooleanValid (value: any) {
46} 47}
47 48
48function toIntOrNull (value: string) { 49function toIntOrNull (value: string) {
49 if (value === 'null') return null 50 const v = toValueOrNull(value)
51
52 if (v === null || v === undefined) return v
53 if (typeof v === 'number') return v
54
55 return validator.toInt(v)
56}
57
58function toBooleanOrNull (value: any) {
59 const v = toValueOrNull(value)
60
61 if (v === null || v === undefined) return v
62 if (typeof v === 'boolean') return v
50 63
51 return validator.toInt(value) 64 return toBoolean(v)
52} 65}
53 66
54function toValueOrNull (value: string) { 67function toValueOrNull (value: string) {
@@ -110,6 +123,7 @@ export {
110 isIdOrUUIDValid, 123 isIdOrUUIDValid,
111 isDateValid, 124 isDateValid,
112 toValueOrNull, 125 toValueOrNull,
126 toBooleanOrNull,
113 isBooleanValid, 127 isBooleanValid,
114 toIntOrNull, 128 toIntOrNull,
115 toArray, 129 toArray,