Fix duplicated tags error
This commit is contained in:
parent
b6898035bf
commit
f2623febd8
1 changed files with 4 additions and 4 deletions
|
@ -45,8 +45,9 @@ export class TagModel extends Model<Partial<AttributesOnly<TagModel>>> {
|
||||||
static findOrCreateTags (tags: string[], transaction: Transaction): Promise<MTag[]> {
|
static findOrCreateTags (tags: string[], transaction: Transaction): Promise<MTag[]> {
|
||||||
if (tags === null) return Promise.resolve([])
|
if (tags === null) return Promise.resolve([])
|
||||||
|
|
||||||
const tasks: Promise<MTag>[] = []
|
const uniqueTags = new Set(tags)
|
||||||
tags.forEach(tag => {
|
|
||||||
|
const tasks = Array.from(uniqueTags).map(tag => {
|
||||||
const query = {
|
const query = {
|
||||||
where: {
|
where: {
|
||||||
name: tag
|
name: tag
|
||||||
|
@ -57,9 +58,8 @@ export class TagModel extends Model<Partial<AttributesOnly<TagModel>>> {
|
||||||
transaction
|
transaction
|
||||||
}
|
}
|
||||||
|
|
||||||
const promise = TagModel.findOrCreate<MTag>(query)
|
return TagModel.findOrCreate<MTag>(query)
|
||||||
.then(([ tagInstance ]) => tagInstance)
|
.then(([ tagInstance ]) => tagInstance)
|
||||||
tasks.push(promise)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return Promise.all(tasks)
|
return Promise.all(tasks)
|
||||||
|
|
Loading…
Reference in a new issue