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