fix double booked day validation

This commit is contained in:
Thomas Ruoff
2020-12-23 23:38:53 +01:00
parent b723fc5660
commit 2a5c9b8638
4 changed files with 37 additions and 21 deletions

View File

@@ -1,5 +1,16 @@
import { VALIDATION_ERRORS } from '../../../db/enums'
interface ValidationErrors {
[key: string]: { properties: { message: string } }
[key: string]: { properties: { message: string }; kind: string }
}
function getDefinedValidationMessage(kind: string) {
switch (kind) {
case VALIDATION_ERRORS.AT_LEAST_ONE_DAY_BOOKED:
return 'Mindestens ein angefragter Tag ist nicht mehr verfügbar'
default:
return null
}
}
export class ValidationError extends Error {
@@ -16,9 +27,12 @@ export class ValidationError extends Error {
}
get message() {
return Object.entries<{ properties: { message: string } }>(this.errors)
return Object.entries<{ properties: { message: string }; kind: string }>(
this.errors
)
.map(([_key, value]) => {
return `${value?.properties?.message}`
const validationMessage = getDefinedValidationMessage(value.kind)
return validationMessage || `${value?.properties?.message}`
})
.join(',')
}