Add route to delete a single token

This commit is contained in:
Johannes Zellner
2016-06-07 15:34:27 +02:00
parent d9d94faf75
commit 8e5af17e5d
3 changed files with 36 additions and 1 deletions

View File

@@ -7,7 +7,8 @@ exports = module.exports = {
getAll: getAll,
addClientToken: addClientToken,
getClientTokens: getClientTokens,
delClientTokens: delClientTokens
delClientTokens: delClientTokens,
delToken: delToken
};
var assert = require('assert'),
@@ -93,3 +94,17 @@ function delClientTokens(req, res, next) {
next(new HttpSuccess(204));
});
}
function delToken(req, res, next) {
assert.strictEqual(typeof req.params.clientId, 'string');
assert.strictEqual(typeof req.params.tokenId, 'string');
assert.strictEqual(typeof req.user, 'object');
clients.delToken(req.params.clientId, req.params.tokenId, function (error) {
if (error && error.reason === DatabaseError.NOT_FOUND) return next(new HttpError(404, 'no such client'));
if (error && error.reason === ClientsError.INVALID_TOKEN) return next(new HttpError(404, 'no such token'));
if (error) return next(new HttpError(500, error));
next(new HttpSuccess(204));
});
}