Added validation for location as well
This commit is contained in:
@@ -144,6 +144,7 @@ export default defineI18nConfig(() => ({
|
||||
toastTitle: "Event wasn't updated.",
|
||||
title_too_big: "Title should be less than 240 characters long.",
|
||||
description_too_big: "Description should be less than 1200 characters long.",
|
||||
location_too_big: "Location should be less than 240 characters long.",
|
||||
},
|
||||
deleteDialog: {
|
||||
title: "Delete this event",
|
||||
@@ -357,6 +358,7 @@ export default defineI18nConfig(() => ({
|
||||
toastTitle: "L'évènement n'a pas été modifié",
|
||||
title_too_big: "Le titre doit être inférieur à 240 caractères.",
|
||||
description_too_big: "La description doit être inférieure à 1200 caractères.",
|
||||
location_too_big: "La localisation doit être inférieure à 240 caractères.",
|
||||
},
|
||||
deleteDialog: {
|
||||
title: "Supprimer l'évènement",
|
||||
|
||||
@@ -22,7 +22,7 @@ export const postEventBodySchema = z.object({
|
||||
event: z.object({
|
||||
title: z.string().max(240),
|
||||
description: z.string().max(1200).optional().nullable(),
|
||||
location: z.string().optional().nullable(),
|
||||
location: z.string().max(240).optional().nullable(),
|
||||
startDate: dateSchema.required(),
|
||||
endDate: dateSchema.optional().nullable(),
|
||||
hidden: z.boolean().optional().nullable(),
|
||||
|
||||
@@ -27,7 +27,7 @@ export default defineEventHandler(async (event) => {
|
||||
fatal: false,
|
||||
statusCode: 401,
|
||||
statusMessage: "Validation Error",
|
||||
message: "Erreur de validation du schéma, cela est probablement dû à une erreur utilisateur.",
|
||||
message: "Erreur de validation du schéma, probablement dûe à une erreur utilisateur.",
|
||||
data: {
|
||||
errors: bodyError.issues.map(issue => ({
|
||||
path: issue.path,
|
||||
|
||||
@@ -7,14 +7,22 @@ export default defineEventHandler(async (event) => {
|
||||
const { data: bodyData, error: schemaError } = await readValidatedBody(event, body => postEventBodySchema.safeParse(body))
|
||||
|
||||
if (schemaError) {
|
||||
throw createError({
|
||||
const error = createError({
|
||||
cause: "Utilisateur",
|
||||
fatal: false,
|
||||
message: "Le schéma de la requête n'est pas complet ou mal renseigné.",
|
||||
data: schemaError.issues,
|
||||
statusMessage: "test",
|
||||
status: 401,
|
||||
statusCode: 401,
|
||||
statusMessage: "Validation Error",
|
||||
message: "Erreur de validation du schéma, probablement dûe à une erreur utilisateur.",
|
||||
data: {
|
||||
errors: schemaError.issues.map(issue => ({
|
||||
path: issue.path,
|
||||
message: issue.message,
|
||||
code: issue.code
|
||||
}))
|
||||
}
|
||||
})
|
||||
|
||||
throw error
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
@@ -93,7 +93,8 @@ alter table public.calendar_events
|
||||
add constraint calendar_events_maxlen_check
|
||||
check (
|
||||
char_length(title) <= 240 AND
|
||||
(description IS NULL OR char_length(description) <= 1200)
|
||||
(description IS NULL OR char_length(description) <= 1200) AND
|
||||
(location IS NULL OR char_length(location) <= 240)
|
||||
);
|
||||
|
||||
-- Link table for events - categories
|
||||
|
||||
Reference in New Issue
Block a user