const Pod = mongoose.model('Pod')
const Video = mongoose.model('Video')
-router.get('/', listPodsUrl)
+router.get('/', listPods)
router.post('/', validators.podsAdd, addPods)
router.post('/makefriends',
oAuth.authenticate,
})
}
-function listPodsUrl (req, res, next) {
- Pod.listOnlyUrls(function (err, podsUrlList) {
+function listPods (req, res, next) {
+ Pod.list(function (err, podsUrlList) {
if (err) return next(err)
- res.json(podsUrlList)
+ res.json(getFormatedPods(podsUrlList))
})
}
res.type('json').status(204).end()
})
}
+
+// ---------------------------------------------------------------------------
+
+function getFormatedPods (pods) {
+ const formatedPods = []
+
+ pods.forEach(function (pod) {
+ formatedPods.push(pod.toFormatedJSON())
+ })
+
+ return formatedPods
+}
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)
}
const series = require('async/series')
const loginUtils = require('../utils/login')
+const miscsUtils = require('../utils/miscs')
const podsUtils = require('../utils/pods')
const serversUtils = require('../utils/servers')
const result = res.body
expect(result).to.be.an('array')
expect(result.length).to.equal(1)
- expect(result[0].url).to.be.equal(servers[2].url)
+
+ const pod = result[0]
+ expect(pod.url).to.equal(servers[2].url)
+ expect(pod.score).to.equal(20)
+ expect(miscsUtils.dateIsValid(pod.createdDate)).to.be.true
next()
})
const result = res.body
expect(result).to.be.an('array')
expect(result.length).to.equal(1)
- expect(result[0].url).to.be.equal(servers[1].url)
+
+ const pod = result[0]
+ expect(pod.url).to.equal(servers[1].url)
+ expect(pod.score).to.equal(20)
+ expect(miscsUtils.dateIsValid(pod.createdDate)).to.be.true
next()
})