aboutsummaryrefslogtreecommitdiffhomepage
path: root/models/poolRequests.js
diff options
context:
space:
mode:
Diffstat (limited to 'models/poolRequests.js')
-rw-r--r--models/poolRequests.js84
1 files changed, 41 insertions, 43 deletions
diff --git a/models/poolRequests.js b/models/poolRequests.js
index 5070a1331..970315597 100644
--- a/models/poolRequests.js
+++ b/models/poolRequests.js
@@ -1,57 +1,55 @@
1;(function () { 1'use strict'
2 'use strict'
3 2
4 var mongoose = require('mongoose') 3var mongoose = require('mongoose')
5 4
6 var logger = require('../helpers/logger') 5var logger = require('../helpers/logger')
7 6
8 // --------------------------------------------------------------------------- 7// ---------------------------------------------------------------------------
9 8
10 var poolRequestsSchema = mongoose.Schema({ 9var poolRequestsSchema = mongoose.Schema({
11 type: String, 10 type: String,
12 id: String, // Special id to find duplicates (video created we want to remove...) 11 id: String, // Special id to find duplicates (video created we want to remove...)
13 request: mongoose.Schema.Types.Mixed 12 request: mongoose.Schema.Types.Mixed
14 }) 13})
15 var PoolRequestsDB = mongoose.model('poolRequests', poolRequestsSchema) 14var PoolRequestsDB = mongoose.model('poolRequests', poolRequestsSchema)
16 15
17 // --------------------------------------------------------------------------- 16// ---------------------------------------------------------------------------
18 17
19 var PoolRequests = { 18var PoolRequests = {
20 create: create, 19 create: create,
21 findById: findById, 20 findById: findById,
22 list: list, 21 list: list,
23 removeRequestById: removeRequestById, 22 removeRequestById: removeRequestById,
24 removeRequests: removeRequests 23 removeRequests: removeRequests
25 } 24}
26 25
27 function create (id, type, request, callback) { 26function create (id, type, request, callback) {
28 PoolRequestsDB.create({ id: id, type: type, request: request }, callback) 27 PoolRequestsDB.create({ id: id, type: type, request: request }, callback)
29 } 28}
30 29
31 function findById (id, callback) { 30function findById (id, callback) {
32 PoolRequestsDB.findOne({ id: id }, callback) 31 PoolRequestsDB.findOne({ id: id }, callback)
33 } 32}
34 33
35 function list (callback) { 34function list (callback) {
36 PoolRequestsDB.find({}, { _id: 1, type: 1, request: 1 }, callback) 35 PoolRequestsDB.find({}, { _id: 1, type: 1, request: 1 }, callback)
37 } 36}
38 37
39 function removeRequestById (id, callback) { 38function removeRequestById (id, callback) {
40 PoolRequestsDB.remove({ id: id }, callback) 39 PoolRequestsDB.remove({ id: id }, callback)
41 } 40}
42 41
43 function removeRequests (ids) { 42function removeRequests (ids) {
44 PoolRequestsDB.remove({ _id: { $in: ids } }, function (err) { 43 PoolRequestsDB.remove({ _id: { $in: ids } }, function (err) {
45 if (err) { 44 if (err) {
46 logger.error('Cannot remove requests from the pool requests database.', { error: err }) 45 logger.error('Cannot remove requests from the pool requests database.', { error: err })
47 return // Abort 46 return // Abort
48 } 47 }
49 48
50 logger.info('Pool requests flushed.') 49 logger.info('Pool requests flushed.')
51 }) 50 })
52 } 51}
53 52
54 // --------------------------------------------------------------------------- 53// ---------------------------------------------------------------------------
55 54
56 module.exports = PoolRequests 55module.exports = PoolRequests
57})()