From 1ca9f7c3f7afac2af4c4c25b98426731f7e789c6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 20 Aug 2019 19:05:31 +0200 Subject: Type toFormattedJSON --- server/models/account/account-blocklist.ts | 4 ++-- server/models/account/account-video-rate.ts | 9 +++++++-- server/models/account/account.ts | 8 ++++---- server/models/account/user-notification-setting.ts | 3 ++- server/models/account/user.ts | 12 ++++++++++-- 5 files changed, 25 insertions(+), 11 deletions(-) (limited to 'server/models/account') diff --git a/server/models/account/account-blocklist.ts b/server/models/account/account-blocklist.ts index bb5371395..8bcaca828 100644 --- a/server/models/account/account-blocklist.ts +++ b/server/models/account/account-blocklist.ts @@ -4,7 +4,7 @@ import { getSort } from '../utils' import { AccountBlock } from '../../../shared/models/blocklist' import { Op } from 'sequelize' import * as Bluebird from 'bluebird' -import { MAccountBlocklist, MAccountBlocklistAccounts } from '@server/typings/models' +import { MAccountBlocklist, MAccountBlocklistAccounts, MAccountBlocklistFormattable } from '@server/typings/models' enum ScopeNames { WITH_ACCOUNTS = 'WITH_ACCOUNTS' @@ -134,7 +134,7 @@ export class AccountBlocklistModel extends Model { }) } - toFormattedJSON (): AccountBlock { + toFormattedJSON (this: MAccountBlocklistFormattable): AccountBlock { return { byAccount: this.ByAccount.toFormattedJSON(), blockedAccount: this.BlockedAccount.toFormattedJSON(), diff --git a/server/models/account/account-video-rate.ts b/server/models/account/account-video-rate.ts index 8b62dd05f..a6edbeee8 100644 --- a/server/models/account/account-video-rate.ts +++ b/server/models/account/account-video-rate.ts @@ -11,7 +11,12 @@ import { isActivityPubUrlValid } from '../../helpers/custom-validators/activityp import { AccountVideoRate } from '../../../shared' import { ScopeNames as VideoChannelScopeNames, SummaryOptions, VideoChannelModel } from '../video/video-channel' import * as Bluebird from 'bluebird' -import { MAccountVideoRate, MAccountVideoRateAccountUrl, MAccountVideoRateAccountVideo } from '@server/typings/models/video/video-rate' +import { + MAccountVideoRate, + MAccountVideoRateAccountUrl, + MAccountVideoRateAccountVideo, + MAccountVideoRateFormattable +} from '@server/typings/models/video/video-rate' /* Account rates per video. @@ -248,7 +253,7 @@ export class AccountVideoRateModel extends Model { }) } - toFormattedJSON (): AccountVideoRate { + toFormattedJSON (this: MAccountVideoRateFormattable): AccountVideoRate { return { video: this.Video.toFormattedJSON(), rating: this.type diff --git a/server/models/account/account.ts b/server/models/account/account.ts index 4cc731075..8369738b9 100644 --- a/server/models/account/account.ts +++ b/server/models/account/account.ts @@ -32,7 +32,7 @@ import { FindOptions, IncludeOptions, Op, Transaction, WhereOptions } from 'sequ import { AccountBlocklistModel } from './account-blocklist' import { ServerBlocklistModel } from '../server/server-blocklist' import { ActorFollowModel } from '../activitypub/actor-follow' -import { MAccountActor, MAccountDefault } from '../../typings/models' +import { MAccountActor, MAccountDefault, MAccountSummaryFormattable, MAccountFormattable } from '../../typings/models' import * as Bluebird from 'bluebird' export enum ScopeNames { @@ -353,7 +353,7 @@ export class AccountModel extends Model { .findAll(query) } - toFormattedJSON (): Account { + toFormattedJSON (this: MAccountFormattable): Account { const actor = this.Actor.toFormattedJSON() const account = { id: this.id, @@ -367,8 +367,8 @@ export class AccountModel extends Model { return Object.assign(actor, account) } - toFormattedSummaryJSON (): AccountSummary { - const actor = this.Actor.toFormattedJSON() + toFormattedSummaryJSON (this: MAccountSummaryFormattable): AccountSummary { + const actor = this.Actor.toFormattedSummaryJSON() return { id: this.id, diff --git a/server/models/account/user-notification-setting.ts b/server/models/account/user-notification-setting.ts index c2fbc6d23..1506295cf 100644 --- a/server/models/account/user-notification-setting.ts +++ b/server/models/account/user-notification-setting.ts @@ -17,6 +17,7 @@ import { UserModel } from './user' import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications' import { UserNotificationSetting, UserNotificationSettingValue } from '../../../shared/models/users/user-notification-setting.model' import { clearCacheByUserId } from '../../lib/oauth-model' +import { MNotificationSettingFormattable } from '@server/typings/models' @Table({ tableName: 'userNotificationSetting', @@ -152,7 +153,7 @@ export class UserNotificationSettingModel extends Model { return comparePassword(password, this.password) } - toFormattedJSON (parameters: { withAdminFlags?: boolean } = {}): User { + toSummaryJSON + + toFormattedJSON (this: MUserFormattable, parameters: { withAdminFlags?: boolean } = {}): User { const videoQuotaUsed = this.get('videoQuotaUsed') const videoQuotaUsedDaily = this.get('videoQuotaUsedDaily') -- cgit v1.2.3