mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-14 06:57:35 +08:00
add cannot modify transaction type error
verify old transaction source account and destination account if changed
This commit is contained in:
@@ -17,4 +17,5 @@ var (
|
||||
ErrCannotAddTransactionToHiddenAccount = NewNormalError(NormalSubcategoryTransaction, 10, http.StatusBadRequest, "cannot add transaction to hidden account")
|
||||
ErrCannotModifyTransactionInHiddenAccount = NewNormalError(NormalSubcategoryTransaction, 11, http.StatusBadRequest, "cannot modify transaction of hidden account")
|
||||
ErrCannotDeleteTransactionInHiddenAccount = NewNormalError(NormalSubcategoryTransaction, 12, http.StatusBadRequest, "cannot delete transaction in hidden account")
|
||||
ErrCannotModifyTransactionType = NewNormalError(NormalSubcategoryTransaction, 13, http.StatusBadRequest, "cannot modify transaction type")
|
||||
)
|
||||
|
||||
@@ -394,6 +394,10 @@ func (s *TransactionService) ModifyTransaction(transaction *models.Transaction,
|
||||
return errs.ErrTransactionNotFound
|
||||
}
|
||||
|
||||
if transaction.Type != oldTransaction.Type {
|
||||
return errs.ErrCannotModifyTransactionType
|
||||
}
|
||||
|
||||
if oldTransaction.Type == models.TRANSACTION_TYPE_MODIFY_BALANCE ||
|
||||
oldTransaction.Type == models.TRANSACTION_TYPE_INCOME ||
|
||||
oldTransaction.Type == models.TRANSACTION_TYPE_EXPENSE {
|
||||
@@ -413,6 +417,8 @@ func (s *TransactionService) ModifyTransaction(transaction *models.Transaction,
|
||||
// Get and verify source and destination account (if necessary)
|
||||
sourceAccount := &models.Account{}
|
||||
destinationAccount := &models.Account{}
|
||||
oldSourceAccount := &models.Account{}
|
||||
oldDestinationAccount := &models.Account{}
|
||||
has, err = sess.ID(transaction.SourceAccountId).Where("uid=? AND deleted=?", transaction.Uid, false).Get(sourceAccount)
|
||||
|
||||
if err != nil {
|
||||
@@ -437,6 +443,34 @@ func (s *TransactionService) ModifyTransaction(transaction *models.Transaction,
|
||||
}
|
||||
}
|
||||
|
||||
if transaction.SourceAccountId == oldTransaction.SourceAccountId {
|
||||
oldSourceAccount = sourceAccount
|
||||
} else {
|
||||
has, err = sess.ID(oldTransaction.SourceAccountId).Where("uid=? AND deleted=?", transaction.Uid, false).Get(oldSourceAccount)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !has {
|
||||
return errs.ErrSourceAccountNotFound
|
||||
} else if oldSourceAccount.Hidden {
|
||||
return errs.ErrCannotModifyTransactionInHiddenAccount
|
||||
}
|
||||
}
|
||||
|
||||
if transaction.DestinationAccountId == oldTransaction.DestinationAccountId {
|
||||
oldDestinationAccount = destinationAccount
|
||||
} else {
|
||||
has, err = sess.ID(oldTransaction.DestinationAccountId).Where("uid=? AND deleted=?", transaction.Uid, false).Get(oldDestinationAccount)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !has {
|
||||
return errs.ErrDestinationAccountNotFound
|
||||
} else if oldDestinationAccount.Hidden {
|
||||
return errs.ErrCannotModifyTransactionInHiddenAccount
|
||||
}
|
||||
}
|
||||
|
||||
// Append modified columns and verify
|
||||
if transaction.CategoryId != oldTransaction.CategoryId {
|
||||
if oldTransaction.Type == models.TRANSACTION_TYPE_MODIFY_BALANCE {
|
||||
|
||||
@@ -320,6 +320,7 @@ export default {
|
||||
'cannot add transaction to hidden account': 'You cannot add transaction to an hidden account',
|
||||
'cannot modify transaction of hidden account': 'You cannot modify transaction of an hidden account',
|
||||
'cannot delete transaction in hidden account': 'You cannot delete transaction in an hidden account',
|
||||
'cannot modify transaction type': 'You cannot modify transaction type',
|
||||
'transaction category id is invalid': 'Transaction category ID is invalid',
|
||||
'transaction category not found': 'Transaction category is not found',
|
||||
'transaction category type is invalid': 'Transaction category type is invalid',
|
||||
|
||||
@@ -320,6 +320,7 @@ export default {
|
||||
'cannot add transaction to hidden account': '您不能在隐藏账户中添加交易',
|
||||
'cannot modify transaction of hidden account': '您不能修改隐藏账户中的交易',
|
||||
'cannot delete transaction in hidden account': '您不能删除隐藏账户中的交易',
|
||||
'cannot modify transaction type': '您不能修改交易类型',
|
||||
'transaction category id is invalid': '交易分类ID无效',
|
||||
'transaction category not found': '交易分类不存在',
|
||||
'transaction category type is invalid': '交易分类类型无效',
|
||||
|
||||
Reference in New Issue
Block a user