Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lf 3773 the user is able to edit the already deleted expense #3293

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/api/src/controllers/farmExpenseController.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ const farmExpenseController = {
const { user_id } = req.auth;

const trx = await transaction.start(Model.knex());

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

try {
const result = await FarmExpenseModel.query(trx)
.context({ user_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 @@ -46,7 +46,8 @@
"ERROR": {
"ADD": "Failed to add new expenses",
"DELETE": "Failed to delete expenses",
"UPDATE": "Failed to update expenses!"
"UPDATE": "Failed to update expenses!",
"EXPENSE_DELETED": "This expense no longer exists"
},
"SUCCESS": {
"ADD": "Successfully added new expenses!",
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 @@ -46,7 +46,8 @@
"ERROR": {
"ADD": "No se pudo agregar nuevos gastos",
"DELETE": "No se pudo borrar gastos",
"UPDATE": "No se pudo actualizar gastos!"
"UPDATE": "No se pudo actualizar gastos!",
"EXPENSE_DELETED": "MISSING"
},
"SUCCESS": {
"ADD": "¡Nuevos gastos agregados 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 @@ -46,7 +46,8 @@
"ERROR": {
"ADD": "Impossible d'ajouter de nouvelles dépenses",
"DELETE": "Impossible de supprimer les dépenses",
"UPDATE": "Impossible de mettre à jour les dépenses"
"UPDATE": "Impossible de mettre à jour les dépenses",
"EXPENSE_DELETED": "MISSING"
},
"SUCCESS": {
"ADD": "Nouvelles dépenses ajoutées",
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 @@ -46,7 +46,8 @@
"ERROR": {
"ADD": "Falha ao adicionar novas despesas",
"DELETE": "Falha ao excluir despesas",
"UPDATE": "Falha ao atualizar despesas!"
"UPDATE": "Falha ao atualizar despesas!",
"EXPENSE_DELETED": "MISSING"
},
"SUCCESS": {
"ADD": "Novas despesas adicionadas 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 @@ -336,7 +336,12 @@ export function* editExpenseSaga(action) {
history.push(FINANCES_HOME_URL);
} catch (e) {
console.log(e);
yield put(enqueueErrorSnackbar(i18n.t('message:EXPENSE.ERROR.UPDATE')));
if (e.response.data == 'expense deleted') {
yield put(enqueueErrorSnackbar(i18n.t('message:EXPENSE.ERROR.EXPENSE_DELETED')));
history.push(FINANCES_HOME_URL);
} else {
yield put(enqueueErrorSnackbar(i18n.t('message:EXPENSE.ERROR.UPDATE')));
}
}
}

Expand Down
Loading