]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/models/view/local-video-viewer-watch-section.ts
Fix video job error when video has been deleted
[github/Chocobozzz/PeerTube.git] / server / models / view / local-video-viewer-watch-section.ts
CommitLineData
b2111066
C
1import { Transaction } from 'sequelize'
2import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Model, Table } from 'sequelize-typescript'
3import { MLocalVideoViewerWatchSection } from '@server/types/models'
4import { AttributesOnly } from '@shared/typescript-utils'
5import { LocalVideoViewerModel } from './local-video-viewer'
6
7@Table({
8 tableName: 'localVideoViewerWatchSection',
9 updatedAt: false,
10 indexes: [
11 {
12 fields: [ 'localVideoViewerId' ]
13 }
14 ]
15})
16export class LocalVideoViewerWatchSectionModel extends Model<Partial<AttributesOnly<LocalVideoViewerWatchSectionModel>>> {
17 @CreatedAt
18 createdAt: Date
19
20 @AllowNull(false)
21 @Column
22 watchStart: number
23
24 @AllowNull(false)
25 @Column
26 watchEnd: number
27
28 @ForeignKey(() => LocalVideoViewerModel)
29 @Column
30 localVideoViewerId: number
31
32 @BelongsTo(() => LocalVideoViewerModel, {
33 foreignKey: {
34 allowNull: false
35 },
36 onDelete: 'CASCADE'
37 })
38 LocalVideoViewer: LocalVideoViewerModel
39
40 static async bulkCreateSections (options: {
41 localVideoViewerId: number
42 watchSections: {
43 start: number
44 end: number
45 }[]
46 transaction?: Transaction
47 }) {
48 const { localVideoViewerId, watchSections, transaction } = options
49 const models: MLocalVideoViewerWatchSection[] = []
50
51 for (const section of watchSections) {
52 const model = await this.create({
53 watchStart: section.start,
54 watchEnd: section.end,
55 localVideoViewerId
56 }, { transaction })
57
58 models.push(model)
59 }
60
61 return models
62 }
63}