diff options
Diffstat (limited to 'server/models/video')
-rw-r--r-- | server/models/video/video-views.ts | 41 | ||||
-rw-r--r-- | server/models/video/video.ts | 9 |
2 files changed, 50 insertions, 0 deletions
diff --git a/server/models/video/video-views.ts b/server/models/video/video-views.ts new file mode 100644 index 000000000..90ce671fd --- /dev/null +++ b/server/models/video/video-views.ts | |||
@@ -0,0 +1,41 @@ | |||
1 | import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Model, Table } from 'sequelize-typescript' | ||
2 | import { VideoModel } from './video' | ||
3 | import * as Sequelize from 'sequelize' | ||
4 | |||
5 | @Table({ | ||
6 | tableName: 'videoView', | ||
7 | indexes: [ | ||
8 | { | ||
9 | fields: [ 'videoId' ] | ||
10 | } | ||
11 | ] | ||
12 | }) | ||
13 | export class VideoViewModel extends Model<VideoViewModel> { | ||
14 | @CreatedAt | ||
15 | createdAt: Date | ||
16 | |||
17 | @AllowNull(false) | ||
18 | @Column(Sequelize.DATE) | ||
19 | startDate: Date | ||
20 | |||
21 | @AllowNull(false) | ||
22 | @Column(Sequelize.DATE) | ||
23 | endDate: Date | ||
24 | |||
25 | @AllowNull(false) | ||
26 | @Column | ||
27 | views: number | ||
28 | |||
29 | @ForeignKey(() => VideoModel) | ||
30 | @Column | ||
31 | videoId: number | ||
32 | |||
33 | @BelongsTo(() => VideoModel, { | ||
34 | foreignKey: { | ||
35 | allowNull: false | ||
36 | }, | ||
37 | onDelete: 'CASCADE' | ||
38 | }) | ||
39 | Video: VideoModel | ||
40 | |||
41 | } | ||
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 6271db1b3..3410833c8 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -1074,6 +1074,15 @@ export class VideoModel extends Model<VideoModel> { | |||
1074 | } | 1074 | } |
1075 | } | 1075 | } |
1076 | 1076 | ||
1077 | static incrementViews (id: number, views: number) { | ||
1078 | return VideoModel.increment('views', { | ||
1079 | by: views, | ||
1080 | where: { | ||
1081 | id | ||
1082 | } | ||
1083 | }) | ||
1084 | } | ||
1085 | |||
1077 | private static buildActorWhereWithFilter (filter?: VideoFilter) { | 1086 | private static buildActorWhereWithFilter (filter?: VideoFilter) { |
1078 | if (filter && filter === 'local') { | 1087 | if (filter && filter === 'local') { |
1079 | return { | 1088 | return { |