1 import { DestroyOptions, Op, Transaction } from 'sequelize'
2 import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, IsInt, Model, Table, UpdatedAt } from 'sequelize-typescript'
3 import { MUserAccountId, MUserId } from '@server/types/models'
4 import { AttributesOnly } from '@shared/core-utils'
5 import { VideoModel } from '../video/video'
6 import { UserModel } from './user'
9 tableName: 'userVideoHistory',
12 fields: [ 'userId', 'videoId' ],
23 export class UserVideoHistoryModel extends Model<Partial<AttributesOnly<UserVideoHistoryModel>>> {
35 @ForeignKey(() => VideoModel)
39 @BelongsTo(() => VideoModel, {
47 @ForeignKey(() => UserModel)
51 @BelongsTo(() => UserModel, {
59 static listForApi (user: MUserAccountId, start: number, count: number, search?: string) {
60 return VideoModel.listForApi({
64 sort: '-"userVideoHistory"."updatedAt"',
66 includeLocalVideos: true,
73 static removeUserHistoryBefore (user: MUserId, beforeDate: string, t: Transaction) {
74 const query: DestroyOptions = {
82 query.where['updatedAt'] = {
87 return UserVideoHistoryModel.destroy(query)
90 static removeOldHistory (beforeDate: string) {
91 const query: DestroyOptions = {
99 return UserVideoHistoryModel.destroy(query)