diff options
Diffstat (limited to 'models/pods.js')
-rw-r--r-- | models/pods.js | 88 |
1 files changed, 0 insertions, 88 deletions
diff --git a/models/pods.js b/models/pods.js deleted file mode 100644 index 57ed20292..000000000 --- a/models/pods.js +++ /dev/null | |||
@@ -1,88 +0,0 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | var mongoose = require('mongoose') | ||
4 | |||
5 | var constants = require('../initializers/constants') | ||
6 | var logger = require('../helpers/logger') | ||
7 | |||
8 | // --------------------------------------------------------------------------- | ||
9 | |||
10 | var podsSchema = mongoose.Schema({ | ||
11 | url: String, | ||
12 | publicKey: String, | ||
13 | score: { type: Number, max: constants.FRIEND_BASE_SCORE } | ||
14 | }) | ||
15 | var PodsDB = mongoose.model('pods', podsSchema) | ||
16 | |||
17 | // --------------------------------------------------------------------------- | ||
18 | |||
19 | var Pods = { | ||
20 | add: add, | ||
21 | count: count, | ||
22 | findByUrl: findByUrl, | ||
23 | findBadPods: findBadPods, | ||
24 | incrementScores: incrementScores, | ||
25 | list: list, | ||
26 | remove: remove, | ||
27 | removeAll: removeAll, | ||
28 | removeAllByIds: removeAllByIds | ||
29 | } | ||
30 | |||
31 | // TODO: check if the pod is not already a friend | ||
32 | function add (data, callback) { | ||
33 | if (!callback) callback = function () {} | ||
34 | var params = { | ||
35 | url: data.url, | ||
36 | publicKey: data.publicKey, | ||
37 | score: constants.FRIEND_BASE_SCORE | ||
38 | } | ||
39 | |||
40 | PodsDB.create(params, callback) | ||
41 | } | ||
42 | |||
43 | function count (callback) { | ||
44 | return PodsDB.count(callback) | ||
45 | } | ||
46 | |||
47 | function findBadPods (callback) { | ||
48 | PodsDB.find({ score: 0 }, callback) | ||
49 | } | ||
50 | |||
51 | function findByUrl (url, callback) { | ||
52 | PodsDB.findOne({ url: url }, callback) | ||
53 | } | ||
54 | |||
55 | function incrementScores (ids, value, callback) { | ||
56 | if (!callback) callback = function () {} | ||
57 | PodsDB.update({ _id: { $in: ids } }, { $inc: { score: value } }, { multi: true }, callback) | ||
58 | } | ||
59 | |||
60 | function list (callback) { | ||
61 | PodsDB.find(function (err, pods_list) { | ||
62 | if (err) { | ||
63 | logger.error('Cannot get the list of the pods.') | ||
64 | return callback(err) | ||
65 | } | ||
66 | |||
67 | return callback(null, pods_list) | ||
68 | }) | ||
69 | } | ||
70 | |||
71 | function remove (url, callback) { | ||
72 | if (!callback) callback = function () {} | ||
73 | PodsDB.remove({ url: url }, callback) | ||
74 | } | ||
75 | |||
76 | function removeAll (callback) { | ||
77 | if (!callback) callback = function () {} | ||
78 | PodsDB.remove(callback) | ||
79 | } | ||
80 | |||
81 | function removeAllByIds (ids, callback) { | ||
82 | if (!callback) callback = function () {} | ||
83 | PodsDB.remove({ _id: { $in: ids } }, callback) | ||
84 | } | ||
85 | |||
86 | // --------------------------------------------------------------------------- | ||
87 | |||
88 | module.exports = Pods | ||