event's API support update and image_url

This commit is contained in:
les
2020-05-14 22:36:58 +02:00
parent 34395c3d66
commit 22381d1fe6
7 changed files with 300 additions and 232 deletions

View File

@@ -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)

View File

@@ -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

View File

@@ -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,