fix add / modify event with duplicated tag

This commit is contained in:
lesion 2022-06-22 15:30:13 +02:00
parent 1c181cba65
commit 969e5184c0
No known key found for this signature in database
GPG key ID: 352918250B012177

View file

@ -1,5 +1,6 @@
const Tag = require('../models/tag')
const Event = require('../models/event')
const uniq = require('lodash/uniq')
const { where, fn, col, Op } = require('sequelize')
const exportController = require('./export')
@ -14,7 +15,7 @@ module.exports = {
// search for already existing tags (tag is the same as TaG)
const existingTags = await Tag.findAll({ where: { [Op.and]: where(fn('LOWER', col('tag')), { [Op.in]: lowercaseTags }) } })
const lowercaseExistingTags = existingTags.map(t => t.tag.toLocaleLowerCase())
const remainingTags = trimmedTags.filter(t => ! lowercaseExistingTags.includes(t.toLocaleLowerCase()))
const remainingTags = uniq(trimmedTags.filter(t => ! lowercaseExistingTags.includes(t.toLocaleLowerCase())))
// create remaining tags (cannot use updateOnDuplicate or manage conflicts)
return [].concat(