2017-12-12 17:53:50 +01:00
|
|
|
import { BelongsTo, Column, CreatedAt, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript'
|
2017-12-28 11:16:08 +01:00
|
|
|
import { SortType } from '../../helpers/utils'
|
2017-12-12 17:53:50 +01:00
|
|
|
import { getSortOnModel } from '../utils'
|
|
|
|
import { VideoModel } from './video'
|
2017-05-22 20:58:25 +02:00
|
|
|
|
2017-12-12 17:53:50 +01:00
|
|
|
@Table({
|
|
|
|
tableName: 'videoBlacklist',
|
|
|
|
indexes: [
|
2017-04-26 21:22:10 +02:00
|
|
|
{
|
2017-12-12 17:53:50 +01:00
|
|
|
fields: [ 'videoId' ],
|
|
|
|
unique: true
|
2017-04-26 21:22:10 +02:00
|
|
|
}
|
2017-05-22 20:58:25 +02:00
|
|
|
]
|
2017-12-12 17:53:50 +01:00
|
|
|
})
|
|
|
|
export class VideoBlacklistModel extends Model<VideoBlacklistModel> {
|
2017-04-26 21:22:10 +02:00
|
|
|
|
2017-12-12 17:53:50 +01:00
|
|
|
@CreatedAt
|
|
|
|
createdAt: Date
|
2017-04-26 21:22:10 +02:00
|
|
|
|
2017-12-12 17:53:50 +01:00
|
|
|
@UpdatedAt
|
|
|
|
updatedAt: Date
|
2017-04-26 21:22:10 +02:00
|
|
|
|
2017-12-12 17:53:50 +01:00
|
|
|
@ForeignKey(() => VideoModel)
|
|
|
|
@Column
|
|
|
|
videoId: number
|
2017-04-26 21:22:10 +02:00
|
|
|
|
2017-12-12 17:53:50 +01:00
|
|
|
@BelongsTo(() => VideoModel, {
|
2017-07-11 16:01:56 +02:00
|
|
|
foreignKey: {
|
|
|
|
allowNull: false
|
|
|
|
},
|
2017-12-12 17:53:50 +01:00
|
|
|
onDelete: 'cascade'
|
2017-04-26 21:22:10 +02:00
|
|
|
})
|
2017-12-12 17:53:50 +01:00
|
|
|
Video: VideoModel
|
|
|
|
|
|
|
|
static listForApi (start: number, count: number, sort: SortType) {
|
|
|
|
const query = {
|
|
|
|
offset: start,
|
|
|
|
limit: count,
|
|
|
|
order: [ getSortOnModel(sort.sortModel, sort.sortValue) ],
|
|
|
|
include: [ { model: VideoModel } ]
|
|
|
|
}
|
2017-04-26 21:22:10 +02:00
|
|
|
|
2017-12-12 17:53:50 +01:00
|
|
|
return VideoBlacklistModel.findAndCountAll(query)
|
|
|
|
.then(({ rows, count }) => {
|
|
|
|
return {
|
|
|
|
data: rows,
|
|
|
|
total: count
|
|
|
|
}
|
|
|
|
})
|
2017-04-26 21:22:10 +02:00
|
|
|
}
|
|
|
|
|
2017-12-12 17:53:50 +01:00
|
|
|
static loadByVideoId (id: number) {
|
|
|
|
const query = {
|
|
|
|
where: {
|
|
|
|
videoId: id
|
|
|
|
}
|
2017-07-05 13:26:25 +02:00
|
|
|
}
|
2017-04-26 21:22:10 +02:00
|
|
|
|
2017-12-12 17:53:50 +01:00
|
|
|
return VideoBlacklistModel.findOne(query)
|
2017-04-26 21:22:10 +02:00
|
|
|
}
|
|
|
|
|
2017-12-12 17:53:50 +01:00
|
|
|
toFormattedJSON () {
|
|
|
|
const video = this.Video
|
|
|
|
|
|
|
|
return {
|
|
|
|
id: this.id,
|
|
|
|
videoId: this.videoId,
|
|
|
|
createdAt: this.createdAt,
|
|
|
|
updatedAt: this.updatedAt,
|
|
|
|
name: video.name,
|
|
|
|
uuid: video.uuid,
|
|
|
|
description: video.description,
|
|
|
|
duration: video.duration,
|
|
|
|
views: video.views,
|
|
|
|
likes: video.likes,
|
|
|
|
dislikes: video.dislikes,
|
|
|
|
nsfw: video.nsfw
|
|
|
|
}
|
|
|
|
}
|
2017-04-26 21:22:10 +02:00
|
|
|
}
|