aboutsummaryrefslogtreecommitdiffhomepage
path: root/models/poolRequests.js
diff options
context:
space:
mode:
Diffstat (limited to 'models/poolRequests.js')
-rw-r--r--models/poolRequests.js19
1 files changed, 13 insertions, 6 deletions
diff --git a/models/poolRequests.js b/models/poolRequests.js
index 0f488ef04..962e75e6a 100644
--- a/models/poolRequests.js
+++ b/models/poolRequests.js
@@ -26,21 +26,28 @@
26 logger.debug('Add request to the pool requests.', { id: id, type: type, request: request }) 26 logger.debug('Add request to the pool requests.', { id: id, type: type, request: request })
27 27
28 PoolRequestsDB.findOne({ id: id }, function (err, entity) { 28 PoolRequestsDB.findOne({ id: id }, function (err, entity) {
29 if (err) logger.error(err) 29 if (err) {
30 logger.error('Cannot find one pool request.', { error: err })
31 return // Abort
32 }
30 33
31 if (entity) { 34 if (entity) {
32 if (entity.type === type) { 35 if (entity.type === type) {
33 logger.error(new Error('Cannot insert two same requests.')) 36 logger.error('Cannot insert two same requests.')
34 return 37 return // Abort
35 } 38 }
36 39
37 // Remove the request of the other type 40 // Remove the request of the other type
38 PoolRequestsDB.remove({ id: id }, function (err) { 41 PoolRequestsDB.remove({ id: id }, function (err) {
39 if (err) logger.error(err) 42 if (err) {
43 logger.error('Cannot remove a pool request.', { error: err })
44 return // Abort
45 }
40 }) 46 })
41 } else { 47 } else {
42 PoolRequestsDB.create({ id: id, type: type, request: request }, function (err) { 48 PoolRequestsDB.create({ id: id, type: type, request: request }, function (err) {
43 if (err) logger.error(err) 49 logger.error('Cannot create a pool request.', { error: err })
50 return // Abort
44 }) 51 })
45 } 52 }
46 }) 53 })
@@ -54,7 +61,7 @@
54 PoolRequestsDB.remove({ _id: { $in: ids } }, function (err) { 61 PoolRequestsDB.remove({ _id: { $in: ids } }, function (err) {
55 if (err) { 62 if (err) {
56 logger.error('Cannot remove requests from the pool requests database.', { error: err }) 63 logger.error('Cannot remove requests from the pool requests database.', { error: err })
57 return 64 return // Abort
58 } 65 }
59 66
60 logger.info('Pool requests flushed.') 67 logger.info('Pool requests flushed.')