use the new _findOrCreate in updated event too

This commit is contained in:
lesion
2022-06-21 22:46:30 +02:00
parent b5b31f0327
commit 660b866f2f

View File

@@ -534,12 +534,14 @@ const eventController = {
}) })
await event.setPlace(place) await event.setPlace(place)
await event.setTags([])
// create/assign tags
let tags = []
if (body.tags) { if (body.tags) {
await Tag.bulkCreate(body.tags.map(t => ({ tag: t })), { ignoreDuplicates: true }) tags = await tagController._findOrCreate(body.tags)
const tags = await Tag.findAll({ where: { tag: { [Op.in]: body.tags } } }) await event.setTags(tags)
await event.addTags(tags)
} }
const newEvent = await Event.findByPk(event.id, { include: [Tag, Place] }) const newEvent = await Event.findByPk(event.id, { include: [Tag, Place] })
res.json(newEvent) res.json(newEvent)