mirror of
https://framagit.org/les/gancio.git
synced 2025-01-31 16:42:22 +01:00
add place_id on add/edit event, fix media update
This commit is contained in:
parent
82ae4b1be9
commit
5bce9cf289
3 changed files with 33 additions and 17 deletions
|
@ -75,6 +75,7 @@ export default {
|
|||
if (typeof p === 'object' && !p.create) {
|
||||
this.place.name = p.name.trim()
|
||||
this.place.address = p.address
|
||||
this.place.id = p.id
|
||||
this.disableAddress = true
|
||||
} else { // this is a new place
|
||||
this.place.name = p.name || p
|
||||
|
@ -83,9 +84,11 @@ export default {
|
|||
const place = this.places.find(p => p.name.toLowerCase() === tmpPlace)
|
||||
if (place) {
|
||||
this.place.name = place.name
|
||||
this.place.id = place.id
|
||||
this.place.address = place.address
|
||||
this.disableAddress = true
|
||||
} else {
|
||||
delete this.place.id
|
||||
this.place.address = ''
|
||||
this.disableAddress = false
|
||||
this.$refs.place.blur()
|
||||
|
|
|
@ -187,12 +187,15 @@ export default {
|
|||
|
||||
if (this.event.media.length) {
|
||||
formData.append('image', this.event.media[0].image)
|
||||
formData.append('image_url', this.event.media[0].url)
|
||||
// formData.append('image_url', this.event.media[0].url)
|
||||
formData.append('image_name', this.event.media[0].name)
|
||||
formData.append('image_focalpoint', this.event.media[0].focalpoint)
|
||||
}
|
||||
|
||||
formData.append('title', this.event.title)
|
||||
if (this.event.place.id) {
|
||||
formData.append('place_id', this.event.place.id)
|
||||
}
|
||||
formData.append('place_name', this.event.place.name)
|
||||
formData.append('place_address', this.event.place.address)
|
||||
formData.append('description', this.event.description)
|
||||
|
|
|
@ -290,7 +290,7 @@ const eventController = {
|
|||
},
|
||||
|
||||
async isAnonEventAllowed (_req, res, next) {
|
||||
if (!res.locals.settings.allow_anon_event) {
|
||||
if (!res.locals.settings.allow_anon_event && !res.locals.user) {
|
||||
return res.sendStatus(403)
|
||||
}
|
||||
next()
|
||||
|
@ -307,11 +307,28 @@ const eventController = {
|
|||
const body = req.body
|
||||
const recurrent = body.recurrent ? JSON.parse(body.recurrent) : null
|
||||
|
||||
const required_fields = [ 'title', 'place_name', 'start_datetime']
|
||||
const missing_field = required_fields.find(required_field => !body[required_field])
|
||||
const required_fields = [ 'title', 'start_datetime']
|
||||
let missing_field = required_fields.find(required_field => !body[required_field])
|
||||
if (missing_field) {
|
||||
log.warn(`${missing_field} is required`)
|
||||
return res.status(400).send(`${missing_field} is required`)
|
||||
log.warn(`${missing_field} required`)
|
||||
return res.status(400).send(`${missing_field} required`)
|
||||
}
|
||||
|
||||
// find or create the place
|
||||
let place
|
||||
if (body.place_id) {
|
||||
place = await Place.findByPk(body.place_id)
|
||||
} else {
|
||||
place = await Place.findOne({ where: { name: body.place_name.trim() }})
|
||||
if (!place) {
|
||||
if (!body.place_address || !body.place_name) {
|
||||
return res.status(400).send(`place_id or place_name and place_address required`)
|
||||
}
|
||||
place = await Place.create({
|
||||
name: body.place_name,
|
||||
address: body.place_address
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const eventDetails = {
|
||||
|
@ -347,13 +364,6 @@ const eventController = {
|
|||
|
||||
let event = await Event.create(eventDetails)
|
||||
|
||||
const [place] = await Place.findOrCreate({
|
||||
where: { name: body.place_name },
|
||||
defaults: {
|
||||
address: body.place_address
|
||||
}
|
||||
})
|
||||
|
||||
await event.setPlace(place)
|
||||
|
||||
// create/assign tags
|
||||
|
@ -427,8 +437,9 @@ const eventController = {
|
|||
}
|
||||
}
|
||||
|
||||
if (req.file || body.image_url) {
|
||||
if (body.image_url && /^https?:\/\//.test(body.image_url)) {
|
||||
// modify associated media only if a new file is uploaded or remote image_url is used
|
||||
if (req.file || (body.image_url && /^https?:\/\//.test(body.image_url))) {
|
||||
if (body.image_url) {
|
||||
req.file = await helpers.getImageFromURL(body.image_url)
|
||||
}
|
||||
|
||||
|
@ -441,10 +452,9 @@ const eventController = {
|
|||
name: body.image_name || body.title || '',
|
||||
focalpoint: [parseFloat(focalpoint[0].slice(0, 6)), parseFloat(focalpoint[1].slice(0, 6))]
|
||||
}]
|
||||
} else {
|
||||
} else if (!body.image) {
|
||||
eventDetails.media = []
|
||||
}
|
||||
|
||||
await event.update(eventDetails)
|
||||
const [place] = await Place.findOrCreate({
|
||||
where: { name: body.place_name },
|
||||
|
|
Loading…
Reference in a new issue