mirror of
https://github.com/jambonz/jambonz-api-server.git
synced 2026-07-04 19:21:53 +00:00
major updates and test suite
This commit is contained in:
@@ -19,12 +19,16 @@ function decorate(router, klass, methods, preconditions) {
|
||||
});
|
||||
}
|
||||
|
||||
function list(router, klass) {
|
||||
function list(router, klass, preconditions) {
|
||||
router.get('/', async(req, res) => {
|
||||
const logger = req.app.locals.logger;
|
||||
//logger.info(`user: ${JSON.stringify(req.user)}`);
|
||||
//logger.info(`scope: ${JSON.stringify(req.authInfo.scope)}`);
|
||||
try {
|
||||
if ('list' in preconditions) {
|
||||
assert(typeof preconditions.list === 'function');
|
||||
await preconditions.list(req);
|
||||
}
|
||||
const results = await klass.retrieveAll();
|
||||
res.status(200).json(results);
|
||||
} catch (err) {
|
||||
@@ -63,11 +67,15 @@ function retrieve(router, klass) {
|
||||
});
|
||||
}
|
||||
|
||||
function update(router, klass) {
|
||||
function update(router, klass, preconditions) {
|
||||
router.put('/:sid', async(req, res) => {
|
||||
const sid = req.params.sid;
|
||||
const logger = req.app.locals.logger;
|
||||
try {
|
||||
if ('update' in preconditions) {
|
||||
assert(typeof preconditions.update === 'function');
|
||||
await preconditions.update(req, sid);
|
||||
}
|
||||
const rowsAffected = await klass.update(sid, req.body);
|
||||
if (rowsAffected === 0) {
|
||||
return res.status(404).end();
|
||||
|
||||
Reference in New Issue
Block a user