]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/models/account/account-video-rate.ts
Add messages about privacy concerns (P2P)
[github/Chocobozzz/PeerTube.git] / server / models / account / account-video-rate.ts
CommitLineData
65fcc311 1import { values } from 'lodash'
3fd3ab2d
C
2import { Transaction } from 'sequelize'
3import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript'
4import { IFindOptions } from 'sequelize-typescript/lib/interfaces/IFindOptions'
5import { VideoRateType } from '../../../shared/models/videos'
74889a71 6import { VIDEO_RATE_TYPES } from '../../initializers'
3fd3ab2d
C
7import { VideoModel } from '../video/video'
8import { AccountModel } from './account'
d38b8281 9
3fd3ab2d
C
10/*
11 Account rates per video.
12*/
13@Table({
14 tableName: 'accountVideoRate',
15 indexes: [
d38b8281 16 {
3fd3ab2d
C
17 fields: [ 'videoId', 'accountId' ],
18 unique: true
d38b8281 19 }
3fd3ab2d
C
20 ]
21})
22export class AccountVideoRateModel extends Model<AccountVideoRateModel> {
d38b8281 23
3fd3ab2d
C
24 @AllowNull(false)
25 @Column(DataType.ENUM(values(VIDEO_RATE_TYPES)))
26 type: VideoRateType
e02643f3 27
3fd3ab2d
C
28 @CreatedAt
29 createdAt: Date
e02643f3 30
3fd3ab2d
C
31 @UpdatedAt
32 updatedAt: Date
d38b8281 33
3fd3ab2d
C
34 @ForeignKey(() => VideoModel)
35 @Column
36 videoId: number
d38b8281 37
3fd3ab2d 38 @BelongsTo(() => VideoModel, {
d38b8281 39 foreignKey: {
d38b8281
C
40 allowNull: false
41 },
42 onDelete: 'CASCADE'
43 })
3fd3ab2d 44 Video: VideoModel
d38b8281 45
3fd3ab2d
C
46 @ForeignKey(() => AccountModel)
47 @Column
48 accountId: number
49
50 @BelongsTo(() => AccountModel, {
d38b8281 51 foreignKey: {
d38b8281
C
52 allowNull: false
53 },
54 onDelete: 'CASCADE'
55 })
3fd3ab2d 56 Account: AccountModel
d38b8281 57
3fd3ab2d
C
58 static load (accountId: number, videoId: number, transaction: Transaction) {
59 const options: IFindOptions<AccountVideoRateModel> = {
60 where: {
61 accountId,
62 videoId
63 }
d38b8281 64 }
3fd3ab2d 65 if (transaction) options.transaction = transaction
d38b8281 66
3fd3ab2d
C
67 return AccountVideoRateModel.findOne(options)
68 }
d38b8281 69}