]>
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')
7 // ---------------------------------------------------------------------------
9 module
.exports = function (sequelize
, DataTypes
) {
10 const Pod
= sequelize
.define('Pod',
13 type: DataTypes
.STRING
16 type: DataTypes
.STRING(5000)
19 type: DataTypes
.INTEGER
,
20 defaultValue: constants
.FRIEND_SCORE
.BASE
45 // TODO: max score -> constants.FRIENDS_SCORE.MAX
47 // PodSchema.path('host').validate(validator.isURL)
48 // PodSchema.path('publicKey').required(true)
49 // PodSchema.path('score').validate(function (value) { return !isNaN(value) })
51 // ------------------------------ METHODS ------------------------------
53 function toFormatedJSON () {
58 createdAt: this.createdAt
64 // ------------------------------ Statics ------------------------------
66 function associate (models
) {
67 this.belongsToMany(models
.Request
, {
69 through: models
.RequestToPod
,
74 function countAll (callback
) {
75 return this.count().asCallback(callback
)
78 function incrementScores (ids
, value
, callback
) {
79 if (!callback
) callback = function () {}
82 score: this.sequelize
.literal('score +' + value
)
93 return this.update(update
, query
).asCallback(callback
)
96 function list (callback
) {
97 return this.findAll().asCallback(callback
)
100 function listAllIds (callback
) {
105 return this.findAll(query
).asCallback(function (err
, pods
) {
106 if (err
) return callback(err
)
108 return callback(null, map(pods
, 'id'))
112 function listBadPods (callback
) {
119 return this.findAll(query
).asCallback(callback
)
122 function load (id
, callback
) {
123 return this.findById(id
).asCallback(callback
)
126 function loadByHost (host
, callback
) {
133 return this.findOne(query
).asCallback(callback
)
136 function removeAll (callback
) {
137 return this.destroy().asCallback(callback
)