aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/request.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-12-28 15:49:23 +0100
committerChocobozzz <florian.bigard@gmail.com>2016-12-28 15:49:23 +0100
commit67bf9b96bbcd92b069fe86d9223fe0f8b9c6e677 (patch)
treebae6a9b0c3133c9cc38a2972222b5991f0cf614e /server/models/request.js
parent552cc9d646e78edae8b0fe61564d4e49db0b6206 (diff)
downloadPeerTube-67bf9b96bbcd92b069fe86d9223fe0f8b9c6e677.tar.gz
PeerTube-67bf9b96bbcd92b069fe86d9223fe0f8b9c6e677.tar.zst
PeerTube-67bf9b96bbcd92b069fe86d9223fe0f8b9c6e677.zip
Server: add database field validations
Diffstat (limited to 'server/models/request.js')
-rw-r--r--server/models/request.js14
1 files changed, 8 insertions, 6 deletions
diff --git a/server/models/request.js b/server/models/request.js
index 70aa32610..e18f8fe3d 100644
--- a/server/models/request.js
+++ b/server/models/request.js
@@ -3,6 +3,7 @@
3const each = require('async/each') 3const each = require('async/each')
4const eachLimit = require('async/eachLimit') 4const eachLimit = require('async/eachLimit')
5const waterfall = require('async/waterfall') 5const waterfall = require('async/waterfall')
6const values = require('lodash/values')
6 7
7const constants = require('../initializers/constants') 8const constants = require('../initializers/constants')
8const logger = require('../helpers/logger') 9const logger = require('../helpers/logger')
@@ -17,11 +18,12 @@ module.exports = function (sequelize, DataTypes) {
17 const Request = sequelize.define('Request', 18 const Request = sequelize.define('Request',
18 { 19 {
19 request: { 20 request: {
20 type: DataTypes.JSON 21 type: DataTypes.JSON,
22 allowNull: false
21 }, 23 },
22 endpoint: { 24 endpoint: {
23 // TODO: enum? 25 type: DataTypes.ENUM(values(constants.REQUEST_ENDPOINTS)),
24 type: DataTypes.STRING 26 allowNull: false
25 } 27 }
26 }, 28 },
27 { 29 {
@@ -196,7 +198,7 @@ function makeRequests () {
196 198
197 makeRequest(toPod, requestToMake.endpoint, requestToMake.datas, function (success) { 199 makeRequest(toPod, requestToMake.endpoint, requestToMake.datas, function (success) {
198 if (success === true) { 200 if (success === true) {
199 logger.debug('Removing requests for %s pod.', requestToMake.toPodId, { requestsIds: requestToMake.ids }) 201 logger.debug('Removing requests for pod %s.', requestToMake.toPodId, { requestsIds: requestToMake.ids })
200 202
201 goodPods.push(requestToMake.toPodId) 203 goodPods.push(requestToMake.toPodId)
202 204
@@ -261,13 +263,13 @@ function updatePodsScore (goodPods, badPods) {
261 263
262 if (goodPods.length !== 0) { 264 if (goodPods.length !== 0) {
263 Pod.incrementScores(goodPods, constants.PODS_SCORE.BONUS, function (err) { 265 Pod.incrementScores(goodPods, constants.PODS_SCORE.BONUS, function (err) {
264 if (err) logger.error('Cannot increment scores of good pods.') 266 if (err) logger.error('Cannot increment scores of good pods.', { error: err })
265 }) 267 })
266 } 268 }
267 269
268 if (badPods.length !== 0) { 270 if (badPods.length !== 0) {
269 Pod.incrementScores(badPods, constants.PODS_SCORE.MALUS, function (err) { 271 Pod.incrementScores(badPods, constants.PODS_SCORE.MALUS, function (err) {
270 if (err) logger.error('Cannot decrement scores of bad pods.') 272 if (err) logger.error('Cannot decrement scores of bad pods.', { error: err })
271 removeBadPods.call(self) 273 removeBadPods.call(self)
272 }) 274 })
273 } 275 }