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/typescript-utils'
5 import { VideoModel } from '../video/video'
6 import { UserModel } from './user'
7 import { getServerActor } from '../application/application'
10 tableName: 'userVideoHistory',
13 fields: [ 'userId', 'videoId' ],
24 export class UserVideoHistoryModel extends Model<Partial<AttributesOnly<UserVideoHistoryModel>>> {
36 @ForeignKey(() => VideoModel)
40 @BelongsTo(() => VideoModel, {
48 @ForeignKey(() => UserModel)
52 @BelongsTo(() => UserModel, {
60 static listForApi (user: MUserAccountId, start: number, count: number, search?: string) {
61 return VideoModel.listForApi({
65 sort: '-"userVideoHistory"."updatedAt"',
67 displayOnlyForFollower: null,
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)