better transaction handling with rollback on exception

This commit is contained in:
azivner
2017-10-29 18:50:28 -04:00
parent afadd6ec06
commit de3d1b3e39
8 changed files with 145 additions and 150 deletions

View File

@@ -27,13 +27,11 @@ router.post('/', async (req, res, next) => {
if (ALLOWED_OPTIONS.includes(body['name'])) {
const optionName = await sql.getOption(body['name']);
await sql.beginTransaction();
await sql.doInTransaction(async () => {
await sql.addAudit(audit_category.SETTINGS, req, null, optionName, body['value'], body['name']);
await sql.addAudit(audit_category.SETTINGS, req, null, optionName, body['value'], body['name']);
await sql.setOption(body['name'], body['value']);
await sql.commit();
await sql.setOption(body['name'], body['value']);
});
res.send({});
}