diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-07-05 13:26:25 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-07-05 14:14:16 +0200 |
commit | 6fcd19ba737f1f5614a56c6925adb882dea43b8d (patch) | |
tree | 3365a96d82bc7f00ae504a568725c8e914150cf8 /server/models/request/request-video-qadu.ts | |
parent | 5fe7e898316e18369c3e1aba307b55077adc7bfb (diff) | |
download | PeerTube-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-qadu.ts')
-rw-r--r-- | server/models/request/request-video-qadu.ts | 27 |
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' | |||
16 | import { REQUEST_VIDEO_QADU_TYPES } from '../../initializers' | 16 | import { REQUEST_VIDEO_QADU_TYPES } from '../../initializers' |
17 | import { addMethodsToModel } from '../utils' | 17 | import { addMethodsToModel } from '../utils' |
18 | import { | 18 | import { |
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 | ||
86 | countTotalRequests = function (callback: RequestVideoQaduMethods.CountTotalRequestsCallback) { | 85 | countTotalRequests = function () { |
87 | const query = {} | 86 | const query = {} |
88 | return RequestVideoQadu.count(query).asCallback(callback) | 87 | return RequestVideoQadu.count(query) |
89 | } | 88 | } |
90 | 89 | ||
91 | listWithLimitAndRandom = function (limitPods: number, limitRequestsPerPod: number, callback: RequestVideoQaduMethods.ListWithLimitAndRandomCallback) { | 90 | listWithLimitAndRandom = 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 | ||
126 | removeByRequestIdsAndPod = function (ids: number[], podId: number, callback: RequestVideoQaduMethods.RemoveByRequestIdsAndPodCallback) { | 121 | removeByRequestIdsAndPod = 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 | ||
139 | removeAll = function (callback: RequestVideoQaduMethods.RemoveAllCallback) { | 134 | removeAll = 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 | // --------------------------------------------------------------------------- |