aboutsummaryrefslogtreecommitdiffhomepage
path: root/models
diff options
context:
space:
mode:
Diffstat (limited to 'models')
-rw-r--r--models/poolRequests.js41
1 files changed, 12 insertions, 29 deletions
diff --git a/models/poolRequests.js b/models/poolRequests.js
index 962e75e6a..5070a1331 100644
--- a/models/poolRequests.js
+++ b/models/poolRequests.js
@@ -17,46 +17,29 @@
17 // --------------------------------------------------------------------------- 17 // ---------------------------------------------------------------------------
18 18
19 var PoolRequests = { 19 var PoolRequests = {
20 addRequest: addRequest, 20 create: create,
21 findById: findById,
21 list: list, 22 list: list,
23 removeRequestById: removeRequestById,
22 removeRequests: removeRequests 24 removeRequests: removeRequests
23 } 25 }
24 26
25 function addRequest (id, type, request) { 27 function create (id, type, request, callback) {
26 logger.debug('Add request to the pool requests.', { id: id, type: type, request: request }) 28 PoolRequestsDB.create({ id: id, type: type, request: request }, callback)
27 29 }
28 PoolRequestsDB.findOne({ id: id }, function (err, entity) {
29 if (err) {
30 logger.error('Cannot find one pool request.', { error: err })
31 return // Abort
32 }
33
34 if (entity) {
35 if (entity.type === type) {
36 logger.error('Cannot insert two same requests.')
37 return // Abort
38 }
39 30
40 // Remove the request of the other type 31 function findById (id, callback) {
41 PoolRequestsDB.remove({ id: id }, function (err) { 32 PoolRequestsDB.findOne({ id: id }, callback)
42 if (err) {
43 logger.error('Cannot remove a pool request.', { error: err })
44 return // Abort
45 }
46 })
47 } else {
48 PoolRequestsDB.create({ id: id, type: type, request: request }, function (err) {
49 logger.error('Cannot create a pool request.', { error: err })
50 return // Abort
51 })
52 }
53 })
54 } 33 }
55 34
56 function list (callback) { 35 function list (callback) {
57 PoolRequestsDB.find({}, { _id: 1, type: 1, request: 1 }, callback) 36 PoolRequestsDB.find({}, { _id: 1, type: 1, request: 1 }, callback)
58 } 37 }
59 38
39 function removeRequestById (id, callback) {
40 PoolRequestsDB.remove({ id: id }, callback)
41 }
42
60 function removeRequests (ids) { 43 function removeRequests (ids) {
61 PoolRequestsDB.remove({ _id: { $in: ids } }, function (err) { 44 PoolRequestsDB.remove({ _id: { $in: ids } }, function (err) {
62 if (err) { 45 if (err) {