]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/models/pod.js
3 const map
= require('lodash/map')
5 const constants
= require('../initializers/constants')
6 const customPodsValidators
= require('../helpers/custom-validators').pods
8 // ---------------------------------------------------------------------------
10 module
.exports = function (sequelize
, DataTypes
) {
11 const Pod
= sequelize
.define('Pod',
14 type: DataTypes
.STRING
,
17 isHost: function (value
) {
18 const res
= customPodsValidators
.isHostValid(value
)
19 if (res
=== false) throw new Error('Host not valid.')
24 type: DataTypes
.STRING(5000),
28 type: DataTypes
.INTEGER
,
29 defaultValue: constants
.FRIEND_SCORE
.BASE
,
33 max: constants
.FRIEND_SCORE
.MAX
59 // ------------------------------ METHODS ------------------------------
61 function toFormatedJSON () {
66 createdAt: this.createdAt
72 // ------------------------------ Statics ------------------------------
74 function associate (models
) {
75 this.belongsToMany(models
.Request
, {
77 through: models
.RequestToPod
,
82 function countAll (callback
) {
83 return this.count().asCallback(callback
)
86 function incrementScores (ids
, value
, callback
) {
87 if (!callback
) callback = function () {}
90 score: this.sequelize
.literal('score +' + value
)
99 // In this case score is a literal and not an integer so we do not validate it
103 return this.update(update
, options
).asCallback(callback
)
106 function list (callback
) {
107 return this.findAll().asCallback(callback
)
110 function listAllIds (callback
) {
115 return this.findAll(query
).asCallback(function (err
, pods
) {
116 if (err
) return callback(err
)
118 return callback(null, map(pods
, 'id'))
122 function listBadPods (callback
) {
129 return this.findAll(query
).asCallback(callback
)
132 function load (id
, callback
) {
133 return this.findById(id
).asCallback(callback
)
136 function loadByHost (host
, callback
) {
143 return this.findOne(query
).asCallback(callback
)
146 function removeAll (callback
) {
147 return this.destroy().asCallback(callback
)