translation: asyncify

This commit is contained in:
Girish Ramakrishnan
2021-08-19 11:00:35 -07:00
parent 03e22170da
commit ada7166bf8
5 changed files with 102 additions and 132 deletions

View File

@@ -248,24 +248,22 @@ function setSysinfoConfig(req, res, next) {
});
}
function getLanguage(req, res, next) {
settings.getLanguage(function (error, language) {
if (error) return next(BoxError.toHttpError(error));
async function getLanguage(req, res, next) {
const [error, language] = await safe(settings.getLanguage());
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(200, { language }));
});
next(new HttpSuccess(200, { language }));
}
function setLanguage(req, res, next) {
async function setLanguage(req, res, next) {
assert.strictEqual(typeof req.body, 'object');
if (!req.body.language || typeof req.body.language !== 'string') return next(new HttpError(400, 'language is required'));
settings.setLanguage(req.body.language, function (error) {
if (error) return next(BoxError.toHttpError(error));
const [error] = await safe(settings.setLanguage(req.body.language));
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(200, {}));
});
next(new HttpSuccess(200, {}));
}
function get(req, res, next) {