diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-11-09 17:51:58 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 19:40:51 +0100 |
commit | e4f97babf701481b55cc10fb3448feab5f97c867 (patch) | |
tree | af37402a594dc5ff09f71ecb0687e8cfe4cdb471 /server/models/account/account-video-rate.ts | |
parent | 343ad675f2a26c15b86150a9a3552e619d5d44f4 (diff) | |
download | PeerTube-e4f97babf701481b55cc10fb3448feab5f97c867.tar.gz PeerTube-e4f97babf701481b55cc10fb3448feab5f97c867.tar.zst PeerTube-e4f97babf701481b55cc10fb3448feab5f97c867.zip |
Begin activitypub
Diffstat (limited to 'server/models/account/account-video-rate.ts')
-rw-r--r-- | server/models/account/account-video-rate.ts | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/server/models/account/account-video-rate.ts b/server/models/account/account-video-rate.ts new file mode 100644 index 000000000..7f7c97606 --- /dev/null +++ b/server/models/account/account-video-rate.ts | |||
@@ -0,0 +1,78 @@ | |||
1 | /* | ||
2 | Account rates per video. | ||
3 | */ | ||
4 | import { values } from 'lodash' | ||
5 | import * as Sequelize from 'sequelize' | ||
6 | |||
7 | import { VIDEO_RATE_TYPES } from '../../initializers' | ||
8 | |||
9 | import { addMethodsToModel } from '../utils' | ||
10 | import { | ||
11 | AccountVideoRateInstance, | ||
12 | AccountVideoRateAttributes, | ||
13 | |||
14 | AccountVideoRateMethods | ||
15 | } from './account-video-rate-interface' | ||
16 | |||
17 | let AccountVideoRate: Sequelize.Model<AccountVideoRateInstance, AccountVideoRateAttributes> | ||
18 | let load: AccountVideoRateMethods.Load | ||
19 | |||
20 | export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { | ||
21 | AccountVideoRate = sequelize.define<AccountVideoRateInstance, AccountVideoRateAttributes>('AccountVideoRate', | ||
22 | { | ||
23 | type: { | ||
24 | type: DataTypes.ENUM(values(VIDEO_RATE_TYPES)), | ||
25 | allowNull: false | ||
26 | } | ||
27 | }, | ||
28 | { | ||
29 | indexes: [ | ||
30 | { | ||
31 | fields: [ 'videoId', 'accountId', 'type' ], | ||
32 | unique: true | ||
33 | } | ||
34 | ] | ||
35 | } | ||
36 | ) | ||
37 | |||
38 | const classMethods = [ | ||
39 | associate, | ||
40 | |||
41 | load | ||
42 | ] | ||
43 | addMethodsToModel(AccountVideoRate, classMethods) | ||
44 | |||
45 | return AccountVideoRate | ||
46 | } | ||
47 | |||
48 | // ------------------------------ STATICS ------------------------------ | ||
49 | |||
50 | function associate (models) { | ||
51 | AccountVideoRate.belongsTo(models.Video, { | ||
52 | foreignKey: { | ||
53 | name: 'videoId', | ||
54 | allowNull: false | ||
55 | }, | ||
56 | onDelete: 'CASCADE' | ||
57 | }) | ||
58 | |||
59 | AccountVideoRate.belongsTo(models.Account, { | ||
60 | foreignKey: { | ||
61 | name: 'accountId', | ||
62 | allowNull: false | ||
63 | }, | ||
64 | onDelete: 'CASCADE' | ||
65 | }) | ||
66 | } | ||
67 | |||
68 | load = function (accountId: number, videoId: number, transaction: Sequelize.Transaction) { | ||
69 | const options: Sequelize.FindOptions<AccountVideoRateAttributes> = { | ||
70 | where: { | ||
71 | accountId, | ||
72 | videoId | ||
73 | } | ||
74 | } | ||
75 | if (transaction) options.transaction = transaction | ||
76 | |||
77 | return AccountVideoRate.findOne(options) | ||
78 | } | ||