aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/request/request-video-event.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/request/request-video-event.ts')
-rw-r--r--server/models/request/request-video-event.ts27
1 files changed, 11 insertions, 16 deletions
diff --git a/server/models/request/request-video-event.ts b/server/models/request/request-video-event.ts
index f552ef50b..90ea15702 100644
--- a/server/models/request/request-video-event.ts
+++ b/server/models/request/request-video-event.ts
@@ -10,7 +10,6 @@ import { REQUEST_VIDEO_EVENT_TYPES } from '../../initializers'
10import { isVideoEventCountValid } from '../../helpers' 10import { isVideoEventCountValid } from '../../helpers'
11import { addMethodsToModel } from '../utils' 11import { addMethodsToModel } from '../utils'
12import { 12import {
13 RequestVideoEventClass,
14 RequestVideoEventInstance, 13 RequestVideoEventInstance,
15 RequestVideoEventAttributes, 14 RequestVideoEventAttributes,
16 15
@@ -77,23 +76,21 @@ function associate (models) {
77 }) 76 })
78} 77}
79 78
80countTotalRequests = function (callback: RequestVideoEventMethods.CountTotalRequestsCallback) { 79countTotalRequests = function () {
81 const query = {} 80 const query = {}
82 return RequestVideoEvent.count(query).asCallback(callback) 81 return RequestVideoEvent.count(query)
83} 82}
84 83
85listWithLimitAndRandom = function (limitPods: number, limitRequestsPerPod: number, callback: RequestVideoEventMethods.ListWithLimitAndRandomCallback) { 84listWithLimitAndRandom = function (limitPods: number, limitRequestsPerPod: number) {
86 const Pod = db.Pod 85 const Pod = db.Pod
87 86
88 // We make a join between videos and authors to find the podId of our video event requests 87 // We make a join between videos and authors to find the podId of our video event requests
89 const podJoins = 'INNER JOIN "Videos" ON "Videos"."authorId" = "Authors"."id" ' + 88 const podJoins = 'INNER JOIN "Videos" ON "Videos"."authorId" = "Authors"."id" ' +
90 'INNER JOIN "RequestVideoEvents" ON "RequestVideoEvents"."videoId" = "Videos"."id"' 89 'INNER JOIN "RequestVideoEvents" ON "RequestVideoEvents"."videoId" = "Videos"."id"'
91 90
92 Pod.listRandomPodIdsWithRequest(limitPods, 'Authors', podJoins, function (err, podIds) { 91 return Pod.listRandomPodIdsWithRequest(limitPods, 'Authors', podJoins).then(podIds => {
93 if (err) return callback(err)
94
95 // We don't have friends that have requests 92 // We don't have friends that have requests
96 if (podIds.length === 0) return callback(null, []) 93 if (podIds.length === 0) return []
97 94
98 const query = { 95 const query = {
99 order: [ 96 order: [
@@ -121,16 +118,14 @@ listWithLimitAndRandom = function (limitPods: number, limitRequestsPerPod: numbe
121 ] 118 ]
122 } 119 }
123 120
124 RequestVideoEvent.findAll(query).asCallback(function (err, requests) { 121 return RequestVideoEvent.findAll(query).then(requests => {
125 if (err) return callback(err)
126
127 const requestsGrouped = groupAndTruncateRequests(requests, limitRequestsPerPod) 122 const requestsGrouped = groupAndTruncateRequests(requests, limitRequestsPerPod)
128 return callback(err, requestsGrouped) 123 return requestsGrouped
129 }) 124 })
130 }) 125 })
131} 126}
132 127
133removeByRequestIdsAndPod = function (ids: number[], podId: number, callback: RequestVideoEventMethods.RemoveByRequestIdsAndPodCallback) { 128removeByRequestIdsAndPod = function (ids: number[], podId: number) {
134 const query = { 129 const query = {
135 where: { 130 where: {
136 id: { 131 id: {
@@ -152,12 +147,12 @@ removeByRequestIdsAndPod = function (ids: number[], podId: number, callback: Req
152 ] 147 ]
153 } 148 }
154 149
155 RequestVideoEvent.destroy(query).asCallback(callback) 150 return RequestVideoEvent.destroy(query)
156} 151}
157 152
158removeAll = function (callback: RequestVideoEventMethods.RemoveAllCallback) { 153removeAll = function () {
159 // Delete all requests 154 // Delete all requests
160 RequestVideoEvent.truncate({ cascade: true }).asCallback(callback) 155 return RequestVideoEvent.truncate({ cascade: true })
161} 156}
162 157
163// --------------------------------------------------------------------------- 158// ---------------------------------------------------------------------------