From 453e83ea5d81d203ba34bc43cd5c2c750ba40568 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 15 Aug 2019 11:53:26 +0200 Subject: Stronger model typings --- server/models/account/account-video-rate.ts | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'server/models/account/account-video-rate.ts') diff --git a/server/models/account/account-video-rate.ts b/server/models/account/account-video-rate.ts index 4bd8114cf..8b62dd05f 100644 --- a/server/models/account/account-video-rate.ts +++ b/server/models/account/account-video-rate.ts @@ -10,6 +10,8 @@ import { buildLocalAccountIdsIn, getSort, throwIfNotValid } from '../utils' import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' 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' /* Account rates per video. @@ -77,7 +79,7 @@ export class AccountVideoRateModel extends Model { }) Account: AccountModel - static load (accountId: number, videoId: number, transaction?: Transaction) { + static load (accountId: number, videoId: number, transaction?: Transaction): Bluebird { const options: FindOptions = { where: { accountId, @@ -89,7 +91,7 @@ export class AccountVideoRateModel extends Model { return AccountVideoRateModel.findOne(options) } - static loadByAccountAndVideoOrUrl (accountId: number, videoId: number, url: string, transaction?: Transaction) { + static loadByAccountAndVideoOrUrl (accountId: number, videoId: number, url: string, t?: Transaction): Bluebird { const options: FindOptions = { where: { [ Op.or]: [ @@ -103,7 +105,7 @@ export class AccountVideoRateModel extends Model { ] } } - if (transaction) options.transaction = transaction + if (t) options.transaction = t return AccountVideoRateModel.findOne(options) } @@ -140,7 +142,12 @@ export class AccountVideoRateModel extends Model { return AccountVideoRateModel.findAndCountAll(query) } - static loadLocalAndPopulateVideo (rateType: VideoRateType, accountName: string, videoId: number, transaction?: Transaction) { + static loadLocalAndPopulateVideo ( + rateType: VideoRateType, + accountName: string, + videoId: number, + t?: Transaction + ): Bluebird { const options: FindOptions = { where: { videoId, @@ -152,7 +159,7 @@ export class AccountVideoRateModel extends Model { required: true, include: [ { - attributes: [ 'id', 'url', 'preferredUsername' ], + attributes: [ 'id', 'url', 'followersUrl', 'preferredUsername' ], model: ActorModel.unscoped(), required: true, where: { @@ -167,7 +174,7 @@ export class AccountVideoRateModel extends Model { } ] } - if (transaction) options.transaction = transaction + if (t) options.transaction = t return AccountVideoRateModel.findOne(options) } @@ -208,7 +215,7 @@ export class AccountVideoRateModel extends Model { ] } - return AccountVideoRateModel.findAndCountAll(query) + return AccountVideoRateModel.findAndCountAll(query) } static cleanOldRatesOf (videoId: number, type: VideoRateType, beforeUpdatedAt: Date) { -- cgit v1.2.3 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-video-rate.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'server/models/account/account-video-rate.ts') 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 -- cgit v1.2.3