From 535724234aafd90c9eac17d9998f3f1c6c6c7615 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 26 Aug 2016 18:55:10 +0200 Subject: Server: add pod created date and score to the list controller --- server/models/pods.js | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'server/models/pods.js') 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') const PodSchema = mongoose.Schema({ url: String, publicKey: String, - score: { type: Number, max: constants.FRIEND_SCORE.MAX } + score: { type: Number, max: constants.FRIEND_SCORE.MAX }, + createdDate: { + type: Date, + default: Date.now + } }) // TODO: set options (TLD...) @@ -19,12 +23,15 @@ PodSchema.path('url').validate(validator.isURL) PodSchema.path('publicKey').required(true) PodSchema.path('score').validate(function (value) { return !isNaN(value) }) +PodSchema.methods = { + toFormatedJSON: toFormatedJSON +} + PodSchema.statics = { countAll: countAll, incrementScores: incrementScores, list: list, listAllIds: listAllIds, - listOnlyUrls: listOnlyUrls, listBadPods: listBadPods, load: load, loadByUrl: loadByUrl, @@ -46,6 +53,19 @@ PodSchema.pre('save', function (next) { const Pod = mongoose.model('Pod', PodSchema) +// ------------------------------ METHODS ------------------------------ + +function toFormatedJSON () { + const json = { + id: this._id, + url: this.url, + score: this.score, + createdDate: this.createdDate + } + + return json +} + // ------------------------------ Statics ------------------------------ function countAll (callback) { @@ -69,10 +89,6 @@ function listAllIds (callback) { }) } -function listOnlyUrls (callback) { - return this.find({}, { _id: 0, url: 1 }, callback) -} - function listBadPods (callback) { return this.find({ score: 0 }, callback) } -- cgit v1.2.3 From c4403b29ad4db097af528a7f04eea07e0ed320d0 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Sun, 2 Oct 2016 12:19:02 +0200 Subject: Server: remove useless hash affectations --- server/models/pods.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'server/models/pods.js') diff --git a/server/models/pods.js b/server/models/pods.js index 59de2d60c..4020a9603 100644 --- a/server/models/pods.js +++ b/server/models/pods.js @@ -24,18 +24,18 @@ PodSchema.path('publicKey').required(true) PodSchema.path('score').validate(function (value) { return !isNaN(value) }) PodSchema.methods = { - toFormatedJSON: toFormatedJSON + toFormatedJSON } PodSchema.statics = { - countAll: countAll, - incrementScores: incrementScores, - list: list, - listAllIds: listAllIds, - listBadPods: listBadPods, - load: load, - loadByUrl: loadByUrl, - removeAll: removeAll + countAll, + incrementScores, + list, + listAllIds, + listBadPods, + load, + loadByUrl, + removeAll } PodSchema.pre('save', function (next) { -- cgit v1.2.3