From 0f320037e689b2778959c12ddd4ce790f6e4ae4f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 11 May 2018 15:10:13 +0200 Subject: Add ability to update a video channel --- server/models/video/video-share.ts | 9 +++++++++ server/models/video/video.ts | 37 ++++++++++++++++++++++++++++++++++--- 2 files changed, 43 insertions(+), 3 deletions(-) (limited to 'server/models') diff --git a/server/models/video/video-share.ts b/server/models/video/video-share.ts index 6f770957f..602cc69b9 100644 --- a/server/models/video/video-share.ts +++ b/server/models/video/video-share.ts @@ -98,6 +98,15 @@ export class VideoShareModel extends Model { }) } + static loadByUrl (url: string, t: Sequelize.Transaction) { + return VideoShareModel.scope(ScopeNames.WITH_ACTOR).findOne({ + where: { + url + }, + transaction: t + }) + } + static loadActorsByShare (videoId: number, t: Sequelize.Transaction) { const query = { where: { diff --git a/server/models/video/video.ts b/server/models/video/video.ts index ea466fccd..fe8c30655 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -130,11 +130,27 @@ enum ScopeNames { } const videoChannelInclude = { - attributes: [ 'name', 'description' ], + attributes: [ 'name', 'description', 'id' ], model: VideoChannelModel.unscoped(), required: true, where: {}, include: [ + { + attributes: [ 'uuid', 'preferredUsername', 'url', 'serverId', 'avatarId' ], + model: ActorModel.unscoped(), + required: true, + include: [ + { + attributes: [ 'host' ], + model: ServerModel.unscoped(), + required: false + }, + { + model: AvatarModel.unscoped(), + required: false + } + ] + }, accountInclude ] } @@ -771,12 +787,17 @@ export class VideoModel extends Model { } }, { - preferredUsername: Sequelize.where(Sequelize.col('preferredUsername'), { + preferredUsernameChannel: Sequelize.where(Sequelize.col('VideoChannel->Actor.preferredUsername'), { [ Sequelize.Op.iLike ]: '%' + value + '%' }) }, { - host: Sequelize.where(Sequelize.col('host'), { + preferredUsernameAccount: Sequelize.where(Sequelize.col('VideoChannel->Account->Actor.preferredUsername'), { + [ Sequelize.Op.iLike ]: '%' + value + '%' + }) + }, + { + host: Sequelize.where(Sequelize.col('VideoChannel->Account->Actor->Server.host'), { [ Sequelize.Op.iLike ]: '%' + value + '%' }) } @@ -1043,6 +1064,7 @@ export class VideoModel extends Model { toFormattedJSON (): Video { const formattedAccount = this.VideoChannel.Account.toFormattedJSON() + const formattedVideoChannel = this.VideoChannel.toFormattedJSON() return { id: this.id, @@ -1085,6 +1107,15 @@ export class VideoModel extends Model { url: formattedAccount.url, host: formattedAccount.host, avatar: formattedAccount.avatar + }, + channel: { + id: formattedVideoChannel.id, + uuid: formattedVideoChannel.uuid, + name: formattedVideoChannel.name, + displayName: formattedVideoChannel.displayName, + url: formattedVideoChannel.url, + host: formattedVideoChannel.host, + avatar: formattedVideoChannel.avatar } } } -- cgit v1.2.3