diff options
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/pods.js | 28 |
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') | |||
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,12 +23,15 @@ 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: toFormatedJSON | ||
28 | } | ||
29 | |||
22 | PodSchema.statics = { | 30 | PodSchema.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 | ||
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 | } |