diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-06-28 20:10:32 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-06-28 20:10:32 +0200 |
commit | 00057e85a703713a8f0d96e01c49978be0987eb2 (patch) | |
tree | 54735435062d2ededa72448de9fcaa677cf2c79c /server/models/requests.js | |
parent | aaf61f3810e6d57c5130af959bd2860df32775e7 (diff) | |
download | PeerTube-00057e85a703713a8f0d96e01c49978be0987eb2.tar.gz PeerTube-00057e85a703713a8f0d96e01c49978be0987eb2.tar.zst PeerTube-00057e85a703713a8f0d96e01c49978be0987eb2.zip |
Request model refractoring -> use mongoose api
Diffstat (limited to 'server/models/requests.js')
-rw-r--r-- | server/models/requests.js | 73 |
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 | |||
3 | const mongoose = require('mongoose') | ||
4 | |||
5 | const logger = require('../helpers/logger') | ||
6 | |||
7 | // --------------------------------------------------------------------------- | ||
8 | |||
9 | const requestsSchema = mongoose.Schema({ | ||
10 | request: mongoose.Schema.Types.Mixed, | ||
11 | to: [ { type: mongoose.Schema.Types.ObjectId, ref: 'users' } ] | ||
12 | }) | ||
13 | const RequestsDB = mongoose.model('requests', requestsSchema) | ||
14 | |||
15 | // --------------------------------------------------------------------------- | ||
16 | |||
17 | const 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 | |||
28 | function create (request, to, callback) { | ||
29 | RequestsDB.create({ request: request, to: to }, callback) | ||
30 | } | ||
31 | |||
32 | function findById (id, callback) { | ||
33 | RequestsDB.findOne({ id: id }, callback) | ||
34 | } | ||
35 | |||
36 | function list (callback) { | ||
37 | RequestsDB.find({}, { _id: 1, request: 1, to: 1 }, callback) | ||
38 | } | ||
39 | |||
40 | function removeAll (callback) { | ||
41 | RequestsDB.remove({ }, callback) | ||
42 | } | ||
43 | |||
44 | function removePodOf (requestsIds, podId, callback) { | ||
45 | if (!callback) callback = function () {} | ||
46 | |||
47 | RequestsDB.update({ _id: { $in: requestsIds } }, { $pull: { to: podId } }, { multi: true }, callback) | ||
48 | } | ||
49 | |||
50 | function removeRequestById (id, callback) { | ||
51 | RequestsDB.remove({ id: id }, callback) | ||
52 | } | ||
53 | |||
54 | function 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 | |||
65 | function removeWithEmptyTo (callback) { | ||
66 | if (!callback) callback = function () {} | ||
67 | |||
68 | RequestsDB.remove({ to: { $size: 0 } }, callback) | ||
69 | } | ||
70 | |||
71 | // --------------------------------------------------------------------------- | ||
72 | |||
73 | module.exports = Requests | ||