aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/request/request-video-event.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-07-05 13:26:25 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-07-05 14:14:16 +0200
commit6fcd19ba737f1f5614a56c6925adb882dea43b8d (patch)
tree3365a96d82bc7f00ae504a568725c8e914150cf8 /server/models/request/request-video-event.ts
parent5fe7e898316e18369c3e1aba307b55077adc7bfb (diff)
downloadPeerTube-6fcd19ba737f1f5614a56c6925adb882dea43b8d.tar.gz
PeerTube-6fcd19ba737f1f5614a56c6925adb882dea43b8d.tar.zst
PeerTube-6fcd19ba737f1f5614a56c6925adb882dea43b8d.zip
Move to promises
Closes https://github.com/Chocobozzz/PeerTube/issues/74
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// ---------------------------------------------------------------------------