diff options
Diffstat (limited to 'server/helpers/custom-validators')
-rw-r--r-- | server/helpers/custom-validators/misc.ts | 7 | ||||
-rw-r--r-- | server/helpers/custom-validators/search.ts | 19 |
2 files changed, 26 insertions, 0 deletions
diff --git a/server/helpers/custom-validators/misc.ts b/server/helpers/custom-validators/misc.ts index 455aae367..151fc852b 100644 --- a/server/helpers/custom-validators/misc.ts +++ b/server/helpers/custom-validators/misc.ts | |||
@@ -41,6 +41,12 @@ function toValueOrNull (value: string) { | |||
41 | return value | 41 | return value |
42 | } | 42 | } |
43 | 43 | ||
44 | function toArray (value: string) { | ||
45 | if (value && isArray(value) === false) return [ value ] | ||
46 | |||
47 | return value | ||
48 | } | ||
49 | |||
44 | function isFileValid ( | 50 | function isFileValid ( |
45 | files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[], | 51 | files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[], |
46 | mimeTypeRegex: string, | 52 | mimeTypeRegex: string, |
@@ -80,5 +86,6 @@ export { | |||
80 | toValueOrNull, | 86 | toValueOrNull, |
81 | isBooleanValid, | 87 | isBooleanValid, |
82 | toIntOrNull, | 88 | toIntOrNull, |
89 | toArray, | ||
83 | isFileValid | 90 | isFileValid |
84 | } | 91 | } |
diff --git a/server/helpers/custom-validators/search.ts b/server/helpers/custom-validators/search.ts new file mode 100644 index 000000000..2fde39160 --- /dev/null +++ b/server/helpers/custom-validators/search.ts | |||
@@ -0,0 +1,19 @@ | |||
1 | import * as validator from 'validator' | ||
2 | import 'express-validator' | ||
3 | |||
4 | import { isArray } from './misc' | ||
5 | |||
6 | function isNumberArray (value: any) { | ||
7 | return isArray(value) && value.every(v => validator.isInt('' + v)) | ||
8 | } | ||
9 | |||
10 | function isStringArray (value: any) { | ||
11 | return isArray(value) && value.every(v => typeof v === 'string') | ||
12 | } | ||
13 | |||
14 | // --------------------------------------------------------------------------- | ||
15 | |||
16 | export { | ||
17 | isNumberArray, | ||
18 | isStringArray | ||
19 | } | ||