mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 06:27:11 +01:00
fix double booked day validation
This commit is contained in:
@@ -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(',')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user