From 418d092afa81e2c8fe8ac6838fc4b5eb0af6a782 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 26 Feb 2019 10:55:40 +0100 Subject: Playlist server API --- server/models/account/account.ts | 60 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 2 deletions(-) (limited to 'server/models/account') diff --git a/server/models/account/account.ts b/server/models/account/account.ts index ee22d8528..3fb766c8a 100644 --- a/server/models/account/account.ts +++ b/server/models/account/account.ts @@ -10,11 +10,11 @@ import { ForeignKey, HasMany, Is, - Model, + Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' -import { Account } from '../../../shared/models/actors' +import { Account, AccountSummary } from '../../../shared/models/actors' import { isAccountDescriptionValid } from '../../helpers/custom-validators/accounts' import { sendDeleteActor } from '../../lib/activitypub/send' import { ActorModel } from '../activitypub/actor' @@ -25,6 +25,13 @@ import { VideoChannelModel } from '../video/video-channel' import { VideoCommentModel } from '../video/video-comment' import { UserModel } from './user' import { CONFIG } from '../../initializers' +import { AvatarModel } from '../avatar/avatar' +import { WhereOptions } from 'sequelize' +import { VideoPlaylistModel } from '../video/video-playlist' + +export enum ScopeNames { + SUMMARY = 'SUMMARY' +} @DefaultScope({ include: [ @@ -34,6 +41,32 @@ import { CONFIG } from '../../initializers' } ] }) +@Scopes({ + [ ScopeNames.SUMMARY ]: (whereActor?: WhereOptions) => { + return { + attributes: [ 'id', 'name' ], + include: [ + { + attributes: [ 'id', 'uuid', 'preferredUsername', 'url', 'serverId', 'avatarId' ], + model: ActorModel.unscoped(), + required: true, + where: whereActor, + include: [ + { + attributes: [ 'host' ], + model: ServerModel.unscoped(), + required: false + }, + { + model: AvatarModel.unscoped(), + required: false + } + ] + } + ] + } + } +}) @Table({ tableName: 'account', indexes: [ @@ -112,6 +145,15 @@ export class AccountModel extends Model { }) VideoChannels: VideoChannelModel[] + @HasMany(() => VideoPlaylistModel, { + foreignKey: { + allowNull: false + }, + onDelete: 'cascade', + hooks: true + }) + VideoPlaylists: VideoPlaylistModel[] + @HasMany(() => VideoCommentModel, { foreignKey: { allowNull: false @@ -285,6 +327,20 @@ export class AccountModel extends Model { return Object.assign(actor, account) } + toFormattedSummaryJSON (): AccountSummary { + const actor = this.Actor.toFormattedJSON() + + return { + id: this.id, + uuid: actor.uuid, + name: actor.name, + displayName: this.getDisplayName(), + url: actor.url, + host: actor.host, + avatar: actor.avatar + } + } + toActivityPubObject () { const obj = this.Actor.toActivityPubObject(this.name, 'Account') -- cgit v1.2.3