Skip to content

Commit

Permalink
Merge pull request #3296 from LiteFarmOrg/LF-4298-The-user-is-able-to…
Browse files Browse the repository at this point in the history
…-edit-the-already-deleted-revenue

Lf 3773 the user is able to edit the already deleted revenue
  • Loading branch information
kathyavini committed Aug 2, 2024
2 parents 6e366df + 8171ee6 commit 1c5db7f
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 5 deletions.
6 changes: 6 additions & 0 deletions packages/api/src/controllers/saleController.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ const SaleController = {
saleData.value = value;
}

// do not allow updates to deleted records
if (await baseController.isDeleted(trx, SaleModel, { sale_id })) {
await trx.rollback();
return res.status(409).send('sale deleted');
}

const newSale = await SaleModel.query(trx)
.context(req.auth)
.where('sale_id', sale_id)
Expand Down
3 changes: 2 additions & 1 deletion packages/webapp/public/locales/en/message.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@
"ERROR": {
"ADD": "Failed to add sale",
"DELETE": "Failed to delete new sale",
"UPDATE": "Failed to update sale"
"UPDATE": "Failed to update sale",
"SALE_DELETED": "This sale no longer exists"
},
"SUCCESS": {
"ADD": "Successfully added sale",
Expand Down
3 changes: 2 additions & 1 deletion packages/webapp/public/locales/es/message.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@
"ERROR": {
"ADD": "No se pudo agregar venta",
"DELETE": "No se pudo borrar nueva venta",
"UPDATE": "No se pudo actualizar venta"
"UPDATE": "No se pudo actualizar venta",
"SALE_DELETED": "MISSING"
},
"SUCCESS": {
"ADD": "Venta agregada exitosamente",
Expand Down
3 changes: 2 additions & 1 deletion packages/webapp/public/locales/fr/message.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@
"ERROR": {
"ADD": "Impossible d'ajouter la vente",
"DELETE": "Impossible de supprimer la vente",
"UPDATE": "Impossible de mettre à jour la vente"
"UPDATE": "Impossible de mettre à jour la vente",
"SALE_DELETED": "MISSING"
},
"SUCCESS": {
"ADD": "Vente ajoutée",
Expand Down
3 changes: 2 additions & 1 deletion packages/webapp/public/locales/pt/message.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@
"ERROR": {
"ADD": "Falha ao adicionar venda",
"DELETE": "Falha de excluir venda nova",
"UPDATE": "Falha de atualizar venda"
"UPDATE": "Falha de atualizar venda",
"SALE_DELETED": "MISSING"
},
"SUCCESS": {
"ADD": "Venda adicionada com sucesso",
Expand Down
7 changes: 6 additions & 1 deletion packages/webapp/src/containers/Finances/saga.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@ export function* updateSaleSaga(action) {
history.push(FINANCES_HOME_URL);
} catch (e) {
console.log(`failed to update sale`);
yield put(enqueueErrorSnackbar(i18n.t('message:SALE.ERROR.UPDATE')));
if (e.response.data == 'sale deleted') {
yield put(enqueueErrorSnackbar(i18n.t('message:SALE.ERROR.SALE_DELETED')));
history.push(FINANCES_HOME_URL);
} else {
yield put(enqueueErrorSnackbar(i18n.t('message:SALE.ERROR.UPDATE')));
}
}
}

Expand Down

0 comments on commit 1c5db7f

Please sign in to comment.