]>
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
67 // ------------------------------ METHODS ------------------------------
69 function toFormatedJSON () {
74 createdAt: this.createdAt
80 // ------------------------------ Statics ------------------------------
82 function associate (models
) {
83 this.belongsToMany(models
.Request
, {
85 through: models
.RequestToPod
,
90 function countAll (callback
) {
91 return this.count().asCallback(callback
)
94 function incrementScores (ids
, value
, callback
) {
95 if (!callback
) callback = function () {}
98 score: this.sequelize
.literal('score +' + value
)
107 // In this case score is a literal and not an integer so we do not validate it
111 return this.update(update
, options
).asCallback(callback
)
114 function list (callback
) {
115 return this.findAll().asCallback(callback
)
118 function listAllIds (callback
) {
123 return this.findAll(query
).asCallback(function (err
, pods
) {
124 if (err
) return callback(err
)
126 return callback(null, map(pods
, 'id'))
130 function listBadPods (callback
) {
137 return this.findAll(query
).asCallback(callback
)
140 function load (id
, callback
) {
141 return this.findById(id
).asCallback(callback
)
144 function loadByHost (host
, callback
) {
151 return this.findOne(query
).asCallback(callback
)
154 function removeAll (callback
) {
155 return this.destroy().asCallback(callback
)