]>
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 | |
e3647ae2 | 9 | const requestsSchema = 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 | }) | |
e3647ae2 | 14 | const RequestsDB = mongoose.model('requests', requestsSchema) |
c173e565 | 15 | |
9f10b292 | 16 | // --------------------------------------------------------------------------- |
c173e565 | 17 | |
e3647ae2 | 18 | const Requests = { |
9f10b292 C |
19 | create: create, |
20 | findById: findById, | |
21 | list: list, | |
22 | removeRequestById: removeRequestById, | |
23 | removeRequests: removeRequests | |
24 | } | |
c173e565 | 25 | |
9f10b292 | 26 | function create (id, type, request, callback) { |
e3647ae2 | 27 | RequestsDB.create({ id: id, type: type, request: request }, callback) |
9f10b292 | 28 | } |
c173e565 | 29 | |
9f10b292 | 30 | function findById (id, callback) { |
e3647ae2 | 31 | RequestsDB.findOne({ id: id }, callback) |
9f10b292 | 32 | } |
c173e565 | 33 | |
9f10b292 | 34 | function list (callback) { |
e3647ae2 | 35 | RequestsDB.find({}, { _id: 1, type: 1, request: 1 }, callback) |
9f10b292 | 36 | } |
c173e565 | 37 | |
9f10b292 | 38 | function removeRequestById (id, callback) { |
e3647ae2 | 39 | RequestsDB.remove({ id: id }, callback) |
9f10b292 | 40 | } |
1fe5076f | 41 | |
9f10b292 | 42 | function removeRequests (ids) { |
e3647ae2 | 43 | RequestsDB.remove({ _id: { $in: ids } }, function (err) { |
9f10b292 | 44 | if (err) { |
e3647ae2 | 45 | logger.error('Cannot remove requests from the requests database.', { error: err }) |
9f10b292 C |
46 | return // Abort |
47 | } | |
c173e565 | 48 | |
9f10b292 C |
49 | logger.info('Pool requests flushed.') |
50 | }) | |
51 | } | |
c173e565 | 52 | |
9f10b292 | 53 | // --------------------------------------------------------------------------- |
c173e565 | 54 | |
e3647ae2 | 55 | module.exports = Requests |