1 import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, IsInt, Model, Table, UpdatedAt } from 'sequelize-typescript'
2 import { VideoModel } from '../video/video'
3 import { UserModel } from './user'
4 import { DestroyOptions, Op, Transaction } from 'sequelize'
5 import { MUserAccountId, MUserId } from '@server/types/models'
8 tableName: 'userVideoHistory',
11 fields: [ 'userId', 'videoId' ],
22 export class UserVideoHistoryModel extends Model {
34 @ForeignKey(() => VideoModel)
38 @BelongsTo(() => VideoModel, {
46 @ForeignKey(() => UserModel)
50 @BelongsTo(() => UserModel, {
58 static listForApi (user: MUserAccountId, start: number, count: number, search?: string) {
59 return VideoModel.listForApi({
63 sort: '-"userVideoHistory"."updatedAt"',
65 includeLocalVideos: true,
72 static removeUserHistoryBefore (user: MUserId, beforeDate: string, t: Transaction) {
73 const query: DestroyOptions = {
81 query.where['updatedAt'] = {
86 return UserVideoHistoryModel.destroy(query)
89 static removeOldHistory (beforeDate: string) {
90 const query: DestroyOptions = {
98 return UserVideoHistoryModel.destroy(query)