aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/poolRequests.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-03-07 11:33:59 +0100
committerChocobozzz <florian.bigard@gmail.com>2016-03-07 11:33:59 +0100
commitb9a3e09ad5a7673f64556d1dba122ed4c4fac980 (patch)
tree66d4928b82af19a2372a2505822233884f3fd471 /server/models/poolRequests.js
parentb2ff5e3e686eb552c5ccd64ce67b0455972ceef0 (diff)
downloadPeerTube-b9a3e09ad5a7673f64556d1dba122ed4c4fac980.tar.gz
PeerTube-b9a3e09ad5a7673f64556d1dba122ed4c4fac980.tar.zst
PeerTube-b9a3e09ad5a7673f64556d1dba122ed4c4fac980.zip
Prepare folders structure for angular app
Diffstat (limited to 'server/models/poolRequests.js')
-rw-r--r--server/models/poolRequests.js55
1 files changed, 55 insertions, 0 deletions
diff --git a/server/models/poolRequests.js b/server/models/poolRequests.js
new file mode 100644
index 000000000..970315597
--- /dev/null
+++ b/server/models/poolRequests.js
@@ -0,0 +1,55 @@
1'use strict'
2
3var mongoose = require('mongoose')
4
5var logger = require('../helpers/logger')
6
7// ---------------------------------------------------------------------------
8
9var poolRequestsSchema = mongoose.Schema({
10 type: String,
11 id: String, // Special id to find duplicates (video created we want to remove...)
12 request: mongoose.Schema.Types.Mixed
13})
14var PoolRequestsDB = mongoose.model('poolRequests', poolRequestsSchema)
15
16// ---------------------------------------------------------------------------
17
18var PoolRequests = {
19 create: create,
20 findById: findById,
21 list: list,
22 removeRequestById: removeRequestById,
23 removeRequests: removeRequests
24}
25
26function create (id, type, request, callback) {
27 PoolRequestsDB.create({ id: id, type: type, request: request }, callback)
28}
29
30function findById (id, callback) {
31 PoolRequestsDB.findOne({ id: id }, callback)
32}
33
34function list (callback) {
35 PoolRequestsDB.find({}, { _id: 1, type: 1, request: 1 }, callback)
36}
37
38function removeRequestById (id, callback) {
39 PoolRequestsDB.remove({ id: id }, callback)
40}
41
42function removeRequests (ids) {
43 PoolRequestsDB.remove({ _id: { $in: ids } }, function (err) {
44 if (err) {
45 logger.error('Cannot remove requests from the pool requests database.', { error: err })
46 return // Abort
47 }
48
49 logger.info('Pool requests flushed.')
50 })
51}
52
53// ---------------------------------------------------------------------------
54
55module.exports = PoolRequests