fix: improve validation on event's update

This commit is contained in:
lesion 2024-01-07 23:59:44 +01:00
parent 9482ba9e39
commit 90deb79d6b
No known key found for this signature in database
GPG key ID: 352918250B012177

View file

@ -438,14 +438,36 @@ const eventController = {
return res.sendStatus(403) return res.sendStatus(403)
} }
const start_datetime = body.start_datetime || event.start_datetime
const end_datetime = body.end_datetime || event.end_datetime || null
// // validate start_datetime and end_datetime
if (end_datetime) {
if (start_datetime > end_datetime) {
return res.status(400).send(`start datetime is greater than end datetime`)
}
if (Number(end_datetime) > 1000*24*60*60*365) {
return res.status(400).send('are you sure?')
}
}
if (!Number(start_datetime)) {
return res.status(400).send(`Wrong format for start datetime`)
}
if (Number(start_datetime) > 1000*24*60*60*365) {
return res.status(400).send('are you sure?')
}
const recurrent = body.recurrent ? JSON.parse(body.recurrent) : null const recurrent = body.recurrent ? JSON.parse(body.recurrent) : null
const eventDetails = { const eventDetails = {
title: body.title || event.title, title: body.title || event.title,
// sanitize and linkify html // sanitize and linkify html
description: helpers.sanitizeHTML(linkifyHtml(body.description || '', { target: '_blank' })) || event.description, description: helpers.sanitizeHTML(linkifyHtml(body.description || '', { target: '_blank' })) || event.description,
multidate: body.multidate, multidate: body.multidate,
start_datetime: body.start_datetime || event.start_datetime, start_datetime,
end_datetime: body.end_datetime || null, end_datetime,
online_locations: body.online_locations, online_locations: body.online_locations,
recurrent recurrent
} }