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/typings/models'
8 tableName: 'userVideoHistory',
11 fields: [ 'userId', 'videoId' ],
22 export class UserVideoHistoryModel extends Model<UserVideoHistoryModel> {
34 @ForeignKey(() => VideoModel)
38 @BelongsTo(() => VideoModel, {
46 @ForeignKey(() => UserModel)
50 @BelongsTo(() => UserModel, {
58 static listForApi (user: MUserAccountId, start: number, count: number) {
59 return VideoModel.listForApi({
62 sort: '-"userVideoHistory"."updatedAt"',
64 includeLocalVideos: true,
71 static removeUserHistoryBefore (user: MUserId, beforeDate: string, t: Transaction) {
72 const query: DestroyOptions = {
80 query.where['updatedAt'] = {
85 return UserVideoHistoryModel.destroy(query)
88 static removeOldHistory (beforeDate: string) {
89 const query: DestroyOptions = {
97 return UserVideoHistoryModel.destroy(query)