aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/schedule-video-update.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video/schedule-video-update.ts')
-rw-r--r--server/models/video/schedule-video-update.ts95
1 files changed, 0 insertions, 95 deletions
diff --git a/server/models/video/schedule-video-update.ts b/server/models/video/schedule-video-update.ts
deleted file mode 100644
index b3cf26966..000000000
--- a/server/models/video/schedule-video-update.ts
+++ /dev/null
@@ -1,95 +0,0 @@
1import { Op, Transaction } from 'sequelize'
2import { AllowNull, BelongsTo, Column, CreatedAt, Default, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript'
3import { MScheduleVideoUpdateFormattable, MScheduleVideoUpdate } from '@server/types/models'
4import { AttributesOnly } from '@shared/typescript-utils'
5import { VideoPrivacy } from '../../../shared/models/videos'
6import { VideoModel } from './video'
7
8@Table({
9 tableName: 'scheduleVideoUpdate',
10 indexes: [
11 {
12 fields: [ 'videoId' ],
13 unique: true
14 },
15 {
16 fields: [ 'updateAt' ]
17 }
18 ]
19})
20export class ScheduleVideoUpdateModel extends Model<Partial<AttributesOnly<ScheduleVideoUpdateModel>>> {
21
22 @AllowNull(false)
23 @Default(null)
24 @Column
25 updateAt: Date
26
27 @AllowNull(true)
28 @Default(null)
29 @Column
30 privacy: VideoPrivacy.PUBLIC | VideoPrivacy.UNLISTED | VideoPrivacy.INTERNAL
31
32 @CreatedAt
33 createdAt: Date
34
35 @UpdatedAt
36 updatedAt: Date
37
38 @ForeignKey(() => VideoModel)
39 @Column
40 videoId: number
41
42 @BelongsTo(() => VideoModel, {
43 foreignKey: {
44 allowNull: false
45 },
46 onDelete: 'cascade'
47 })
48 Video: VideoModel
49
50 static areVideosToUpdate () {
51 const query = {
52 logging: false,
53 attributes: [ 'id' ],
54 where: {
55 updateAt: {
56 [Op.lte]: new Date()
57 }
58 }
59 }
60
61 return ScheduleVideoUpdateModel.findOne(query)
62 .then(res => !!res)
63 }
64
65 static listVideosToUpdate (transaction?: Transaction) {
66 const query = {
67 where: {
68 updateAt: {
69 [Op.lte]: new Date()
70 }
71 },
72 transaction
73 }
74
75 return ScheduleVideoUpdateModel.findAll<MScheduleVideoUpdate>(query)
76 }
77
78 static deleteByVideoId (videoId: number, t: Transaction) {
79 const query = {
80 where: {
81 videoId
82 },
83 transaction: t
84 }
85
86 return ScheduleVideoUpdateModel.destroy(query)
87 }
88
89 toFormattedJSON (this: MScheduleVideoUpdateFormattable) {
90 return {
91 updateAt: this.updateAt,
92 privacy: this.privacy || undefined
93 }
94 }
95}