diff options
Diffstat (limited to 'server/models/request-video-event.ts')
-rw-r--r-- | server/models/request-video-event.ts | 19 |
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 @@ | |||
5 | import { values } from 'lodash' | 5 | import { values } from 'lodash' |
6 | import * as Sequelize from 'sequelize' | 6 | import * as Sequelize from 'sequelize' |
7 | 7 | ||
8 | import { database as db } from '../initializers/database' | ||
8 | import { REQUEST_VIDEO_EVENT_TYPES } from '../initializers' | 9 | import { REQUEST_VIDEO_EVENT_TYPES } from '../initializers' |
9 | import { isVideoEventCountValid } from '../helpers' | 10 | import { isVideoEventCountValid } from '../helpers' |
10 | |||
11 | import { addMethodsToModel } from './utils' | 11 | import { addMethodsToModel } from './utils' |
12 | import { | 12 | import { |
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 | ||
20 | let RequestVideoEvent: Sequelize.Model<RequestVideoEventInstance, RequestVideoEventAttributes> | 21 | let RequestVideoEvent: Sequelize.Model<RequestVideoEventInstance, RequestVideoEventAttributes> |
@@ -76,13 +77,13 @@ function associate (models) { | |||
76 | }) | 77 | }) |
77 | } | 78 | } |
78 | 79 | ||
79 | countTotalRequests = function (callback) { | 80 | countTotalRequests = 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 | ||
84 | listWithLimitAndRandom = function (limitPods, limitRequestsPerPod, callback) { | 85 | listWithLimitAndRandom = 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 | ||
132 | removeByRequestIdsAndPod = function (ids, podId, callback) { | 133 | removeByRequestIdsAndPod = 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 | ||
157 | removeAll = function (callback) { | 158 | removeAll = 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 | ||
164 | function groupAndTruncateRequests (events, limitRequestsPerPod) { | 165 | function 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 |