Fix update route to use async

This commit is contained in:
Girish Ramakrishnan
2021-08-27 09:30:52 -07:00
parent 7413ccd22e
commit a5d41e33f9
2 changed files with 16 additions and 17 deletions

View File

@@ -177,17 +177,16 @@ async function getMemory(req, res, next) {
next(new HttpSuccess(200, result));
}
function update(req, res, next) {
async function update(req, res, next) {
if ('skipBackup' in req.body && typeof req.body.skipBackup !== 'boolean') return next(new HttpError(400, 'skipBackup must be a boolean'));
// this only initiates the update, progress can be checked via the progress route
updater.updateToLatest(req.body, auditSource.fromRequest(req), function (error, taskId) {
if (error && error.reason === BoxError.NOT_FOUND) return next(new HttpError(422, error.message));
if (error && error.reason === BoxError.BAD_STATE) return next(new HttpError(409, error.message));
if (error) return next(new HttpError(500, error));
const [error, taskId] = await safe(updater.updateToLatest(req.body, auditSource.fromRequest(req)));
if (error && error.reason === BoxError.NOT_FOUND) return next(new HttpError(422, error.message));
if (error && error.reason === BoxError.BAD_STATE) return next(new HttpError(409, error.message));
if (error) return next(new HttpError(500, error));
next(new HttpSuccess(202, { taskId }));
});
next(new HttpSuccess(202, { taskId }));
}
function getUpdateInfo(req, res, next) {