]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/models/pods.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
46 // TODO: max score -> constants.FRIENDS_SCORE.MAX
48 // PodSchema.path('host').validate(validator.isURL)
49 // PodSchema.path('publicKey').required(true)
50 // PodSchema.path('score').validate(function (value) { return !isNaN(value) })
52 // ------------------------------ METHODS ------------------------------
54 function toFormatedJSON () {
59 createdAt: this.createdAt
65 // ------------------------------ Statics ------------------------------
67 function associate (models
) {
68 this.belongsToMany(models
.Request
, {
70 through: models
.RequestToPod
,
75 function countAll (callback
) {
76 return this.count().asCallback(callback
)
79 function incrementScores (ids
, value
, callback
) {
80 if (!callback
) callback = function () {}
83 score: this.sequelize
.literal('score +' + value
)
94 return this.update(update
, query
).asCallback(callback
)
97 function list (callback
) {
98 return this.findAll().asCallback(callback
)
101 function listAllIds (callback
) {
106 return this.findAll(query
).asCallback(function (err
, pods
) {
107 if (err
) return callback(err
)
109 return callback(null, map(pods
, 'id'))
113 function listBadPods (callback
) {
120 return this.findAll(query
).asCallback(callback
)
123 function load (id
, callback
) {
124 return this.findById(id
).asCallback(callback
)
127 function loadByHost (host
, callback
) {
134 return this.findOne(query
).asCallback(callback
)
137 function removeAll (callback
) {
138 return this.destroy().asCallback(callback
)