diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-06-10 22:15:25 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-06-10 22:15:25 +0200 |
commit | 69818c9394366b954b6ba3bd697bd9d2b09f2a16 (patch) | |
tree | ad199a18ec3c322460d6f9523fc383ee562554e0 /server/models/pod.ts | |
parent | 4d4e5cd4dca78480ec7f40e747f424cd107376a4 (diff) | |
download | PeerTube-69818c9394366b954b6ba3bd697bd9d2b09f2a16.tar.gz PeerTube-69818c9394366b954b6ba3bd697bd9d2b09f2a16.tar.zst PeerTube-69818c9394366b954b6ba3bd697bd9d2b09f2a16.zip |
Type functions
Diffstat (limited to 'server/models/pod.ts')
-rw-r--r-- | server/models/pod.ts | 34 |
1 files changed, 12 insertions, 22 deletions
diff --git a/server/models/pod.ts b/server/models/pod.ts index 2df32e4a4..107744c43 100644 --- a/server/models/pod.ts +++ b/server/models/pod.ts | |||
@@ -118,11 +118,11 @@ function associate (models) { | |||
118 | }) | 118 | }) |
119 | } | 119 | } |
120 | 120 | ||
121 | countAll = function (callback) { | 121 | countAll = function (callback: PodMethods.CountAllCallback) { |
122 | return Pod.count().asCallback(callback) | 122 | return Pod.count().asCallback(callback) |
123 | } | 123 | } |
124 | 124 | ||
125 | incrementScores = function (ids, value, callback) { | 125 | incrementScores = function (ids: number[], value: number, callback?: PodMethods.IncrementScoresCallback) { |
126 | if (!callback) callback = function () { /* empty */ } | 126 | if (!callback) callback = function () { /* empty */ } |
127 | 127 | ||
128 | const update = { | 128 | const update = { |
@@ -142,35 +142,25 @@ incrementScores = function (ids, value, callback) { | |||
142 | return Pod.update(update, options).asCallback(callback) | 142 | return Pod.update(update, options).asCallback(callback) |
143 | } | 143 | } |
144 | 144 | ||
145 | list = function (callback) { | 145 | list = function (callback: PodMethods.ListCallback) { |
146 | return Pod.findAll().asCallback(callback) | 146 | return Pod.findAll().asCallback(callback) |
147 | } | 147 | } |
148 | 148 | ||
149 | listAllIds = function (transaction, callback) { | 149 | listAllIds = function (transaction: Sequelize.Transaction, callback: PodMethods.ListAllIdsCallback) { |
150 | if (!callback) { | ||
151 | callback = transaction | ||
152 | transaction = null | ||
153 | } | ||
154 | |||
155 | const query: any = { | 150 | const query: any = { |
156 | attributes: [ 'id' ] | 151 | attributes: [ 'id' ] |
157 | } | 152 | } |
158 | 153 | ||
159 | if (transaction) query.transaction = transaction | 154 | if (transaction !== null) query.transaction = transaction |
160 | 155 | ||
161 | return Pod.findAll(query).asCallback(function (err, pods) { | 156 | return Pod.findAll(query).asCallback(function (err: Error, pods) { |
162 | if (err) return callback(err) | 157 | if (err) return callback(err) |
163 | 158 | ||
164 | return callback(null, map(pods, 'id')) | 159 | return callback(null, map(pods, 'id')) |
165 | }) | 160 | }) |
166 | } | 161 | } |
167 | 162 | ||
168 | listRandomPodIdsWithRequest = function (limit, tableWithPods, tableWithPodsJoins, callback) { | 163 | listRandomPodIdsWithRequest = function (limit: number, tableWithPods: string, tableWithPodsJoins: string, callback: PodMethods.ListRandomPodIdsWithRequestCallback) { |
169 | if (!callback) { | ||
170 | callback = tableWithPodsJoins | ||
171 | tableWithPodsJoins = '' | ||
172 | } | ||
173 | |||
174 | Pod.count().asCallback(function (err, count) { | 164 | Pod.count().asCallback(function (err, count) { |
175 | if (err) return callback(err) | 165 | if (err) return callback(err) |
176 | 166 | ||
@@ -204,7 +194,7 @@ listRandomPodIdsWithRequest = function (limit, tableWithPods, tableWithPodsJoins | |||
204 | }) | 194 | }) |
205 | } | 195 | } |
206 | 196 | ||
207 | listBadPods = function (callback) { | 197 | listBadPods = function (callback: PodMethods.ListBadPodsCallback) { |
208 | const query = { | 198 | const query = { |
209 | where: { | 199 | where: { |
210 | score: { $lte: 0 } | 200 | score: { $lte: 0 } |
@@ -214,11 +204,11 @@ listBadPods = function (callback) { | |||
214 | return Pod.findAll(query).asCallback(callback) | 204 | return Pod.findAll(query).asCallback(callback) |
215 | } | 205 | } |
216 | 206 | ||
217 | load = function (id, callback) { | 207 | load = function (id: number, callback: PodMethods.LoadCallback) { |
218 | return Pod.findById(id).asCallback(callback) | 208 | return Pod.findById(id).asCallback(callback) |
219 | } | 209 | } |
220 | 210 | ||
221 | loadByHost = function (host, callback) { | 211 | loadByHost = function (host: string, callback: PodMethods.LoadByHostCallback) { |
222 | const query = { | 212 | const query = { |
223 | where: { | 213 | where: { |
224 | host: host | 214 | host: host |
@@ -228,11 +218,11 @@ loadByHost = function (host, callback) { | |||
228 | return Pod.findOne(query).asCallback(callback) | 218 | return Pod.findOne(query).asCallback(callback) |
229 | } | 219 | } |
230 | 220 | ||
231 | removeAll = function (callback) { | 221 | removeAll = function (callback: PodMethods.RemoveAllCallback) { |
232 | return Pod.destroy().asCallback(callback) | 222 | return Pod.destroy().asCallback(callback) |
233 | } | 223 | } |
234 | 224 | ||
235 | updatePodsScore = function (goodPods, badPods) { | 225 | updatePodsScore = function (goodPods: number[], badPods: number[]) { |
236 | logger.info('Updating %d good pods and %d bad pods scores.', goodPods.length, badPods.length) | 226 | logger.info('Updating %d good pods and %d bad pods scores.', goodPods.length, badPods.length) |
237 | 227 | ||
238 | if (goodPods.length !== 0) { | 228 | if (goodPods.length !== 0) { |