aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-08-26 18:55:10 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-08-26 18:55:10 +0200
commit535724234aafd90c9eac17d9998f3f1c6c6c7615 (patch)
tree5b37a63037006abd60548877a00208fb97bb9fde /server/models
parentcc599f34b7a55adbc614898fe8fd63ecc38f5e7d (diff)
downloadPeerTube-535724234aafd90c9eac17d9998f3f1c6c6c7615.tar.gz
PeerTube-535724234aafd90c9eac17d9998f3f1c6c6c7615.tar.zst
PeerTube-535724234aafd90c9eac17d9998f3f1c6c6c7615.zip
Server: add pod created date and score to the list controller
Diffstat (limited to 'server/models')
-rw-r--r--server/models/pods.js28
1 files changed, 22 insertions, 6 deletions
diff --git a/server/models/pods.js b/server/models/pods.js
index bf43d7b25..59de2d60c 100644
--- a/server/models/pods.js
+++ b/server/models/pods.js
@@ -11,7 +11,11 @@ const constants = require('../initializers/constants')
11const PodSchema = mongoose.Schema({ 11const PodSchema = mongoose.Schema({
12 url: String, 12 url: String,
13 publicKey: String, 13 publicKey: String,
14 score: { type: Number, max: constants.FRIEND_SCORE.MAX } 14 score: { type: Number, max: constants.FRIEND_SCORE.MAX },
15 createdDate: {
16 type: Date,
17 default: Date.now
18 }
15}) 19})
16 20
17// TODO: set options (TLD...) 21// TODO: set options (TLD...)
@@ -19,12 +23,15 @@ PodSchema.path('url').validate(validator.isURL)
19PodSchema.path('publicKey').required(true) 23PodSchema.path('publicKey').required(true)
20PodSchema.path('score').validate(function (value) { return !isNaN(value) }) 24PodSchema.path('score').validate(function (value) { return !isNaN(value) })
21 25
26PodSchema.methods = {
27 toFormatedJSON: toFormatedJSON
28}
29
22PodSchema.statics = { 30PodSchema.statics = {
23 countAll: countAll, 31 countAll: countAll,
24 incrementScores: incrementScores, 32 incrementScores: incrementScores,
25 list: list, 33 list: list,
26 listAllIds: listAllIds, 34 listAllIds: listAllIds,
27 listOnlyUrls: listOnlyUrls,
28 listBadPods: listBadPods, 35 listBadPods: listBadPods,
29 load: load, 36 load: load,
30 loadByUrl: loadByUrl, 37 loadByUrl: loadByUrl,
@@ -46,6 +53,19 @@ PodSchema.pre('save', function (next) {
46 53
47const Pod = mongoose.model('Pod', PodSchema) 54const Pod = mongoose.model('Pod', PodSchema)
48 55
56// ------------------------------ METHODS ------------------------------
57
58function toFormatedJSON () {
59 const json = {
60 id: this._id,
61 url: this.url,
62 score: this.score,
63 createdDate: this.createdDate
64 }
65
66 return json
67}
68
49// ------------------------------ Statics ------------------------------ 69// ------------------------------ Statics ------------------------------
50 70
51function countAll (callback) { 71function countAll (callback) {
@@ -69,10 +89,6 @@ function listAllIds (callback) {
69 }) 89 })
70} 90}
71 91
72function listOnlyUrls (callback) {
73 return this.find({}, { _id: 0, url: 1 }, callback)
74}
75
76function listBadPods (callback) { 92function listBadPods (callback) {
77 return this.find({ score: 0 }, callback) 93 return this.find({ score: 0 }, callback)
78} 94}