From 4771e0008dd26eadbb7eaff64255a6ec914fdadb Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 10 Jul 2017 19:43:21 +0200 Subject: Better typescript typing for a better world --- server/lib/request/request-video-qadu-scheduler.ts | 31 +++++++++++++++++----- 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'server/lib/request/request-video-qadu-scheduler.ts') diff --git a/server/lib/request/request-video-qadu-scheduler.ts b/server/lib/request/request-video-qadu-scheduler.ts index 5ec7de9c2..988165170 100644 --- a/server/lib/request/request-video-qadu-scheduler.ts +++ b/server/lib/request/request-video-qadu-scheduler.ts @@ -1,7 +1,7 @@ import * as Sequelize from 'sequelize' import { database as db } from '../../initializers/database' -import { AbstractRequestScheduler } from './abstract-request-scheduler' +import { AbstractRequestScheduler, RequestsObjects } from './abstract-request-scheduler' import { logger } from '../../helpers' import { REQUESTS_VIDEO_QADU_LIMIT_PODS, @@ -9,8 +9,27 @@ import { REQUEST_VIDEO_QADU_ENDPOINT, REQUEST_VIDEO_QADU_TYPES } from '../../initializers' -import { RequestsVideoQaduGrouped } from '../../models' -import { RequestVideoQaduType } from '../../../shared' +import { RequestsVideoQaduGrouped, PodInstance } from '../../models' +import { RemoteQaduVideoRequest, RequestVideoQaduType } from '../../../shared' + +// We create a custom interface because we need "videos" attribute for our computations +interface RequestsObjectsCustom extends RequestsObjects { + [ id: string ]: { + toPod: PodInstance + endpoint: string + ids: number[] // ids + datas: U[] + + videos: { + [ id: string ]: { + remoteId: string + likes?: number + dislikes?: number + views?: number + } + } + } +} export type RequestVideoQaduSchedulerOptions = { type: RequestVideoQaduType @@ -37,8 +56,8 @@ class RequestVideoQaduScheduler extends AbstractRequestScheduler = {} Object.keys(requests).forEach(toPodId => { requests[toPodId].forEach(data => { @@ -59,7 +78,7 @@ class RequestVideoQaduScheduler extends AbstractRequestScheduler