X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Ftag.ts;h=61dfb224d37c21d5223aa4495e9ec5504f03d8c2;hb=fa66c9a601d69f6d57c956a3513e8bbed7ee9616;hp=adbc4fb7d6c22b2d2015399cafbdef4589575ec4;hpb=26d6bf6533023326fa017812cf31bbe20c752d36;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/tag.ts b/server/models/video/tag.ts index adbc4fb7d..61dfb224d 100644 --- a/server/models/video/tag.ts +++ b/server/models/video/tag.ts @@ -1,12 +1,12 @@ -import * as Bluebird from 'bluebird' -import { fn, QueryTypes, Transaction, col } from 'sequelize' +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 { VideoPrivacy, VideoState } from '../../../shared/models/videos' 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/types/models' @Table({ tableName: 'tag', @@ -18,11 +18,11 @@ import { MTag } from '@server/types/models' }, { name: 'tag_lower_name', - fields: [ fn('lower', col('name')) ] as any // FIXME: typings + fields: [ fn('lower', col('name')) ] } ] }) -export class TagModel extends Model { +export class TagModel extends Model>> { @AllowNull(false) @Is('VideoTag', value => throwIfNotValid(value, isVideoTagValid, 'tag')) @@ -45,7 +45,7 @@ export class TagModel extends Model { static findOrCreateTags (tags: string[], transaction: Transaction): Promise { if (tags === null) return Promise.resolve([]) - const tasks: Bluebird[] = [] + const tasks: Promise[] = [] tags.forEach(tag => { const query = { where: { @@ -66,7 +66,7 @@ export class TagModel extends Model { } // threshold corresponds to how many video the field should have to be returned - static getRandomSamples (threshold: number, count: number): Bluebird { + static getRandomSamples (threshold: number, count: number): Promise { const query = 'SELECT tag.name FROM tag ' + 'INNER JOIN "videoTag" ON "videoTag"."tagId" = tag.id ' + 'INNER JOIN video ON video.id = "videoTag"."videoId" ' +