2018-08-29 16:26:25 +02:00
|
|
|
import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Model, Table } from 'sequelize-typescript'
|
|
|
|
import { VideoModel } from './video'
|
|
|
|
import * as Sequelize from 'sequelize'
|
|
|
|
|
|
|
|
@Table({
|
|
|
|
tableName: 'videoView',
|
2019-04-26 09:16:43 +02:00
|
|
|
updatedAt: false,
|
2018-08-29 16:26:25 +02:00
|
|
|
indexes: [
|
|
|
|
{
|
|
|
|
fields: [ 'videoId' ]
|
2018-09-04 15:25:02 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
fields: [ 'startDate' ]
|
2018-08-29 16:26:25 +02:00
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
2020-12-08 14:30:29 +01:00
|
|
|
export class VideoViewModel extends Model {
|
2018-08-29 16:26:25 +02:00
|
|
|
@CreatedAt
|
|
|
|
createdAt: Date
|
|
|
|
|
|
|
|
@AllowNull(false)
|
|
|
|
@Column(Sequelize.DATE)
|
|
|
|
startDate: Date
|
|
|
|
|
|
|
|
@AllowNull(false)
|
|
|
|
@Column(Sequelize.DATE)
|
|
|
|
endDate: Date
|
|
|
|
|
|
|
|
@AllowNull(false)
|
|
|
|
@Column
|
|
|
|
views: number
|
|
|
|
|
|
|
|
@ForeignKey(() => VideoModel)
|
|
|
|
@Column
|
|
|
|
videoId: number
|
|
|
|
|
|
|
|
@BelongsTo(() => VideoModel, {
|
|
|
|
foreignKey: {
|
|
|
|
allowNull: false
|
|
|
|
},
|
|
|
|
onDelete: 'CASCADE'
|
|
|
|
})
|
|
|
|
Video: VideoModel
|
|
|
|
|
2019-04-11 17:33:36 +02:00
|
|
|
static removeOldRemoteViewsHistory (beforeDate: string) {
|
|
|
|
const query = {
|
|
|
|
where: {
|
|
|
|
startDate: {
|
|
|
|
[Sequelize.Op.lt]: beforeDate
|
|
|
|
},
|
|
|
|
videoId: {
|
|
|
|
[Sequelize.Op.in]: Sequelize.literal('(SELECT "id" FROM "video" WHERE "remote" IS TRUE)')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return VideoViewModel.destroy(query)
|
|
|
|
}
|
2018-08-29 16:26:25 +02:00
|
|
|
}
|