From 835b3b7b8b0e5adb429b73211273459d5f4080eb Mon Sep 17 00:00:00 2001 From: MaysWind Date: Fri, 15 Nov 2024 00:34:46 +0800 Subject: [PATCH] not need balance time field in parent account --- pkg/api/accounts.go | 10 ++++++++++ pkg/errs/account.go | 1 + pkg/models/account.go | 2 +- src/locales/en.json | 1 + src/locales/zh_Hans.json | 1 + src/stores/account.js | 4 +++- 6 files changed, 17 insertions(+), 2 deletions(-) diff --git a/pkg/api/accounts.go b/pkg/api/accounts.go index 09ee69b4..69956937 100644 --- a/pkg/api/accounts.go +++ b/pkg/api/accounts.go @@ -169,6 +169,11 @@ func (a *AccountsApi) AccountCreateHandler(c *core.WebContext) (any, *errs.Error log.Warnf(c, "[accounts.AccountCreateHandler] account cannot set currency placeholder") return nil, errs.ErrAccountCurrencyInvalid } + + if accountCreateReq.Balance != 0 && accountCreateReq.BalanceTime <= 0 { + log.Warnf(c, "[accounts.AccountCreateHandler] account balance time is not set") + return nil, errs.ErrAccountBalanceTimeNotSet + } } else if accountCreateReq.Type == models.ACCOUNT_TYPE_MULTI_SUB_ACCOUNTS { if len(accountCreateReq.SubAccounts) < 1 { log.Warnf(c, "[accounts.AccountCreateHandler] account does not have any sub-accounts") @@ -202,6 +207,11 @@ func (a *AccountsApi) AccountCreateHandler(c *core.WebContext) (any, *errs.Error log.Warnf(c, "[accounts.AccountCreateHandler] sub-account cannot set currency placeholder") return nil, errs.ErrAccountCurrencyInvalid } + + if subAccount.Balance != 0 && subAccount.BalanceTime <= 0 { + log.Warnf(c, "[accounts.AccountCreateHandler] sub-account balance time is not set") + return nil, errs.ErrAccountBalanceTimeNotSet + } } } else { log.Warnf(c, "[accounts.AccountCreateHandler] account type invalid, type is %d", accountCreateReq.Type) diff --git a/pkg/errs/account.go b/pkg/errs/account.go index c4344521..816ebfee 100644 --- a/pkg/errs/account.go +++ b/pkg/errs/account.go @@ -19,4 +19,5 @@ var ( 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") + ErrAccountBalanceTimeNotSet = NewNormalError(NormalSubcategoryAccount, 15, http.StatusBadRequest, "account balance time is not set") ) diff --git a/pkg/models/account.go b/pkg/models/account.go index 6b5e244c..a596bfb9 100644 --- a/pkg/models/account.go +++ b/pkg/models/account.go @@ -82,7 +82,7 @@ type AccountCreateRequest struct { Color string `json:"color" binding:"required,len=6,validHexRGBColor"` Currency string `json:"currency" binding:"required,len=3,validCurrency"` Balance int64 `json:"balance"` - BalanceTime int64 `json:"balanceTime" binding:"required,min=1"` + BalanceTime int64 `json:"balanceTime"` Comment string `json:"comment" binding:"max=255"` SubAccounts []*AccountCreateRequest `json:"subAccounts" binding:"omitempty"` ClientSessionId string `json:"clientSessionId"` diff --git a/src/locales/en.json b/src/locales/en.json index 8003a138..b8713e08 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -1058,6 +1058,7 @@ "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", + "account balance time is not set": "Account balance time is not set", "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.json b/src/locales/zh_Hans.json index 7c71b834..faa9a89e 100644 --- a/src/locales/zh_Hans.json +++ b/src/locales/zh_Hans.json @@ -1058,6 +1058,7 @@ "destination account not found": "目标账户不存在", "account is in use and cannot be deleted": "账户正在被使用,无法删除", "account category is invalid": "账户分类无效", + "account balance time is not set": "账户余额时间没有设置", "transaction id is invalid": "交易ID无效", "transaction not found": "交易不存在", "transaction type is invalid": "交易类型无效", diff --git a/src/stores/account.js b/src/stores/account.js index 974ddb0e..d153bc20 100644 --- a/src/stores/account.js +++ b/src/stores/account.js @@ -791,7 +791,9 @@ export const useAccountsStore = defineStore('accounts', { submitAccount.id = account.id; submitAccount.hidden = !account.visible; } else { - submitAccount.balanceTime = account.balanceTime; + if (account.type === accountConstants.allAccountTypes.SingleAccount) { + submitAccount.balanceTime = account.balanceTime; + } } const oldAccount = submitAccount.id ? self.allAccountsMap[submitAccount.id] : null;