aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/request-video-event.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/request-video-event.ts')
-rw-r--r--server/models/request-video-event.ts19
1 files changed, 10 insertions, 9 deletions
diff --git a/server/models/request-video-event.ts b/server/models/request-video-event.ts
index 234e2a8a9..e422649af 100644
--- a/server/models/request-video-event.ts
+++ b/server/models/request-video-event.ts
@@ -5,16 +5,17 @@
5import { values } from 'lodash' 5import { values } from 'lodash'
6import * as Sequelize from 'sequelize' 6import * as Sequelize from 'sequelize'
7 7
8import { database as db } from '../initializers/database'
8import { REQUEST_VIDEO_EVENT_TYPES } from '../initializers' 9import { REQUEST_VIDEO_EVENT_TYPES } from '../initializers'
9import { isVideoEventCountValid } from '../helpers' 10import { isVideoEventCountValid } from '../helpers'
10
11import { addMethodsToModel } from './utils' 11import { addMethodsToModel } from './utils'
12import { 12import {
13 RequestVideoEventClass, 13 RequestVideoEventClass,
14 RequestVideoEventInstance, 14 RequestVideoEventInstance,
15 RequestVideoEventAttributes, 15 RequestVideoEventAttributes,
16 16
17 RequestVideoEventMethods 17 RequestVideoEventMethods,
18 RequestsVideoEventGrouped
18} from './request-video-event-interface' 19} from './request-video-event-interface'
19 20
20let RequestVideoEvent: Sequelize.Model<RequestVideoEventInstance, RequestVideoEventAttributes> 21let RequestVideoEvent: Sequelize.Model<RequestVideoEventInstance, RequestVideoEventAttributes>
@@ -76,13 +77,13 @@ function associate (models) {
76 }) 77 })
77} 78}
78 79
79countTotalRequests = function (callback) { 80countTotalRequests = function (callback: RequestVideoEventMethods.CountTotalRequestsCallback) {
80 const query = {} 81 const query = {}
81 return RequestVideoEvent.count(query).asCallback(callback) 82 return RequestVideoEvent.count(query).asCallback(callback)
82} 83}
83 84
84listWithLimitAndRandom = function (limitPods, limitRequestsPerPod, callback) { 85listWithLimitAndRandom = function (limitPods: number, limitRequestsPerPod: number, callback: RequestVideoEventMethods.ListWithLimitAndRandomCallback) {
85 const Pod = RequestVideoEvent['sequelize'].models.Pod 86 const Pod = db.Pod
86 87
87 // We make a join between videos and authors to find the podId of our video event requests 88 // We make a join between videos and authors to find the podId of our video event requests
88 const podJoins = 'INNER JOIN "Videos" ON "Videos"."authorId" = "Authors"."id" ' + 89 const podJoins = 'INNER JOIN "Videos" ON "Videos"."authorId" = "Authors"."id" ' +
@@ -129,7 +130,7 @@ listWithLimitAndRandom = function (limitPods, limitRequestsPerPod, callback) {
129 }) 130 })
130} 131}
131 132
132removeByRequestIdsAndPod = function (ids, podId, callback) { 133removeByRequestIdsAndPod = function (ids: number[], podId: number, callback: RequestVideoEventMethods.RemoveByRequestIdsAndPodCallback) {
133 const query = { 134 const query = {
134 where: { 135 where: {
135 id: { 136 id: {
@@ -154,15 +155,15 @@ removeByRequestIdsAndPod = function (ids, podId, callback) {
154 RequestVideoEvent.destroy(query).asCallback(callback) 155 RequestVideoEvent.destroy(query).asCallback(callback)
155} 156}
156 157
157removeAll = function (callback) { 158removeAll = function (callback: RequestVideoEventMethods.RemoveAllCallback) {
158 // Delete all requests 159 // Delete all requests
159 RequestVideoEvent.truncate({ cascade: true }).asCallback(callback) 160 RequestVideoEvent.truncate({ cascade: true }).asCallback(callback)
160} 161}
161 162
162// --------------------------------------------------------------------------- 163// ---------------------------------------------------------------------------
163 164
164function groupAndTruncateRequests (events, limitRequestsPerPod) { 165function groupAndTruncateRequests (events: RequestVideoEventInstance[], limitRequestsPerPod: number) {
165 const eventsGrouped = {} 166 const eventsGrouped: RequestsVideoEventGrouped = {}
166 167
167 events.forEach(function (event) { 168 events.forEach(function (event) {
168 const pod = event.Video.Author.Pod 169 const pod = event.Video.Author.Pod