-'use strict'
+import { each, waterfall } from 'async'
+import { map } from 'lodash'
-const each = require('async/each')
-const map = require('lodash/map')
-const waterfall = require('async/waterfall')
-
-const constants = require('../initializers/constants')
-const logger = require('../helpers/logger')
-const customPodsValidators = require('../helpers/custom-validators').pods
+import { FRIEND_SCORE, PODS_SCORE } from '../initializers'
+import { logger, isHostValid } from '../helpers'
// ---------------------------------------------------------------------------
allowNull: false,
validate: {
isHost: function (value) {
- const res = customPodsValidators.isHostValid(value)
+ const res = isHostValid(value)
if (res === false) throw new Error('Host not valid.')
}
}
},
score: {
type: DataTypes.INTEGER,
- defaultValue: constants.FRIEND_SCORE.BASE,
+ defaultValue: FRIEND_SCORE.BASE,
allowNull: false,
validate: {
isInt: true,
- max: constants.FRIEND_SCORE.MAX
+ max: FRIEND_SCORE.MAX
}
},
email: {
}
function incrementScores (ids, value, callback) {
- if (!callback) callback = function () {}
+ if (!callback) callback = function () { /* empty */ }
const update = {
score: this.sequelize.literal('score +' + value)
transaction = null
}
- const query = {
+ const query: any = {
attributes: [ 'id' ]
}
logger.info('Updating %d good pods and %d bad pods scores.', goodPods.length, badPods.length)
if (goodPods.length !== 0) {
- this.incrementScores(goodPods, constants.PODS_SCORE.BONUS, function (err) {
+ this.incrementScores(goodPods, PODS_SCORE.BONUS, function (err) {
if (err) logger.error('Cannot increment scores of good pods.', { error: err })
})
}
if (badPods.length !== 0) {
- this.incrementScores(badPods, constants.PODS_SCORE.MALUS, function (err) {
+ this.incrementScores(badPods, PODS_SCORE.MALUS, function (err) {
if (err) logger.error('Cannot decrement scores of bad pods.', { error: err })
removeBadPods.call(self)
})
},
function removeTheseBadPods (pods, callback) {
- each(pods, function (pod, callbackEach) {
+ each(pods, function (pod: any, callbackEach) {
pod.destroy().asCallback(callbackEach)
}, function (err) {
return callback(err, pods.length)