aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/requests.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/requests.js')
-rw-r--r--server/models/requests.js73
1 files changed, 0 insertions, 73 deletions
diff --git a/server/models/requests.js b/server/models/requests.js
deleted file mode 100644
index e67ccad56..000000000
--- a/server/models/requests.js
+++ /dev/null
@@ -1,73 +0,0 @@
1'use strict'
2
3const mongoose = require('mongoose')
4
5const logger = require('../helpers/logger')
6
7// ---------------------------------------------------------------------------
8
9const requestsSchema = mongoose.Schema({
10 request: mongoose.Schema.Types.Mixed,
11 to: [ { type: mongoose.Schema.Types.ObjectId, ref: 'users' } ]
12})
13const RequestsDB = mongoose.model('requests', requestsSchema)
14
15// ---------------------------------------------------------------------------
16
17const Requests = {
18 create: create,
19 findById: findById,
20 list: list,
21 removeAll: removeAll,
22 removePodOf: removePodOf,
23 removeRequestById: removeRequestById,
24 removeRequests: removeRequests,
25 removeWithEmptyTo: removeWithEmptyTo
26}
27
28function create (request, to, callback) {
29 RequestsDB.create({ request: request, to: to }, callback)
30}
31
32function findById (id, callback) {
33 RequestsDB.findOne({ id: id }, callback)
34}
35
36function list (callback) {
37 RequestsDB.find({}, { _id: 1, request: 1, to: 1 }, callback)
38}
39
40function removeAll (callback) {
41 RequestsDB.remove({ }, callback)
42}
43
44function removePodOf (requestsIds, podId, callback) {
45 if (!callback) callback = function () {}
46
47 RequestsDB.update({ _id: { $in: requestsIds } }, { $pull: { to: podId } }, { multi: true }, callback)
48}
49
50function removeRequestById (id, callback) {
51 RequestsDB.remove({ id: id }, callback)
52}
53
54function removeRequests (ids) {
55 RequestsDB.remove({ _id: { $in: ids } }, function (err) {
56 if (err) {
57 logger.error('Cannot remove requests from the requests database.', { error: err })
58 return // Abort
59 }
60
61 logger.info('Pool requests flushed.')
62 })
63}
64
65function removeWithEmptyTo (callback) {
66 if (!callback) callback = function () {}
67
68 RequestsDB.remove({ to: { $size: 0 } }, callback)
69}
70
71// ---------------------------------------------------------------------------
72
73module.exports = Requests