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 { Transaction, Op, DestroyOptions } from 'sequelize'
7 tableName: 'userVideoHistory',
10 fields: [ 'userId', 'videoId' ],
21 export class UserVideoHistoryModel extends Model<UserVideoHistoryModel> {
33 @ForeignKey(() => VideoModel)
37 @BelongsTo(() => VideoModel, {
45 @ForeignKey(() => UserModel)
49 @BelongsTo(() => UserModel, {
57 static listForApi (user: UserModel, start: number, count: number) {
58 return VideoModel.listForApi({
61 sort: '-UserVideoHistories.updatedAt',
63 includeLocalVideos: true,
70 static removeHistoryBefore (user: UserModel, beforeDate: string, t: Transaction) {
71 const query: DestroyOptions = {
79 query.where.updatedAt = {
84 return UserVideoHistoryModel.destroy(query)