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.ts15
1 files changed, 15 insertions, 0 deletions
diff --git a/server/helpers/custom-validators/misc.ts b/server/helpers/custom-validators/misc.ts
index 528bfcfb8..c19a3e5eb 100644
--- a/server/helpers/custom-validators/misc.ts
+++ b/server/helpers/custom-validators/misc.ts
@@ -23,6 +23,10 @@ function isNotEmptyIntArray (value: any) {
23 return Array.isArray(value) && value.every(v => validator.isInt('' + v)) && value.length !== 0 23 return Array.isArray(value) && value.every(v => validator.isInt('' + v)) && value.length !== 0
24} 24}
25 25
26function isNotEmptyStringArray (value: any) {
27 return Array.isArray(value) && value.every(v => typeof v === 'string' && v.length !== 0) && value.length !== 0
28}
29
26function isArrayOf (value: any, validator: (value: any) => boolean) { 30function isArrayOf (value: any, validator: (value: any) => boolean) {
27 return isArray(value) && value.every(v => validator(v)) 31 return isArray(value) && value.every(v => validator(v))
28} 32}
@@ -39,6 +43,10 @@ function isUUIDValid (value: string) {
39 return exists(value) && validator.isUUID('' + value, 4) 43 return exists(value) && validator.isUUID('' + value, 4)
40} 44}
41 45
46function areUUIDsValid (values: string[]) {
47 return isArray(values) && values.every(v => isUUIDValid(v))
48}
49
42function isIdOrUUIDValid (value: string) { 50function isIdOrUUIDValid (value: string) {
43 return isIdValid(value) || isUUIDValid(value) 51 return isIdValid(value) || isUUIDValid(value)
44} 52}
@@ -132,6 +140,10 @@ function toCompleteUUID (value: string) {
132 return value 140 return value
133} 141}
134 142
143function toCompleteUUIDs (values: string[]) {
144 return values.map(v => toCompleteUUID(v))
145}
146
135function toIntOrNull (value: string) { 147function toIntOrNull (value: string) {
136 const v = toValueOrNull(value) 148 const v = toValueOrNull(value)
137 149
@@ -179,7 +191,9 @@ export {
179 isIntOrNull, 191 isIntOrNull,
180 isIdValid, 192 isIdValid,
181 isSafePath, 193 isSafePath,
194 isNotEmptyStringArray,
182 isUUIDValid, 195 isUUIDValid,
196 toCompleteUUIDs,
183 toCompleteUUID, 197 toCompleteUUID,
184 isIdOrUUIDValid, 198 isIdOrUUIDValid,
185 isDateValid, 199 isDateValid,
@@ -187,6 +201,7 @@ export {
187 toBooleanOrNull, 201 toBooleanOrNull,
188 isBooleanValid, 202 isBooleanValid,
189 toIntOrNull, 203 toIntOrNull,
204 areUUIDsValid,
190 toArray, 205 toArray,
191 toIntArray, 206 toIntArray,
192 isFileFieldValid, 207 isFileFieldValid,