aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/tag.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video/tag.ts')
-rw-r--r--server/models/video/tag.ts13
1 files changed, 6 insertions, 7 deletions
diff --git a/server/models/video/tag.ts b/server/models/video/tag.ts
index adbc4fb7d..d04205703 100644
--- a/server/models/video/tag.ts
+++ b/server/models/video/tag.ts
@@ -1,12 +1,11 @@
1import * as Bluebird from 'bluebird' 1import { col, fn, QueryTypes, Transaction } from 'sequelize'
2import { fn, QueryTypes, Transaction, col } from 'sequelize'
3import { AllowNull, BelongsToMany, Column, CreatedAt, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' 2import { AllowNull, BelongsToMany, Column, CreatedAt, Is, Model, Table, UpdatedAt } from 'sequelize-typescript'
3import { MTag } from '@server/types/models'
4import { VideoPrivacy, VideoState } from '../../../shared/models/videos'
4import { isVideoTagValid } from '../../helpers/custom-validators/videos' 5import { isVideoTagValid } from '../../helpers/custom-validators/videos'
5import { throwIfNotValid } from '../utils' 6import { throwIfNotValid } from '../utils'
6import { VideoModel } from './video' 7import { VideoModel } from './video'
7import { VideoTagModel } from './video-tag' 8import { VideoTagModel } from './video-tag'
8import { VideoPrivacy, VideoState } from '../../../shared/models/videos'
9import { MTag } from '@server/types/models'
10 9
11@Table({ 10@Table({
12 tableName: 'tag', 11 tableName: 'tag',
@@ -22,7 +21,7 @@ import { MTag } from '@server/types/models'
22 } 21 }
23 ] 22 ]
24}) 23})
25export class TagModel extends Model<TagModel> { 24export class TagModel extends Model {
26 25
27 @AllowNull(false) 26 @AllowNull(false)
28 @Is('VideoTag', value => throwIfNotValid(value, isVideoTagValid, 'tag')) 27 @Is('VideoTag', value => throwIfNotValid(value, isVideoTagValid, 'tag'))
@@ -45,7 +44,7 @@ export class TagModel extends Model<TagModel> {
45 static findOrCreateTags (tags: string[], transaction: Transaction): Promise<MTag[]> { 44 static findOrCreateTags (tags: string[], transaction: Transaction): Promise<MTag[]> {
46 if (tags === null) return Promise.resolve([]) 45 if (tags === null) return Promise.resolve([])
47 46
48 const tasks: Bluebird<MTag>[] = [] 47 const tasks: Promise<MTag>[] = []
49 tags.forEach(tag => { 48 tags.forEach(tag => {
50 const query = { 49 const query = {
51 where: { 50 where: {
@@ -66,7 +65,7 @@ export class TagModel extends Model<TagModel> {
66 } 65 }
67 66
68 // threshold corresponds to how many video the field should have to be returned 67 // threshold corresponds to how many video the field should have to be returned
69 static getRandomSamples (threshold: number, count: number): Bluebird<string[]> { 68 static getRandomSamples (threshold: number, count: number): Promise<string[]> {
70 const query = 'SELECT tag.name FROM tag ' + 69 const query = 'SELECT tag.name FROM tag ' +
71 'INNER JOIN "videoTag" ON "videoTag"."tagId" = tag.id ' + 70 'INNER JOIN "videoTag" ON "videoTag"."tagId" = tag.id ' +
72 'INNER JOIN video ON video.id = "videoTag"."videoId" ' + 71 'INNER JOIN video ON video.id = "videoTag"."videoId" ' +