diff options
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/pods.js | 15 | ||||
-rw-r--r-- | server/models/requests.js | 32 |
2 files changed, 40 insertions, 7 deletions
diff --git a/server/models/pods.js b/server/models/pods.js index 04cc2d6fc..daeadeb07 100644 --- a/server/models/pods.js +++ b/server/models/pods.js | |||
@@ -19,10 +19,13 @@ const PodsDB = mongoose.model('pods', podsSchema) | |||
19 | const Pods = { | 19 | const Pods = { |
20 | add: add, | 20 | add: add, |
21 | count: count, | 21 | count: count, |
22 | findById: findById, | ||
22 | findByUrl: findByUrl, | 23 | findByUrl: findByUrl, |
23 | findBadPods: findBadPods, | 24 | findBadPods: findBadPods, |
24 | incrementScores: incrementScores, | 25 | incrementScores: incrementScores, |
25 | list: list, | 26 | list: list, |
27 | listAllIds: listAllIds, | ||
28 | listAllUrls: listAllUrls, | ||
26 | remove: remove, | 29 | remove: remove, |
27 | removeAll: removeAll, | 30 | removeAll: removeAll, |
28 | removeAllByIds: removeAllByIds | 31 | removeAllByIds: removeAllByIds |
@@ -48,6 +51,10 @@ function findBadPods (callback) { | |||
48 | PodsDB.find({ score: 0 }, callback) | 51 | PodsDB.find({ score: 0 }, callback) |
49 | } | 52 | } |
50 | 53 | ||
54 | function findById (id, callback) { | ||
55 | PodsDB.findById(id, callback) | ||
56 | } | ||
57 | |||
51 | function findByUrl (url, callback) { | 58 | function findByUrl (url, callback) { |
52 | PodsDB.findOne({ url: url }, callback) | 59 | PodsDB.findOne({ url: url }, callback) |
53 | } | 60 | } |
@@ -68,6 +75,14 @@ function list (callback) { | |||
68 | }) | 75 | }) |
69 | } | 76 | } |
70 | 77 | ||
78 | function listAllIds (callback) { | ||
79 | return PodsDB.find({}, { _id: 1 }, callback) | ||
80 | } | ||
81 | |||
82 | function listAllUrls (callback) { | ||
83 | return PodsDB.find({}, { _id: 0, url: 1 }, callback) | ||
84 | } | ||
85 | |||
71 | function remove (url, callback) { | 86 | function remove (url, callback) { |
72 | if (!callback) callback = function () {} | 87 | if (!callback) callback = function () {} |
73 | PodsDB.remove({ url: url }, callback) | 88 | PodsDB.remove({ url: url }, callback) |
diff --git a/server/models/requests.js b/server/models/requests.js index 2152ae0e9..e67ccad56 100644 --- a/server/models/requests.js +++ b/server/models/requests.js | |||
@@ -7,9 +7,8 @@ const logger = require('../helpers/logger') | |||
7 | // --------------------------------------------------------------------------- | 7 | // --------------------------------------------------------------------------- |
8 | 8 | ||
9 | const requestsSchema = mongoose.Schema({ | 9 | const requestsSchema = mongoose.Schema({ |
10 | type: String, | 10 | request: mongoose.Schema.Types.Mixed, |
11 | id: String, // Special id to find duplicates (video created we want to remove...) | 11 | to: [ { type: mongoose.Schema.Types.ObjectId, ref: 'users' } ] |
12 | request: mongoose.Schema.Types.Mixed | ||
13 | }) | 12 | }) |
14 | const RequestsDB = mongoose.model('requests', requestsSchema) | 13 | const RequestsDB = mongoose.model('requests', requestsSchema) |
15 | 14 | ||
@@ -19,12 +18,15 @@ const Requests = { | |||
19 | create: create, | 18 | create: create, |
20 | findById: findById, | 19 | findById: findById, |
21 | list: list, | 20 | list: list, |
21 | removeAll: removeAll, | ||
22 | removePodOf: removePodOf, | ||
22 | removeRequestById: removeRequestById, | 23 | removeRequestById: removeRequestById, |
23 | removeRequests: removeRequests | 24 | removeRequests: removeRequests, |
25 | removeWithEmptyTo: removeWithEmptyTo | ||
24 | } | 26 | } |
25 | 27 | ||
26 | function create (id, type, request, callback) { | 28 | function create (request, to, callback) { |
27 | RequestsDB.create({ id: id, type: type, request: request }, callback) | 29 | RequestsDB.create({ request: request, to: to }, callback) |
28 | } | 30 | } |
29 | 31 | ||
30 | function findById (id, callback) { | 32 | function findById (id, callback) { |
@@ -32,7 +34,17 @@ function findById (id, callback) { | |||
32 | } | 34 | } |
33 | 35 | ||
34 | function list (callback) { | 36 | function list (callback) { |
35 | RequestsDB.find({}, { _id: 1, type: 1, request: 1 }, callback) | 37 | RequestsDB.find({}, { _id: 1, request: 1, to: 1 }, callback) |
38 | } | ||
39 | |||
40 | function removeAll (callback) { | ||
41 | RequestsDB.remove({ }, callback) | ||
42 | } | ||
43 | |||
44 | function removePodOf (requestsIds, podId, callback) { | ||
45 | if (!callback) callback = function () {} | ||
46 | |||
47 | RequestsDB.update({ _id: { $in: requestsIds } }, { $pull: { to: podId } }, { multi: true }, callback) | ||
36 | } | 48 | } |
37 | 49 | ||
38 | function removeRequestById (id, callback) { | 50 | function removeRequestById (id, callback) { |
@@ -50,6 +62,12 @@ function removeRequests (ids) { | |||
50 | }) | 62 | }) |
51 | } | 63 | } |
52 | 64 | ||
65 | function removeWithEmptyTo (callback) { | ||
66 | if (!callback) callback = function () {} | ||
67 | |||
68 | RequestsDB.remove({ to: { $size: 0 } }, callback) | ||
69 | } | ||
70 | |||
53 | // --------------------------------------------------------------------------- | 71 | // --------------------------------------------------------------------------- |
54 | 72 | ||
55 | module.exports = Requests | 73 | module.exports = Requests |