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...)
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,
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) {
})
}
-function listOnlyUrls (callback) {
- return this.find({}, { _id: 0, url: 1 }, callback)
-}
-
function listBadPods (callback) {
return this.find({ score: 0 }, callback)
}