From 6d331c873b37c2652525464701518fd6455b49b2 Mon Sep 17 00:00:00 2001 From: MaysWind Date: Thu, 1 Aug 2024 00:17:17 +0800 Subject: [PATCH] check whether account category is valid when creating account --- pkg/api/accounts.go | 10 ++++++++++ pkg/errs/account.go | 1 + pkg/models/cron_task_lock.go | 1 + src/locales/en.js | 1 + src/locales/zh_Hans.js | 1 + 5 files changed, 14 insertions(+) create mode 100644 pkg/models/cron_task_lock.go diff --git a/pkg/api/accounts.go b/pkg/api/accounts.go index 625f42e8..ed823a7f 100644 --- a/pkg/api/accounts.go +++ b/pkg/api/accounts.go @@ -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) diff --git a/pkg/errs/account.go b/pkg/errs/account.go index c7fe7311..c4344521 100644 --- a/pkg/errs/account.go +++ b/pkg/errs/account.go @@ -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") ) diff --git a/pkg/models/cron_task_lock.go b/pkg/models/cron_task_lock.go new file mode 100644 index 00000000..2640e7f9 --- /dev/null +++ b/pkg/models/cron_task_lock.go @@ -0,0 +1 @@ +package models diff --git a/src/locales/en.js b/src/locales/en.js index 630d26e0..8464947d 100644 --- a/src/locales/en.js +++ b/src/locales/en.js @@ -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', diff --git a/src/locales/zh_Hans.js b/src/locales/zh_Hans.js index c82b2532..c54977ef 100644 --- a/src/locales/zh_Hans.js +++ b/src/locales/zh_Hans.js @@ -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': '交易类型无效',