diff options
Diffstat (limited to 'server/models/pods.js')
-rw-r--r-- | server/models/pods.js | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/server/models/pods.js b/server/models/pods.js index bf43d7b25..4020a9603 100644 --- a/server/models/pods.js +++ b/server/models/pods.js | |||
@@ -11,7 +11,11 @@ const constants = require('../initializers/constants') | |||
11 | const PodSchema = mongoose.Schema({ | 11 | const 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,16 +23,19 @@ PodSchema.path('url').validate(validator.isURL) | |||
19 | PodSchema.path('publicKey').required(true) | 23 | PodSchema.path('publicKey').required(true) |
20 | PodSchema.path('score').validate(function (value) { return !isNaN(value) }) | 24 | PodSchema.path('score').validate(function (value) { return !isNaN(value) }) |
21 | 25 | ||
26 | PodSchema.methods = { | ||
27 | toFormatedJSON | ||
28 | } | ||
29 | |||
22 | PodSchema.statics = { | 30 | PodSchema.statics = { |
23 | countAll: countAll, | 31 | countAll, |
24 | incrementScores: incrementScores, | 32 | incrementScores, |
25 | list: list, | 33 | list, |
26 | listAllIds: listAllIds, | 34 | listAllIds, |
27 | listOnlyUrls: listOnlyUrls, | 35 | listBadPods, |
28 | listBadPods: listBadPods, | 36 | load, |
29 | load: load, | 37 | loadByUrl, |
30 | loadByUrl: loadByUrl, | 38 | removeAll |
31 | removeAll: removeAll | ||
32 | } | 39 | } |
33 | 40 | ||
34 | PodSchema.pre('save', function (next) { | 41 | PodSchema.pre('save', function (next) { |
@@ -46,6 +53,19 @@ PodSchema.pre('save', function (next) { | |||
46 | 53 | ||
47 | const Pod = mongoose.model('Pod', PodSchema) | 54 | const Pod = mongoose.model('Pod', PodSchema) |
48 | 55 | ||
56 | // ------------------------------ METHODS ------------------------------ | ||
57 | |||
58 | function 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 | ||
51 | function countAll (callback) { | 71 | function countAll (callback) { |
@@ -69,10 +89,6 @@ function listAllIds (callback) { | |||
69 | }) | 89 | }) |
70 | } | 90 | } |
71 | 91 | ||
72 | function listOnlyUrls (callback) { | ||
73 | return this.find({}, { _id: 0, url: 1 }, callback) | ||
74 | } | ||
75 | |||
76 | function listBadPods (callback) { | 92 | function listBadPods (callback) { |
77 | return this.find({ score: 0 }, callback) | 93 | return this.find({ score: 0 }, callback) |
78 | } | 94 | } |