import * as Sequelize from 'sequelize'
+import * as Bluebird from 'bluebird'
import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript'
import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
import { CONSTRAINTS_FIELDS } from '../../initializers'
})
}
+ static loadByUrl (url: string, t: Sequelize.Transaction) {
+ return VideoShareModel.scope(ScopeNames.FULL).findOne({
+ where: {
+ url
+ },
+ transaction: t
+ })
+ }
+
static loadActorsByShare (videoId: number, t: Sequelize.Transaction) {
const query = {
where: {
.then(res => res.map(r => r.Actor))
}
- static loadActorsByVideoOwner (actorOwnerId: number, t: Sequelize.Transaction) {
+ static loadActorsByVideoOwner (actorOwnerId: number, t: Sequelize.Transaction): Bluebird<ActorModel[]> {
const query = {
attributes: [],
include: [
return VideoShareModel.scope(ScopeNames.FULL).findAll(query)
.then(res => res.map(r => r.Actor))
}
+
+ static loadActorsByVideoChannel (videoChannelId: number, t: Sequelize.Transaction): Bluebird<ActorModel[]> {
+ const query = {
+ attributes: [],
+ include: [
+ {
+ model: ActorModel,
+ required: true
+ },
+ {
+ attributes: [],
+ model: VideoModel,
+ required: true,
+ where: {
+ channelId: videoChannelId
+ }
+ }
+ ],
+ transaction: t
+ }
+
+ return VideoShareModel.scope(ScopeNames.FULL)
+ .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)
+ }
}