aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video-live-replay-setting.ts
blob: 1c824dfa2c5bec15e961a34c69e648c2c39466e1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { isVideoPrivacyValid } from '@server/helpers/custom-validators/videos'
import { MLiveReplaySetting } from '@server/types/models/video/video-live-replay-setting'
import { VideoPrivacy } from '@shared/models/videos/video-privacy.enum'
import { Transaction } from 'sequelize'
import { AllowNull, Column, CreatedAt, Is, Model, Table, UpdatedAt } from 'sequelize-typescript'
import { throwIfNotValid } from '../shared/sequelize-helpers'

@Table({
  tableName: 'videoLiveReplaySetting'
})
export class VideoLiveReplaySettingModel extends Model<VideoLiveReplaySettingModel> {

  @CreatedAt
  createdAt: Date

  @UpdatedAt
  updatedAt: Date

  @AllowNull(false)
  @Is('VideoPrivacy', value => throwIfNotValid(value, isVideoPrivacyValid, 'privacy'))
  @Column
  privacy: VideoPrivacy

  static load (id: number, transaction?: Transaction): Promise<MLiveReplaySetting> {
    return VideoLiveReplaySettingModel.findOne({
      where: { id },
      transaction
    })
  }

  static removeSettings (id: number) {
    return VideoLiveReplaySettingModel.destroy({
      where: { id }
    })
  }

  toFormattedJSON () {
    return {
      privacy: this.privacy
    }
  }
}