-
Notifications
You must be signed in to change notification settings - Fork 0
/
permissions-maintenance-db.js
63 lines (52 loc) · 2.24 KB
/
permissions-maintenance-db.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'use strict'
const lib = require('http-helper-functions')
const rLib = require('response-helper-functions')
const db = require('./permissions-maintenance-pg.js')
function withErrorHandling(req, res, callback) {
return function (err) {
if (err == 404)
rLib.notFound(res, `//${req.headers.host}${req.url} not found`)
else if (err == 409)
rLib.duplicate(res, 'permissions-maintenance-db: permissions already exist for this subject')
else if (err)
rLib.internalError(res, err)
else
callback.apply(this, Array.prototype.slice.call(arguments, 1))
}
}
function withPermissionsDo(req, res, subject, callback) {
db.withPermissionsDo(req, subject, withErrorHandling(req, res, callback))
}
function deletePermissionsThen(req, res, subject, callback) {
db.deletePermissionsThen(req, subject, withErrorHandling(req, res, callback))
}
function createPermissionsThen(req, res, permissions, scopes, callback) {
db.createPermissionsThen(req, permissions, scopes, withErrorHandling(req, res, callback))
}
function updatePermissionsThen(req, res, subject, patchedPermissions, scopes, etag, callback) {
db.updatePermissionsThen(req, subject, patchedPermissions, scopes, etag, withErrorHandling(req, res, callback))
}
function putPermissionsThen(req, res, subject, permissions, scopes, callback) {
db.putPermissionsThen(req, subject, permissions, scopes, withErrorHandling(req, res, callback))
}
function withResourcesSharedWithActorsDo(req, res, actors, callback) {
db.withResourcesSharedWithActorsDo(req, actors, withErrorHandling(req, res, callback))
}
function withHeirsDo(req, res, securedObject, callback) {
db.withHeirsDo(req, securedObject, withErrorHandling(req, res, callback))
}
function init(callback, aPool) {
db.init(callback, aPool)
}
process.on('unhandledRejection', function(e) {
console.log(e.message, e.stack)
})
exports.withPermissionsDo = withPermissionsDo
exports.createPermissionsThen = createPermissionsThen
exports.deletePermissionsThen = deletePermissionsThen
exports.updatePermissionsThen = updatePermissionsThen
exports.putPermissionsThen = putPermissionsThen
exports.withResourcesSharedWithActorsDo = withResourcesSharedWithActorsDo
exports.withHeirsDo = withHeirsDo
exports.init = init
exports.db = db