X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Faccount%2Fuser-video-history.ts;h=45171fc6063c0e2ce65806385d870b6625d511f8;hb=b49f22d8f9a52ab75fd38db2d377249eb58fa678;hp=15cb399c952bc909305e331baf8cece53bccd45d;hpb=8b9a525a180cc9f3a98c334cc052dcfc8f36dcd4;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/account/user-video-history.ts b/server/models/account/user-video-history.ts index 15cb399c9..45171fc60 100644 --- a/server/models/account/user-video-history.ts +++ b/server/models/account/user-video-history.ts @@ -1,7 +1,8 @@ import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, IsInt, Model, Table, UpdatedAt } from 'sequelize-typescript' import { VideoModel } from '../video/video' import { UserModel } from './user' -import { Transaction, Op, DestroyOptions } from 'sequelize' +import { DestroyOptions, Op, Transaction } from 'sequelize' +import { MUserAccountId, MUserId } from '@server/types/models' @Table({ tableName: 'userVideoHistory', @@ -18,7 +19,7 @@ import { Transaction, Op, DestroyOptions } from 'sequelize' } ] }) -export class UserVideoHistoryModel extends Model { +export class UserVideoHistoryModel extends Model { @CreatedAt createdAt: Date @@ -54,11 +55,11 @@ export class UserVideoHistoryModel extends Model { }) User: UserModel - static listForApi (user: UserModel, start: number, count: number) { + static listForApi (user: MUserAccountId, start: number, count: number) { return VideoModel.listForApi({ start, count, - sort: '-UserVideoHistories.updatedAt', + sort: '-"userVideoHistory"."updatedAt"', nsfw: null, // All includeLocalVideos: true, withFiles: false, @@ -67,7 +68,7 @@ export class UserVideoHistoryModel extends Model { }) } - static removeHistoryBefore (user: UserModel, beforeDate: string, t: Transaction) { + static removeUserHistoryBefore (user: MUserId, beforeDate: string, t: Transaction) { const query: DestroyOptions = { where: { userId: user.id @@ -76,11 +77,23 @@ export class UserVideoHistoryModel extends Model { } if (beforeDate) { - query.where.updatedAt = { + query.where['updatedAt'] = { [Op.lt]: beforeDate } } return UserVideoHistoryModel.destroy(query) } + + static removeOldHistory (beforeDate: string) { + const query: DestroyOptions = { + where: { + updatedAt: { + [Op.lt]: beforeDate + } + } + } + + return UserVideoHistoryModel.destroy(query) + } }