-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: k1ch/ introduce POST:/clients/{client_id}/permissions
- Loading branch information
Showing
4 changed files
with
143 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const createError = require('http-errors') | ||
const dbAdminPermission = require('database/layer/admin-permission') | ||
const { checkClientExists, checkPermissionNameUniqueness } = require('./utils') | ||
|
||
/** | ||
* HTTP Request handler | ||
* Create a permission | ||
* | ||
* @param {Object} req - The request object | ||
* @param {Object} res - The response object to send 201 statusCode and the cerated permission on success | ||
* @param {Function} next - The next middleware function | ||
* @returns {Promise<void>} - A Promise that resolves to void when the permission is created | ||
*/ | ||
const createPermission = async (req, res, next) => { | ||
try { | ||
const { client_id: clientId } = req.params | ||
const client = await checkClientExists(clientId) | ||
const payload = { | ||
...req.body, | ||
clientkey: client.key, | ||
} | ||
await checkPermissionNameUniqueness(payload) | ||
const permission = await dbAdminPermission.insertPermission(payload) | ||
res.status(201).send(permission) | ||
} catch ({ httpStatusCode = 500, message }) { | ||
return next(createError(httpStatusCode, { message })) | ||
} | ||
} | ||
|
||
module.exports = { | ||
createPermission, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters