'use strict'
const mongoose = require('mongoose')
+const map = require('lodash/map')
const constants = require('../initializers/constants')
const logger = require('../helpers/logger')
const Pods = {
add: add,
count: count,
+ findById: findById,
findByUrl: findByUrl,
findBadPods: findBadPods,
incrementScores: incrementScores,
list: list,
+ listAllIds: listAllIds,
+ listAllUrls: listAllUrls,
remove: remove,
removeAll: removeAll,
removeAllByIds: removeAllByIds
PodsDB.find({ score: 0 }, callback)
}
+function findById (id, callback) {
+ PodsDB.findById(id, callback)
+}
+
function findByUrl (url, callback) {
PodsDB.findOne({ url: url }, callback)
}
}
function list (callback) {
- PodsDB.find(function (err, pods_list) {
+ PodsDB.find(function (err, podsList) {
if (err) {
logger.error('Cannot get the list of the pods.')
return callback(err)
}
- return callback(null, pods_list)
+ return callback(null, podsList)
+ })
+}
+
+function listAllIds (callback) {
+ return PodsDB.find({}, { _id: 1 }, function (err, pods) {
+ if (err) return callback(err)
+
+ return callback(null, map(pods, '_id'))
})
}
+function listAllUrls (callback) {
+ return PodsDB.find({}, { _id: 0, url: 1 }, callback)
+}
+
function remove (url, callback) {
if (!callback) callback = function () {}
PodsDB.remove({ url: url }, callback)