import { col, fn, QueryTypes, Transaction } from 'sequelize'
import { AllowNull, BelongsToMany, Column, CreatedAt, Is, Model, Table, UpdatedAt } from 'sequelize-typescript'
import { MTag } from '@server/types/models'
-import { AttributesOnly } from '@shared/core-utils'
+import { AttributesOnly } from '@shared/typescript-utils'
import { VideoPrivacy, VideoState } from '../../../shared/models/videos'
import { isVideoTagValid } from '../../helpers/custom-validators/videos'
import { throwIfNotValid } from '../utils'
},
{
name: 'tag_lower_name',
- fields: [ fn('lower', col('name')) ] as any // FIXME: typings
+ fields: [ fn('lower', col('name')) ]
}
]
})
static findOrCreateTags (tags: string[], transaction: Transaction): Promise<MTag[]> {
if (tags === null) return Promise.resolve([])
- const tasks: Promise<MTag>[] = []
- tags.forEach(tag => {
+ const uniqueTags = new Set(tags)
+
+ const tasks = Array.from(uniqueTags).map(tag => {
const query = {
where: {
name: tag
transaction
}
- const promise = TagModel.findOrCreate<MTag>(query)
+ return TagModel.findOrCreate<MTag>(query)
.then(([ tagInstance ]) => tagInstance)
- tasks.push(promise)
})
return Promise.all(tasks)