X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Ftag.ts;h=ed8df8b48aa84367003161035dda9256eac13c76;hb=35f28e94c763370616d25d5820f4b9ef70cedca9;hp=048b4761368d7451d2055a7531c86161dd797e2e;hpb=1735c825726edaa0af5035cb6cbb0cc0db502c6d;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/tag.ts b/server/models/video/tag.ts index 048b47613..ed8df8b48 100644 --- a/server/models/video/tag.ts +++ b/server/models/video/tag.ts @@ -1,11 +1,12 @@ import * as Bluebird from 'bluebird' -import { QueryTypes, Transaction } from 'sequelize' +import { fn, QueryTypes, Transaction, col } from 'sequelize' import { AllowNull, BelongsToMany, Column, CreatedAt, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' import { isVideoTagValid } from '../../helpers/custom-validators/videos' import { throwIfNotValid } from '../utils' import { VideoModel } from './video' import { VideoTagModel } from './video-tag' import { VideoPrivacy, VideoState } from '../../../shared/models/videos' +import { MTag } from '@server/typings/models' @Table({ tableName: 'tag', @@ -14,6 +15,10 @@ import { VideoPrivacy, VideoState } from '../../../shared/models/videos' { fields: [ 'name' ], unique: true + }, + { + name: 'tag_lower_name', + fields: [ fn('lower', col('name')) ] as any // FIXME: typings } ] }) @@ -37,10 +42,10 @@ export class TagModel extends Model { }) Videos: VideoModel[] - static findOrCreateTags (tags: string[], transaction: Transaction) { - if (tags === null) return [] + static findOrCreateTags (tags: string[], transaction: Transaction): Promise { + if (tags === null) return Promise.resolve([]) - const tasks: Bluebird[] = [] + const tasks: Bluebird[] = [] tags.forEach(tag => { const query = { where: { @@ -52,7 +57,7 @@ export class TagModel extends Model { transaction } - const promise = TagModel.findOrCreate(query) + const promise = TagModel.findOrCreate(query) .then(([ tagInstance ]) => tagInstance) tasks.push(promise) }) @@ -75,7 +80,7 @@ export class TagModel extends Model { type: QueryTypes.SELECT as QueryTypes.SELECT } - return TagModel.sequelize.query<{ name }>(query, options) + return TagModel.sequelize.query<{ name: string }>(query, options) .then(data => data.map(d => d.name)) } }