})
Video: VideoModel
- static load (actorId: number, videoId: number, t: Sequelize.Transaction) {
+ static load (actorId: number, videoId: number, t?: Sequelize.Transaction) {
return VideoShareModel.scope(ScopeNames.WITH_ACTOR).findOne({
where: {
actorId,
}
static loadByUrl (url: string, t: Sequelize.Transaction) {
- return VideoShareModel.scope(ScopeNames.WITH_ACTOR).findOne({
+ return VideoShareModel.scope(ScopeNames.FULL).findOne({
where: {
url
},
.then(res => res.map(r => r.Actor))
}
- static loadActorsByVideoOwner (actorOwnerId: number, t: Sequelize.Transaction): Bluebird<ActorModel[]> {
+ static loadActorsWhoSharedVideosOf (actorOwnerId: number, t: Sequelize.Transaction): Bluebird<ActorModel[]> {
const query = {
attributes: [],
include: [
.findAll(query)
.then(res => res.map(r => r.Actor))
}
+
+ static listAndCountByVideoId (videoId: number, start: number, count: number, t?: Sequelize.Transaction) {
+ const query = {
+ offset: start,
+ limit: count,
+ where: {
+ videoId
+ },
+ transaction: t
+ }
+
+ return VideoShareModel.findAndCountAll(query)
+ }
+
+ static cleanOldSharesOf (videoId: number, beforeUpdatedAt: Date) {
+ const query = {
+ where: {
+ updatedAt: {
+ [Sequelize.Op.lt]: beforeUpdatedAt
+ },
+ videoId
+ }
+ }
+
+ return VideoShareModel.destroy(query)
+ }
}