]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/request/request-video-event-scheduler.ts
Better typescript typing for a better world
[github/Chocobozzz/PeerTube.git] / server / lib / request / request-video-event-scheduler.ts
index d4d714c02facd5271c460190e51886d11e26f04e..8a008c51bbae9d3c15bb0bfc5152285c28c6c4e5 100644 (file)
@@ -1,14 +1,14 @@
 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 {
   REQUESTS_VIDEO_EVENT_LIMIT_PODS,
   REQUESTS_VIDEO_EVENT_LIMIT_PER_POD,
   REQUEST_VIDEO_EVENT_ENDPOINT
 } from '../../initializers'
 import { RequestsVideoEventGrouped } from '../../models'
-import { RequestVideoEventType } from '../../../shared'
+import { RequestVideoEventType, RemoteVideoEventRequest, RemoteVideoEventType } from '../../../shared'
 
 export type RequestVideoEventSchedulerOptions = {
   type: RequestVideoEventType
@@ -36,8 +36,8 @@ class RequestVideoEventScheduler extends AbstractRequestScheduler<RequestsVideoE
     return db.RequestVideoEvent
   }
 
-  buildRequestObjects (eventRequests: RequestsVideoEventGrouped) {
-    const requestsToMakeGrouped = {}
+  buildRequestsObjects (eventRequests: RequestsVideoEventGrouped) {
+    const requestsToMakeGrouped: RequestsObjects<RemoteVideoEventRequest> = {}
 
     /* Example:
         {
@@ -47,7 +47,15 @@ class RequestVideoEventScheduler extends AbstractRequestScheduler<RequestsVideoE
           }
         }
     */
-    const eventsPerVideoPerPod = {}
+    const eventsPerVideoPerPod: {
+      [ podId: string ]: {
+        [ videoRemoteId: string ]: {
+          views?: number
+          likes?: number
+          dislikes?: number
+        }
+      }
+    } = {}
 
     // We group video events per video and per pod
     // We add the counts of the same event types
@@ -87,8 +95,8 @@ class RequestVideoEventScheduler extends AbstractRequestScheduler<RequestsVideoE
           requestsToMakeGrouped[toPodId].datas.push({
             data: {
               remoteId,
-              eventType,
-              count: eventsForVideo[eventType]
+              eventType: eventType as RemoteVideoEventType,
+              count: +eventsForVideo[eventType]
             }
           })
         })