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