check whether account category is valid when creating account

This commit is contained in:
MaysWind
2024-08-01 00:17:17 +08:00
parent a03df7ed36
commit 6d331c873b
5 changed files with 14 additions and 0 deletions
+10
View File
@@ -146,6 +146,11 @@ func (a *AccountsApi) AccountCreateHandler(c *core.Context) (any, *errs.Error) {
return nil, errs.ErrClientTimezoneOffsetInvalid
}
if accountCreateReq.Category < models.ACCOUNT_CATEGORY_CASH || accountCreateReq.Category > models.ACCOUNT_CATEGORY_INVESTMENT {
log.WarnfWithRequestId(c, "[accounts.AccountCreateHandler] account category invalid, category is %d", accountCreateReq.Category)
return nil, errs.ErrAccountCategoryInvalid
}
if accountCreateReq.Type == models.ACCOUNT_TYPE_SINGLE_ACCOUNT {
if len(accountCreateReq.SubAccounts) > 0 {
log.WarnfWithRequestId(c, "[accounts.AccountCreateHandler] account cannot have any sub-accounts")
@@ -275,6 +280,11 @@ func (a *AccountsApi) AccountModifyHandler(c *core.Context) (any, *errs.Error) {
return nil, errs.NewIncompleteOrIncorrectSubmissionError(err)
}
if accountModifyReq.Category < models.ACCOUNT_CATEGORY_CASH || accountModifyReq.Category > models.ACCOUNT_CATEGORY_INVESTMENT {
log.WarnfWithRequestId(c, "[accounts.AccountModifyHandler] account category invalid, category is %d", accountModifyReq.Category)
return nil, errs.ErrAccountCategoryInvalid
}
uid := c.GetCurrentUid()
accountAndSubAccounts, err := a.accounts.GetAccountAndSubAccountsByAccountId(c, uid, accountModifyReq.Id)
+1
View File
@@ -18,4 +18,5 @@ var (
ErrSourceAccountNotFound = NewNormalError(NormalSubcategoryAccount, 11, http.StatusBadRequest, "source account not found")
ErrDestinationAccountNotFound = NewNormalError(NormalSubcategoryAccount, 12, http.StatusBadRequest, "destination account not found")
ErrAccountInUseCannotBeDeleted = NewNormalError(NormalSubcategoryAccount, 13, http.StatusBadRequest, "account is in use and cannot be deleted")
ErrAccountCategoryInvalid = NewNormalError(NormalSubcategoryAccount, 14, http.StatusBadRequest, "account category is invalid")
)
+1
View File
@@ -0,0 +1 @@
package models
+1
View File
@@ -661,6 +661,7 @@ export default {
'source account not found': 'Source account is not found',
'destination account not found': 'Destination account is not found',
'account is in use and cannot be deleted': 'Account is in use and it cannot be deleted',
'account category is invalid': 'Account category is invalid',
'transaction id is invalid': 'Transaction ID is invalid',
'transaction not found': 'Transaction is not found',
'transaction type is invalid': 'Transaction type is invalid',
+1
View File
@@ -661,6 +661,7 @@ export default {
'source account not found': '来源账户不存在',
'destination account not found': '目标账户不存在',
'account is in use and cannot be deleted': '账户正在被使用,无法删除',
'account category is invalid': '账户分类无效',
'transaction id is invalid': '交易ID无效',
'transaction not found': '交易不存在',
'transaction type is invalid': '交易类型无效',