aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/request.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-06-10 22:15:25 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-06-10 22:15:25 +0200
commit69818c9394366b954b6ba3bd697bd9d2b09f2a16 (patch)
treead199a18ec3c322460d6f9523fc383ee562554e0 /server/models/request.ts
parent4d4e5cd4dca78480ec7f40e747f424cd107376a4 (diff)
downloadPeerTube-69818c9394366b954b6ba3bd697bd9d2b09f2a16.tar.gz
PeerTube-69818c9394366b954b6ba3bd697bd9d2b09f2a16.tar.zst
PeerTube-69818c9394366b954b6ba3bd697bd9d2b09f2a16.zip
Type functions
Diffstat (limited to 'server/models/request.ts')
-rw-r--r--server/models/request.ts22
1 files changed, 12 insertions, 10 deletions
diff --git a/server/models/request.ts b/server/models/request.ts
index 18fa291fa..71f81ae66 100644
--- a/server/models/request.ts
+++ b/server/models/request.ts
@@ -1,15 +1,16 @@
1import { values } from 'lodash' 1import { values } from 'lodash'
2import * as Sequelize from 'sequelize' 2import * as Sequelize from 'sequelize'
3 3
4import { database as db } from '../initializers/database'
4import { REQUEST_ENDPOINTS } from '../initializers' 5import { REQUEST_ENDPOINTS } from '../initializers'
5
6import { addMethodsToModel } from './utils' 6import { addMethodsToModel } from './utils'
7import { 7import {
8 RequestClass, 8 RequestClass,
9 RequestInstance, 9 RequestInstance,
10 RequestAttributes, 10 RequestAttributes,
11 11
12 RequestMethods 12 RequestMethods,
13 RequestsGrouped
13} from './request-interface' 14} from './request-interface'
14 15
15let Request: Sequelize.Model<RequestInstance, RequestAttributes> 16let Request: Sequelize.Model<RequestInstance, RequestAttributes>
@@ -59,7 +60,7 @@ function associate (models) {
59 }) 60 })
60} 61}
61 62
62countTotalRequests = function (callback) { 63countTotalRequests = function (callback: RequestMethods.CountTotalRequestsCallback) {
63 // We need to include Pod because there are no cascade delete when a pod is removed 64 // We need to include Pod because there are no cascade delete when a pod is removed
64 // So we could count requests that do not have existing pod anymore 65 // So we could count requests that do not have existing pod anymore
65 const query = { 66 const query = {
@@ -69,10 +70,11 @@ countTotalRequests = function (callback) {
69 return Request.count(query).asCallback(callback) 70 return Request.count(query).asCallback(callback)
70} 71}
71 72
72listWithLimitAndRandom = function (limitPods, limitRequestsPerPod, callback) { 73listWithLimitAndRandom = function (limitPods: number, limitRequestsPerPod: number, callback: RequestMethods.ListWithLimitAndRandomCallback) {
73 const Pod = Request['sequelize'].models.Pod 74 const Pod = db.Pod
75 const tableJoin = ''
74 76
75 Pod.listRandomPodIdsWithRequest(limitPods, 'RequestToPods', function (err, podIds) { 77 Pod.listRandomPodIdsWithRequest(limitPods, 'RequestToPods', '', function (err, podIds) {
76 if (err) return callback(err) 78 if (err) return callback(err)
77 79
78 // We don't have friends that have requests 80 // We don't have friends that have requests
@@ -105,12 +107,12 @@ listWithLimitAndRandom = function (limitPods, limitRequestsPerPod, callback) {
105 }) 107 })
106} 108}
107 109
108removeAll = function (callback) { 110removeAll = function (callback: RequestMethods.RemoveAllCallback) {
109 // Delete all requests 111 // Delete all requests
110 Request.truncate({ cascade: true }).asCallback(callback) 112 Request.truncate({ cascade: true }).asCallback(callback)
111} 113}
112 114
113removeWithEmptyTo = function (callback) { 115removeWithEmptyTo = function (callback?: RequestMethods.RemoveWithEmptyToCallback) {
114 if (!callback) callback = function () { /* empty */ } 116 if (!callback) callback = function () { /* empty */ }
115 117
116 const query = { 118 const query = {
@@ -128,8 +130,8 @@ removeWithEmptyTo = function (callback) {
128 130
129// --------------------------------------------------------------------------- 131// ---------------------------------------------------------------------------
130 132
131function groupAndTruncateRequests (requests, limitRequestsPerPod) { 133function groupAndTruncateRequests (requests: RequestInstance[], limitRequestsPerPod: number) {
132 const requestsGrouped = {} 134 const requestsGrouped: RequestsGrouped = {}
133 135
134 requests.forEach(function (request) { 136 requests.forEach(function (request) {
135 request.Pods.forEach(function (pod) { 137 request.Pods.forEach(function (pod) {