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