1 import { AllowNull, BelongsToMany, Column, CreatedAt, Model, Table, UpdatedAt } from 'sequelize-typescript'
2 import { Transaction } from 'sequelize/types'
3 import { MTracker } from '@server/types/models/server/tracker'
4 import { AttributesOnly } from '@shared/core-utils'
5 import { VideoModel } from '../video/video'
6 import { VideoTrackerModel } from './video-tracker'
17 export class TrackerModel extends Model<Partial<AttributesOnly<TrackerModel>>> {
29 @BelongsToMany(() => VideoModel, {
30 foreignKey: 'trackerId',
31 through: () => VideoTrackerModel,
36 static listUrlsByVideoId (videoId: number) {
41 model: VideoModel.unscoped(),
43 where: { id: videoId }
48 return TrackerModel.findAll(query)
49 .then(rows => rows.map(rows => rows.url))
52 static findOrCreateTrackers (trackers: string[], transaction: Transaction): Promise<MTracker[]> {
53 if (trackers === null) return Promise.resolve([])
55 const tasks: Promise<MTracker>[] = []
56 trackers.forEach(tracker => {
67 const promise = TrackerModel.findOrCreate<MTracker>(query)
68 .then(([ trackerInstance ]) => trackerInstance)
72 return Promise.all(tasks)