-
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: topic/k1ch/ introduce GET:/tenants
- Loading branch information
Showing
3 changed files
with
175 additions
and
11 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,33 @@ | ||
const createError = require('http-errors') | ||
const dbAdminTenant = require('database/layer/admin-tenant') | ||
|
||
/** | ||
* HTTP Request handler | ||
* Get tenants with optional filtering, sorting, and ordering | ||
* | ||
* @param {Object} req - The request object | ||
* @param {Object} res - The response object to send 200 statusCode and a list of tenants | ||
* @param {Function} next - The callback function for the next middleware | ||
* @returns {Promise<void>} - A promise that resolves to void when tenants are retrieved | ||
*/ | ||
const getTenants = async (req, res, next) => { | ||
try { | ||
const { sort, order } = req.query | ||
const allowedFilterParameters = ['key', 'name', 'iss_claim'] | ||
const filters = allowedFilterParameters.reduce((acc, filter) => { | ||
const filterValue = req.query[filter] | ||
if (filterValue) { | ||
acc[filter] = filterValue | ||
} | ||
return acc | ||
}, {}) | ||
const tenants = await dbAdminTenant.getTenants(filters, sort, order) | ||
res.status(200).send(tenants); | ||
} catch ({ httpStatusCode = 500, message }) { | ||
return next(createError(httpStatusCode, { message })) | ||
} | ||
} | ||
|
||
module.exports = { | ||
getTenants, | ||
} |
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