error handling while adding events
This commit is contained in:
@@ -37,11 +37,16 @@ const userController = {
|
||||
* add event
|
||||
*/
|
||||
async addEvent (req, res) {
|
||||
// req.err comes from multer streaming error
|
||||
if (req.err) {
|
||||
debug(req.err)
|
||||
return res.status(400).json(req.err.toString())
|
||||
}
|
||||
|
||||
try {
|
||||
const body = req.body
|
||||
const recurrent = body.recurrent ? JSON.parse(body.recurrent) : null
|
||||
|
||||
const eventDetails = {
|
||||
title: body.title,
|
||||
// remove html tags
|
||||
@@ -49,7 +54,7 @@ const userController = {
|
||||
multidate: body.multidate,
|
||||
start_datetime: body.start_datetime,
|
||||
end_datetime: body.end_datetime,
|
||||
recurrent: body.recurrent,
|
||||
recurrent,
|
||||
// publish this event only if authenticated
|
||||
is_visible: !!req.user
|
||||
}
|
||||
@@ -61,18 +66,13 @@ const userController = {
|
||||
const event = await Event.create(eventDetails)
|
||||
|
||||
// create place if needed
|
||||
let place
|
||||
try {
|
||||
place = await Place.findOrCreate({
|
||||
const place = await Place.findOrCreate({
|
||||
where: { name: body.place_name },
|
||||
defaults: { address: body.place_address }
|
||||
})
|
||||
.spread((place, created) => place)
|
||||
await event.setPlace(place)
|
||||
event.place = place
|
||||
} catch (e) {
|
||||
debug(e)
|
||||
}
|
||||
|
||||
// create/assign tags
|
||||
if (body.tags) {
|
||||
@@ -98,6 +98,10 @@ const userController = {
|
||||
const notifier = require('../../notifier')
|
||||
notifier.notifyEvent('Create', event.id)
|
||||
}
|
||||
} catch (e) {
|
||||
res.sendStatus(400)
|
||||
debug(e.toString())
|
||||
}
|
||||
},
|
||||
|
||||
async updateEvent (req, res) {
|
||||
|
||||
Reference in New Issue
Block a user