2024-04-03 14:25:21 +02:00
|
|
|
import { MLocalVideoViewerWatchSection } from '@server/types/models/index.js'
|
2022-03-24 13:36:47 +01:00
|
|
|
import { Transaction } from 'sequelize'
|
2024-02-22 10:12:04 +01:00
|
|
|
import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Table } from 'sequelize-typescript'
|
|
|
|
import { SequelizeModel } from '../shared/index.js'
|
2024-04-03 14:25:21 +02:00
|
|
|
import { LocalVideoViewerModel } from './local-video-viewer.js'
|
2022-03-24 13:36:47 +01:00
|
|
|
|
|
|
|
@Table({
|
|
|
|
tableName: 'localVideoViewerWatchSection',
|
|
|
|
updatedAt: false,
|
|
|
|
indexes: [
|
|
|
|
{
|
|
|
|
fields: [ 'localVideoViewerId' ]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
2024-02-22 10:12:04 +01:00
|
|
|
export class LocalVideoViewerWatchSectionModel extends SequelizeModel<LocalVideoViewerWatchSectionModel> {
|
2022-03-24 13:36:47 +01:00
|
|
|
@CreatedAt
|
|
|
|
createdAt: Date
|
|
|
|
|
|
|
|
@AllowNull(false)
|
|
|
|
@Column
|
|
|
|
watchStart: number
|
|
|
|
|
|
|
|
@AllowNull(false)
|
|
|
|
@Column
|
|
|
|
watchEnd: number
|
|
|
|
|
|
|
|
@ForeignKey(() => LocalVideoViewerModel)
|
|
|
|
@Column
|
|
|
|
localVideoViewerId: number
|
|
|
|
|
|
|
|
@BelongsTo(() => LocalVideoViewerModel, {
|
|
|
|
foreignKey: {
|
|
|
|
allowNull: false
|
|
|
|
},
|
|
|
|
onDelete: 'CASCADE'
|
|
|
|
})
|
2023-07-31 14:34:36 +02:00
|
|
|
LocalVideoViewer: Awaited<LocalVideoViewerModel>
|
2022-03-24 13:36:47 +01:00
|
|
|
|
|
|
|
static async bulkCreateSections (options: {
|
|
|
|
localVideoViewerId: number
|
|
|
|
watchSections: {
|
|
|
|
start: number
|
|
|
|
end: number
|
|
|
|
}[]
|
|
|
|
transaction?: Transaction
|
|
|
|
}) {
|
|
|
|
const { localVideoViewerId, watchSections, transaction } = options
|
|
|
|
const models: MLocalVideoViewerWatchSection[] = []
|
|
|
|
|
|
|
|
for (const section of watchSections) {
|
2024-04-03 14:25:21 +02:00
|
|
|
const watchStart = section.start || 0
|
|
|
|
const watchEnd = section.end || 0
|
|
|
|
|
|
|
|
if (watchStart === watchEnd) continue
|
|
|
|
|
2022-03-24 13:36:47 +01:00
|
|
|
const model = await this.create({
|
2024-04-03 14:25:21 +02:00
|
|
|
watchStart,
|
|
|
|
watchEnd,
|
2022-03-24 13:36:47 +01:00
|
|
|
localVideoViewerId
|
|
|
|
}, { transaction })
|
|
|
|
|
|
|
|
models.push(model)
|
|
|
|
}
|
|
|
|
|
|
|
|
return models
|
|
|
|
}
|
|
|
|
}
|