-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4517 from airqo-platform/staging
move to production
- Loading branch information
Showing
18 changed files
with
862 additions
and
70 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
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
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
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
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
230 changes: 230 additions & 0 deletions
230
src/auth-service/controllers/tenant-settings.controller.js
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,230 @@ | ||
// tenantSettings.controller.js | ||
const tenantSettingsUtil = require("@utils/tenant-settings.util"); | ||
const { | ||
logObject, | ||
logText, | ||
logElement, | ||
HttpError, | ||
extractErrorsFromRequest, | ||
} = require("@utils/shared"); | ||
const constants = require("@config/constants"); | ||
const isEmpty = require("is-empty"); | ||
const httpStatus = require("http-status"); | ||
const log4js = require("log4js"); | ||
const logger = log4js.getLogger( | ||
`${constants.ENVIRONMENT} -- tenantSettings-controller` | ||
); | ||
|
||
const tenantSettings = { | ||
create: async (req, res, next) => { | ||
try { | ||
const errors = extractErrorsFromRequest(req); | ||
if (errors) { | ||
next( | ||
new HttpError("bad request errors", httpStatus.BAD_REQUEST, errors) | ||
); | ||
return; | ||
} | ||
const request = req; | ||
const defaultTenant = constants.DEFAULT_TENANT || "airqo"; | ||
request.query.tenant = isEmpty(req.query.tenant) | ||
? defaultTenant | ||
: req.query.tenant; | ||
|
||
const result = await tenantSettingsUtil.create(request, next); | ||
|
||
if (isEmpty(result) || res.headersSent) { | ||
return; | ||
} | ||
|
||
if (result.success === true) { | ||
const status = result.status ? result.status : httpStatus.OK; | ||
return res.status(status).json({ | ||
success: true, | ||
message: result.message ? result.message : "", | ||
tenantSettings: result.data ? result.data : [], | ||
}); | ||
} else if (result.success === false) { | ||
const status = result.status | ||
? result.status | ||
: httpStatus.INTERNAL_SERVER_ERROR; | ||
return res.status(status).json({ | ||
success: false, | ||
message: result.message ? result.message : "", | ||
errors: result.errors ? result.errors : { message: "" }, | ||
}); | ||
} | ||
} catch (error) { | ||
logger.error(`🐛🐛 Internal Server Error ${error.message}`); | ||
next( | ||
new HttpError( | ||
"Internal Server Error", | ||
httpStatus.INTERNAL_SERVER_ERROR, | ||
{ message: error.message } | ||
) | ||
); | ||
return; | ||
} | ||
}, | ||
|
||
list: async (req, res, next) => { | ||
try { | ||
const errors = extractErrorsFromRequest(req); | ||
if (errors) { | ||
next( | ||
new HttpError("bad request errors", httpStatus.BAD_REQUEST, errors) | ||
); | ||
return; | ||
} | ||
const request = req; | ||
const defaultTenant = constants.DEFAULT_TENANT || "airqo"; | ||
request.query.tenant = isEmpty(req.query.tenant) | ||
? defaultTenant | ||
: req.query.tenant; | ||
|
||
const result = await tenantSettingsUtil.list(request, next); | ||
|
||
if (isEmpty(result) || res.headersSent) { | ||
return; | ||
} | ||
|
||
if (result.success === true) { | ||
const status = result.status ? result.status : httpStatus.OK; | ||
return res.status(status).json({ | ||
success: true, | ||
message: result.message ? result.message : "", | ||
tenantSettings: result.data ? result.data : [], | ||
}); | ||
} else if (result.success === false) { | ||
const status = result.status | ||
? result.status | ||
: httpStatus.INTERNAL_SERVER_ERROR; | ||
return res.status(status).json({ | ||
success: false, | ||
message: result.message ? result.message : "", | ||
errors: result.errors | ||
? result.errors | ||
: { message: "Internal Server Error" }, | ||
}); | ||
} | ||
} catch (error) { | ||
logger.error(`🐛🐛 Internal Server Error ${error.message}`); | ||
next( | ||
new HttpError( | ||
"Internal Server Error", | ||
httpStatus.INTERNAL_SERVER_ERROR, | ||
{ message: error.message } | ||
) | ||
); | ||
return; | ||
} | ||
}, | ||
|
||
update: async (req, res, next) => { | ||
try { | ||
const errors = extractErrorsFromRequest(req); | ||
if (errors) { | ||
next( | ||
new HttpError("bad request errors", httpStatus.BAD_REQUEST, errors) | ||
); | ||
return; | ||
} | ||
const request = req; | ||
const defaultTenant = constants.DEFAULT_TENANT || "airqo"; | ||
request.query.tenant = isEmpty(req.query.tenant) | ||
? defaultTenant | ||
: req.query.tenant; | ||
|
||
const result = await tenantSettingsUtil.update(request, next); | ||
|
||
if (isEmpty(result) || res.headersSent) { | ||
return; | ||
} | ||
|
||
if (result.success === true) { | ||
const status = result.status ? result.status : httpStatus.OK; | ||
return res.status(status).json({ | ||
success: true, | ||
message: result.message ? result.message : "", | ||
updatedTenantSettings: result.data ? result.data : [], | ||
}); | ||
} else if (result.success === false) { | ||
const status = result.status | ||
? result.status | ||
: httpStatus.INTERNAL_SERVER_ERROR; | ||
return res.status(status).json({ | ||
success: false, | ||
message: result.message ? result.message : "", | ||
errors: result.errors | ||
? result.errors | ||
: { message: "Internal Server Error" }, | ||
}); | ||
} | ||
} catch (error) { | ||
logger.error(`🐛🐛 Internal Server Error ${error.message}`); | ||
next( | ||
new HttpError( | ||
"Internal Server Error", | ||
httpStatus.INTERNAL_SERVER_ERROR, | ||
{ message: error.message } | ||
) | ||
); | ||
return; | ||
} | ||
}, | ||
|
||
delete: async (req, res, next) => { | ||
try { | ||
const errors = extractErrorsFromRequest(req); | ||
if (errors) { | ||
next( | ||
new HttpError("bad request errors", httpStatus.BAD_REQUEST, errors) | ||
); | ||
return; | ||
} | ||
const request = req; | ||
const defaultTenant = constants.DEFAULT_TENANT || "airqo"; | ||
request.query.tenant = isEmpty(req.query.tenant) | ||
? defaultTenant | ||
: req.query.tenant; | ||
|
||
const result = await tenantSettingsUtil.delete(request, next); | ||
|
||
if (isEmpty(result) || res.headersSent) { | ||
return; | ||
} | ||
|
||
if (result.success === true) { | ||
const status = result.status ? result.status : httpStatus.OK; | ||
return res.status(status).json({ | ||
success: true, | ||
message: result.message ? result.message : "", | ||
deletedTenantSettings: result.data ? result.data : [], | ||
}); | ||
} else if (result.success === false) { | ||
const status = result.status | ||
? result.status | ||
: httpStatus.INTERNAL_SERVER_ERROR; | ||
return res.status(status).json({ | ||
success: false, | ||
message: result.message ? result.message : "", | ||
errors: result.errors | ||
? result.errors | ||
: { message: "Internal Server Error" }, | ||
}); | ||
} | ||
} catch (error) { | ||
logger.error(`🐛🐛 Internal Server Error ${error.message}`); | ||
next( | ||
new HttpError( | ||
"Internal Server Error", | ||
httpStatus.INTERNAL_SERVER_ERROR, | ||
{ message: error.message } | ||
) | ||
); | ||
return; | ||
} | ||
}, | ||
}; | ||
|
||
module.exports = tenantSettings; |
Oops, something went wrong.