aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/request/request-video-qadu.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/request/request-video-qadu.ts')
-rw-r--r--server/models/request/request-video-qadu.ts27
1 files changed, 11 insertions, 16 deletions
diff --git a/server/models/request/request-video-qadu.ts b/server/models/request/request-video-qadu.ts
index da62239f5..74e28f129 100644
--- a/server/models/request/request-video-qadu.ts
+++ b/server/models/request/request-video-qadu.ts
@@ -16,7 +16,6 @@ import { database as db } from '../../initializers/database'
16import { REQUEST_VIDEO_QADU_TYPES } from '../../initializers' 16import { REQUEST_VIDEO_QADU_TYPES } from '../../initializers'
17import { addMethodsToModel } from '../utils' 17import { addMethodsToModel } from '../utils'
18import { 18import {
19 RequestVideoQaduClass,
20 RequestVideoQaduInstance, 19 RequestVideoQaduInstance,
21 RequestVideoQaduAttributes, 20 RequestVideoQaduAttributes,
22 21
@@ -83,20 +82,18 @@ function associate (models) {
83 }) 82 })
84} 83}
85 84
86countTotalRequests = function (callback: RequestVideoQaduMethods.CountTotalRequestsCallback) { 85countTotalRequests = function () {
87 const query = {} 86 const query = {}
88 return RequestVideoQadu.count(query).asCallback(callback) 87 return RequestVideoQadu.count(query)
89} 88}
90 89
91listWithLimitAndRandom = function (limitPods: number, limitRequestsPerPod: number, callback: RequestVideoQaduMethods.ListWithLimitAndRandomCallback) { 90listWithLimitAndRandom = function (limitPods: number, limitRequestsPerPod: number) {
92 const Pod = db.Pod 91 const Pod = db.Pod
93 const tableJoin = '' 92 const tableJoin = ''
94 93
95 Pod.listRandomPodIdsWithRequest(limitPods, 'RequestVideoQadus', tableJoin, function (err, podIds) { 94 return Pod.listRandomPodIdsWithRequest(limitPods, 'RequestVideoQadus', tableJoin).then(podIds => {
96 if (err) return callback(err)
97
98 // We don't have friends that have requests 95 // We don't have friends that have requests
99 if (podIds.length === 0) return callback(null, []) 96 if (podIds.length === 0) return []
100 97
101 const query = { 98 const query = {
102 include: [ 99 include: [
@@ -114,16 +111,14 @@ listWithLimitAndRandom = function (limitPods: number, limitRequestsPerPod: numbe
114 ] 111 ]
115 } 112 }
116 113
117 RequestVideoQadu.findAll(query).asCallback(function (err, requests) { 114 return RequestVideoQadu.findAll(query).then(requests => {
118 if (err) return callback(err)
119
120 const requestsGrouped = groupAndTruncateRequests(requests, limitRequestsPerPod) 115 const requestsGrouped = groupAndTruncateRequests(requests, limitRequestsPerPod)
121 return callback(err, requestsGrouped) 116 return requestsGrouped
122 }) 117 })
123 }) 118 })
124} 119}
125 120
126removeByRequestIdsAndPod = function (ids: number[], podId: number, callback: RequestVideoQaduMethods.RemoveByRequestIdsAndPodCallback) { 121removeByRequestIdsAndPod = function (ids: number[], podId: number) {
127 const query = { 122 const query = {
128 where: { 123 where: {
129 id: { 124 id: {
@@ -133,12 +128,12 @@ removeByRequestIdsAndPod = function (ids: number[], podId: number, callback: Req
133 } 128 }
134 } 129 }
135 130
136 RequestVideoQadu.destroy(query).asCallback(callback) 131 return RequestVideoQadu.destroy(query)
137} 132}
138 133
139removeAll = function (callback: RequestVideoQaduMethods.RemoveAllCallback) { 134removeAll = function () {
140 // Delete all requests 135 // Delete all requests
141 RequestVideoQadu.truncate({ cascade: true }).asCallback(callback) 136 return RequestVideoQadu.truncate({ cascade: true })
142} 137}
143 138
144// --------------------------------------------------------------------------- 139// ---------------------------------------------------------------------------