event's API support update and image_url
This commit is contained in:
@@ -236,6 +236,8 @@ const eventController = {
|
||||
|
||||
if (req.file) {
|
||||
eventDetails.image_path = req.file.filename
|
||||
} else if (body.image_url) {
|
||||
eventDetails.image_path = await helpers.getImageFromURL(body.image_url)
|
||||
}
|
||||
|
||||
const event = await Event.create(eventDetails)
|
||||
@@ -289,6 +291,7 @@ const eventController = {
|
||||
}
|
||||
const body = req.body
|
||||
const event = await Event.findByPk(body.id)
|
||||
if (!event) return res.sendStatus(404)
|
||||
if (!req.user.is_admin && event.userId !== req.user.id) {
|
||||
return res.sendStatus(403)
|
||||
}
|
||||
@@ -316,6 +319,8 @@ const eventController = {
|
||||
}
|
||||
}
|
||||
eventDetails.image_path = req.file.filename
|
||||
} else if (body.image_url) {
|
||||
eventDetails.image_path = await helpers.getImageFromURL(body.image_url)
|
||||
}
|
||||
|
||||
await event.update(eventDetails)
|
||||
|
||||
@@ -86,8 +86,7 @@ api.put('/place', isAdmin, eventController.updatePlace)
|
||||
* @param {array} [recurrent.days] - array of days
|
||||
* @param {image} [image] - Image
|
||||
*/
|
||||
api.post('/event', upload.single('image'), eventController.add)
|
||||
|
||||
api.post('/event', hasPerm('event:write'), upload.single('image'), eventController.add)
|
||||
api.put('/event', hasPerm('event:write'), upload.single('image'), eventController.update)
|
||||
|
||||
// remove event
|
||||
|
||||
@@ -45,7 +45,7 @@ const DiskStorage = {
|
||||
.pipe(outStream)
|
||||
.on('error', err)
|
||||
|
||||
outStream.on('finish', function () {
|
||||
outStream.on('finish', () => {
|
||||
cb(null, {
|
||||
destination: config.upload_path,
|
||||
filename,
|
||||
|
||||
Reference in New Issue
Block a user