]>
Commit | Line | Data |
---|---|---|
c173e565 C |
1 | ;(function () { |
2 | 'use strict' | |
3 | ||
4 | var mongoose = require('mongoose') | |
5 | ||
6 | var logger = require('../helpers/logger') | |
7 | ||
8 | // --------------------------------------------------------------------------- | |
9 | ||
10 | var poolRequestsSchema = mongoose.Schema({ | |
11 | type: String, | |
12 | id: String, // Special id to find duplicates (video created we want to remove...) | |
13 | request: mongoose.Schema.Types.Mixed | |
14 | }) | |
15 | var PoolRequestsDB = mongoose.model('poolRequests', poolRequestsSchema) | |
16 | ||
17 | // --------------------------------------------------------------------------- | |
18 | ||
19 | var PoolRequests = { | |
1fe5076f C |
20 | create: create, |
21 | findById: findById, | |
c173e565 | 22 | list: list, |
1fe5076f | 23 | removeRequestById: removeRequestById, |
c173e565 C |
24 | removeRequests: removeRequests |
25 | } | |
26 | ||
1fe5076f C |
27 | function create (id, type, request, callback) { |
28 | PoolRequestsDB.create({ id: id, type: type, request: request }, callback) | |
29 | } | |
c173e565 | 30 | |
1fe5076f C |
31 | function findById (id, callback) { |
32 | PoolRequestsDB.findOne({ id: id }, callback) | |
c173e565 C |
33 | } |
34 | ||
35 | function list (callback) { | |
36 | PoolRequestsDB.find({}, { _id: 1, type: 1, request: 1 }, callback) | |
37 | } | |
38 | ||
1fe5076f C |
39 | function removeRequestById (id, callback) { |
40 | PoolRequestsDB.remove({ id: id }, callback) | |
41 | } | |
42 | ||
c173e565 C |
43 | function removeRequests (ids) { |
44 | PoolRequestsDB.remove({ _id: { $in: ids } }, function (err) { | |
45 | if (err) { | |
46 | logger.error('Cannot remove requests from the pool requests database.', { error: err }) | |
8425cb89 | 47 | return // Abort |
c173e565 C |
48 | } |
49 | ||
50 | logger.info('Pool requests flushed.') | |
51 | }) | |
52 | } | |
53 | ||
54 | // --------------------------------------------------------------------------- | |
55 | ||
56 | module.exports = PoolRequests | |
57 | })() |