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'
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 displayOnlyForFollower: null,
72 static removeUserHistoryElement (user: MUserId, videoId: number) {
73 const query: DestroyOptions = {
80 return UserVideoHistoryModel.destroy(query)
83 static removeUserHistoryBefore (user: MUserId, beforeDate: string, t: Transaction) {
84 const query: DestroyOptions = {
92 query.where['updatedAt'] = {
97 return UserVideoHistoryModel.destroy(query)
100 static removeOldHistory (beforeDate: string) {
101 const query: DestroyOptions = {
109 return UserVideoHistoryModel.destroy(query)