From 7d9ba5c08999c6482f0bc5e0c09c6f55b7724090 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 11 May 2021 11:15:29 +0200 Subject: Cleanup models directory organization --- server/models/account/user-video-history.ts | 100 ---------------------------- 1 file changed, 100 deletions(-) delete mode 100644 server/models/account/user-video-history.ts (limited to 'server/models/account/user-video-history.ts') diff --git a/server/models/account/user-video-history.ts b/server/models/account/user-video-history.ts deleted file mode 100644 index 6be1d65ea..000000000 --- a/server/models/account/user-video-history.ts +++ /dev/null @@ -1,100 +0,0 @@ -import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, IsInt, Model, Table, UpdatedAt } from 'sequelize-typescript' -import { VideoModel } from '../video/video' -import { UserModel } from './user' -import { DestroyOptions, Op, Transaction } from 'sequelize' -import { MUserAccountId, MUserId } from '@server/types/models' - -@Table({ - tableName: 'userVideoHistory', - indexes: [ - { - fields: [ 'userId', 'videoId' ], - unique: true - }, - { - fields: [ 'userId' ] - }, - { - fields: [ 'videoId' ] - } - ] -}) -export class UserVideoHistoryModel extends Model { - @CreatedAt - createdAt: Date - - @UpdatedAt - updatedAt: Date - - @AllowNull(false) - @IsInt - @Column - currentTime: number - - @ForeignKey(() => VideoModel) - @Column - videoId: number - - @BelongsTo(() => VideoModel, { - foreignKey: { - allowNull: false - }, - onDelete: 'CASCADE' - }) - Video: VideoModel - - @ForeignKey(() => UserModel) - @Column - userId: number - - @BelongsTo(() => UserModel, { - foreignKey: { - allowNull: false - }, - onDelete: 'CASCADE' - }) - User: UserModel - - static listForApi (user: MUserAccountId, start: number, count: number, search?: string) { - return VideoModel.listForApi({ - start, - count, - search, - sort: '-"userVideoHistory"."updatedAt"', - nsfw: null, // All - includeLocalVideos: true, - withFiles: false, - user, - historyOfUser: user - }) - } - - static removeUserHistoryBefore (user: MUserId, beforeDate: string, t: Transaction) { - const query: DestroyOptions = { - where: { - userId: user.id - }, - transaction: t - } - - if (beforeDate) { - query.where['updatedAt'] = { - [Op.lt]: beforeDate - } - } - - return UserVideoHistoryModel.destroy(query) - } - - static removeOldHistory (beforeDate: string) { - const query: DestroyOptions = { - where: { - updatedAt: { - [Op.lt]: beforeDate - } - } - } - - return UserVideoHistoryModel.destroy(query) - } -} -- cgit v1.2.3