Implement GET /schemas/OneSchema

This commit is contained in:
Drew Gross
2016-02-03 16:10:00 -08:00
parent 33a881764d
commit 67ee94d98f
2 changed files with 149 additions and 72 deletions

View File

@@ -64,6 +64,26 @@ function getAllSchemas(req) {
}}));
}
function getOneSchema(req) {
if (!req.auth.isMaster) {
return Promise.resolve({
status: 401,
response: {error: 'unauthorized'},
});
}
return req.config.database.collection('_SCHEMA')
.then(coll => coll.findOne({'_id': req.params.className}))
.then(schema => ({response: mongoSchemaToSchemaAPIResponse(schema)}))
.catch(() => ({
status: 400,
response: {
code: 103,
error: 'class ' + req.params.className + ' does not exist',
}
}));
}
router.route('GET', '/schemas', getAllSchemas);
router.route('GET', '/schemas/:className', getOneSchema);
module.exports = router;