diff options
Diffstat (limited to 'server/models/user/user-video-rate.ts')
-rw-r--r-- | server/models/user/user-video-rate.ts | 78 |
1 files changed, 0 insertions, 78 deletions
diff --git a/server/models/user/user-video-rate.ts b/server/models/user/user-video-rate.ts deleted file mode 100644 index 7d6dd7281..000000000 --- a/server/models/user/user-video-rate.ts +++ /dev/null | |||
@@ -1,78 +0,0 @@ | |||
1 | /* | ||
2 | User 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 | UserVideoRateInstance, | ||
12 | UserVideoRateAttributes, | ||
13 | |||
14 | UserVideoRateMethods | ||
15 | } from './user-video-rate-interface' | ||
16 | |||
17 | let UserVideoRate: Sequelize.Model<UserVideoRateInstance, UserVideoRateAttributes> | ||
18 | let load: UserVideoRateMethods.Load | ||
19 | |||
20 | export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { | ||
21 | UserVideoRate = sequelize.define<UserVideoRateInstance, UserVideoRateAttributes>('UserVideoRate', | ||
22 | { | ||
23 | type: { | ||
24 | type: DataTypes.ENUM(values(VIDEO_RATE_TYPES)), | ||
25 | allowNull: false | ||
26 | } | ||
27 | }, | ||
28 | { | ||
29 | indexes: [ | ||
30 | { | ||
31 | fields: [ 'videoId', 'userId', 'type' ], | ||
32 | unique: true | ||
33 | } | ||
34 | ] | ||
35 | } | ||
36 | ) | ||
37 | |||
38 | const classMethods = [ | ||
39 | associate, | ||
40 | |||
41 | load | ||
42 | ] | ||
43 | addMethodsToModel(UserVideoRate, classMethods) | ||
44 | |||
45 | return UserVideoRate | ||
46 | } | ||
47 | |||
48 | // ------------------------------ STATICS ------------------------------ | ||
49 | |||
50 | function associate (models) { | ||
51 | UserVideoRate.belongsTo(models.Video, { | ||
52 | foreignKey: { | ||
53 | name: 'videoId', | ||
54 | allowNull: false | ||
55 | }, | ||
56 | onDelete: 'CASCADE' | ||
57 | }) | ||
58 | |||
59 | UserVideoRate.belongsTo(models.User, { | ||
60 | foreignKey: { | ||
61 | name: 'userId', | ||
62 | allowNull: false | ||
63 | }, | ||
64 | onDelete: 'CASCADE' | ||
65 | }) | ||
66 | } | ||
67 | |||
68 | load = function (userId: number, videoId: number, transaction: Sequelize.Transaction) { | ||
69 | const options: Sequelize.FindOptions<UserVideoRateAttributes> = { | ||
70 | where: { | ||
71 | userId, | ||
72 | videoId | ||
73 | } | ||
74 | } | ||
75 | if (transaction) options.transaction = transaction | ||
76 | |||
77 | return UserVideoRate.findOne(options) | ||
78 | } | ||