diff options
author | Chocobozzz <me@florianbigard.com> | 2019-02-11 11:52:34 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-02-11 11:52:34 +0100 |
commit | 88108880bbdba473cfe36ecbebc1c3c4f972e102 (patch) | |
tree | b242efb3b4f0d7e49d88f2d1f2063b5b3b0489c0 /server/models/account/user-video-history.ts | |
parent | 53a94c7cfa8368da4cd248d65df8346905938f0c (diff) | |
parent | 9b712a2017e4ab3cf12cd6bd58278905520159d0 (diff) | |
download | PeerTube-88108880bbdba473cfe36ecbebc1c3c4f972e102.tar.gz PeerTube-88108880bbdba473cfe36ecbebc1c3c4f972e102.tar.zst PeerTube-88108880bbdba473cfe36ecbebc1c3c4f972e102.zip |
Merge branch 'develop' into pr/1217
Diffstat (limited to 'server/models/account/user-video-history.ts')
-rw-r--r-- | server/models/account/user-video-history.ts | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/server/models/account/user-video-history.ts b/server/models/account/user-video-history.ts index 0476cad9d..15cb399c9 100644 --- a/server/models/account/user-video-history.ts +++ b/server/models/account/user-video-history.ts | |||
@@ -1,6 +1,7 @@ | |||
1 | import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, IsInt, Min, Model, Table, UpdatedAt } from 'sequelize-typescript' | 1 | import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, IsInt, Model, Table, UpdatedAt } from 'sequelize-typescript' |
2 | import { VideoModel } from '../video/video' | 2 | import { VideoModel } from '../video/video' |
3 | import { UserModel } from './user' | 3 | import { UserModel } from './user' |
4 | import { Transaction, Op, DestroyOptions } from 'sequelize' | ||
4 | 5 | ||
5 | @Table({ | 6 | @Table({ |
6 | tableName: 'userVideoHistory', | 7 | tableName: 'userVideoHistory', |
@@ -52,4 +53,34 @@ export class UserVideoHistoryModel extends Model<UserVideoHistoryModel> { | |||
52 | onDelete: 'CASCADE' | 53 | onDelete: 'CASCADE' |
53 | }) | 54 | }) |
54 | User: UserModel | 55 | User: UserModel |
56 | |||
57 | static listForApi (user: UserModel, start: number, count: number) { | ||
58 | return VideoModel.listForApi({ | ||
59 | start, | ||
60 | count, | ||
61 | sort: '-UserVideoHistories.updatedAt', | ||
62 | nsfw: null, // All | ||
63 | includeLocalVideos: true, | ||
64 | withFiles: false, | ||
65 | user, | ||
66 | historyOfUser: user | ||
67 | }) | ||
68 | } | ||
69 | |||
70 | static removeHistoryBefore (user: UserModel, beforeDate: string, t: Transaction) { | ||
71 | const query: DestroyOptions = { | ||
72 | where: { | ||
73 | userId: user.id | ||
74 | }, | ||
75 | transaction: t | ||
76 | } | ||
77 | |||
78 | if (beforeDate) { | ||
79 | query.where.updatedAt = { | ||
80 | [Op.lt]: beforeDate | ||
81 | } | ||
82 | } | ||
83 | |||
84 | return UserVideoHistoryModel.destroy(query) | ||
85 | } | ||
55 | } | 86 | } |