diff options
Diffstat (limited to 'server/models/video/video-view.ts')
-rw-r--r-- | server/models/video/video-view.ts | 60 |
1 files changed, 0 insertions, 60 deletions
diff --git a/server/models/video/video-view.ts b/server/models/video/video-view.ts deleted file mode 100644 index d72df100f..000000000 --- a/server/models/video/video-view.ts +++ /dev/null | |||
@@ -1,60 +0,0 @@ | |||
1 | import { literal, Op } from 'sequelize' | ||
2 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Model, Table } from 'sequelize-typescript' | ||
3 | import { AttributesOnly } from '@shared/typescript-utils' | ||
4 | import { VideoModel } from './video' | ||
5 | |||
6 | @Table({ | ||
7 | tableName: 'videoView', | ||
8 | updatedAt: false, | ||
9 | indexes: [ | ||
10 | { | ||
11 | fields: [ 'videoId' ] | ||
12 | }, | ||
13 | { | ||
14 | fields: [ 'startDate' ] | ||
15 | } | ||
16 | ] | ||
17 | }) | ||
18 | export class VideoViewModel extends Model<Partial<AttributesOnly<VideoViewModel>>> { | ||
19 | @CreatedAt | ||
20 | createdAt: Date | ||
21 | |||
22 | @AllowNull(false) | ||
23 | @Column(DataType.DATE) | ||
24 | startDate: Date | ||
25 | |||
26 | @AllowNull(false) | ||
27 | @Column(DataType.DATE) | ||
28 | endDate: Date | ||
29 | |||
30 | @AllowNull(false) | ||
31 | @Column | ||
32 | views: number | ||
33 | |||
34 | @ForeignKey(() => VideoModel) | ||
35 | @Column | ||
36 | videoId: number | ||
37 | |||
38 | @BelongsTo(() => VideoModel, { | ||
39 | foreignKey: { | ||
40 | allowNull: false | ||
41 | }, | ||
42 | onDelete: 'CASCADE' | ||
43 | }) | ||
44 | Video: VideoModel | ||
45 | |||
46 | static removeOldRemoteViewsHistory (beforeDate: string) { | ||
47 | const query = { | ||
48 | where: { | ||
49 | startDate: { | ||
50 | [Op.lt]: beforeDate | ||
51 | }, | ||
52 | videoId: { | ||
53 | [Op.in]: literal('(SELECT "id" FROM "video" WHERE "remote" IS TRUE)') | ||
54 | } | ||
55 | } | ||
56 | } | ||
57 | |||
58 | return VideoViewModel.destroy(query) | ||
59 | } | ||
60 | } | ||