]>
Commit | Line | Data |
---|---|---|
9f10b292 | 1 | 'use strict' |
c173e565 | 2 | |
f0f5567b | 3 | const mongoose = require('mongoose') |
c173e565 | 4 | |
f0f5567b | 5 | const logger = require('../helpers/logger') |
c173e565 | 6 | |
9f10b292 | 7 | // --------------------------------------------------------------------------- |
c173e565 | 8 | |
f0f5567b | 9 | const poolRequestsSchema = mongoose.Schema({ |
9f10b292 C |
10 | type: String, |
11 | id: String, // Special id to find duplicates (video created we want to remove...) | |
12 | request: mongoose.Schema.Types.Mixed | |
13 | }) | |
f0f5567b | 14 | const PoolRequestsDB = mongoose.model('poolRequests', poolRequestsSchema) |
c173e565 | 15 | |
9f10b292 | 16 | // --------------------------------------------------------------------------- |
c173e565 | 17 | |
f0f5567b | 18 | const PoolRequests = { |
9f10b292 C |
19 | create: create, |
20 | findById: findById, | |
21 | list: list, | |
22 | removeRequestById: removeRequestById, | |
23 | removeRequests: removeRequests | |
24 | } | |
c173e565 | 25 | |
9f10b292 C |
26 | function create (id, type, request, callback) { |
27 | PoolRequestsDB.create({ id: id, type: type, request: request }, callback) | |
28 | } | |
c173e565 | 29 | |
9f10b292 C |
30 | function findById (id, callback) { |
31 | PoolRequestsDB.findOne({ id: id }, callback) | |
32 | } | |
c173e565 | 33 | |
9f10b292 C |
34 | function list (callback) { |
35 | PoolRequestsDB.find({}, { _id: 1, type: 1, request: 1 }, callback) | |
36 | } | |
c173e565 | 37 | |
9f10b292 C |
38 | function removeRequestById (id, callback) { |
39 | PoolRequestsDB.remove({ id: id }, callback) | |
40 | } | |
1fe5076f | 41 | |
9f10b292 C |
42 | function 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 | } | |
c173e565 | 48 | |
9f10b292 C |
49 | logger.info('Pool requests flushed.') |
50 | }) | |
51 | } | |
c173e565 | 52 | |
9f10b292 | 53 | // --------------------------------------------------------------------------- |
c173e565 | 54 | |
9f10b292 | 55 | module.exports = PoolRequests |