diff options
Diffstat (limited to 'server/models/video/tag.ts')
-rw-r--r-- | server/models/video/tag.ts | 13 |
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 @@ | |||
1 | import * as Bluebird from 'bluebird' | 1 | import { col, fn, QueryTypes, Transaction } from 'sequelize' |
2 | import { fn, QueryTypes, Transaction, col } from 'sequelize' | ||
3 | import { AllowNull, BelongsToMany, Column, CreatedAt, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' | 2 | import { AllowNull, BelongsToMany, Column, CreatedAt, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' |
3 | import { MTag } from '@server/types/models' | ||
4 | import { VideoPrivacy, VideoState } from '../../../shared/models/videos' | ||
4 | import { isVideoTagValid } from '../../helpers/custom-validators/videos' | 5 | import { isVideoTagValid } from '../../helpers/custom-validators/videos' |
5 | import { throwIfNotValid } from '../utils' | 6 | import { throwIfNotValid } from '../utils' |
6 | import { VideoModel } from './video' | 7 | import { VideoModel } from './video' |
7 | import { VideoTagModel } from './video-tag' | 8 | import { VideoTagModel } from './video-tag' |
8 | import { VideoPrivacy, VideoState } from '../../../shared/models/videos' | ||
9 | import { 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 | }) |
25 | export class TagModel extends Model<TagModel> { | 24 | export 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" ' + |