code refactor
This commit is contained in:
@@ -229,11 +229,11 @@ func (a *TransactionCategoriesApi) CategoryModifyHandler(c *core.WebContext) (an
|
||||
return nil, errs.ErrNothingWillBeUpdated
|
||||
}
|
||||
|
||||
if category.ParentCategoryId == 0 && newCategory.ParentCategoryId != 0 {
|
||||
if category.ParentCategoryId == models.LevelOneTransactionCategoryParentId && newCategory.ParentCategoryId != models.LevelOneTransactionCategoryParentId {
|
||||
return nil, errs.Or(err, errs.ErrNotAllowChangePrimaryTransactionCategoryToSecondary)
|
||||
}
|
||||
|
||||
if category.ParentCategoryId != 0 && newCategory.ParentCategoryId == 0 {
|
||||
if category.ParentCategoryId != models.LevelOneTransactionCategoryParentId && newCategory.ParentCategoryId == models.LevelOneTransactionCategoryParentId {
|
||||
return nil, errs.Or(err, errs.ErrNotAllowChangeSecondaryTransactionCategoryToPrimary)
|
||||
}
|
||||
|
||||
@@ -256,7 +256,7 @@ func (a *TransactionCategoriesApi) CategoryModifyHandler(c *core.WebContext) (an
|
||||
return nil, errs.Or(err, errs.ErrNotAllowChangePrimaryTransactionType)
|
||||
}
|
||||
|
||||
if toPrimaryCategory.ParentCategoryId != 0 {
|
||||
if toPrimaryCategory.ParentCategoryId != models.LevelOneTransactionCategoryParentId {
|
||||
return nil, errs.Or(err, errs.ErrNotAllowUseSecondaryTransactionAsPrimaryCategory)
|
||||
}
|
||||
}
|
||||
@@ -433,7 +433,7 @@ func (a *TransactionCategoriesApi) getTransactionCategoryListByTypeResponse(cate
|
||||
for i := 0; i < len(categoryResps); i++ {
|
||||
categoryResp := categoryResps[i]
|
||||
|
||||
if categoryResp.ParentId <= models.LevelOneTransactionParentId {
|
||||
if categoryResp.ParentId <= models.LevelOneTransactionCategoryParentId {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -449,7 +449,7 @@ func (a *TransactionCategoriesApi) getTransactionCategoryListByTypeResponse(cate
|
||||
finalCategoryResps := make(models.TransactionCategoryInfoResponseSlice, 0)
|
||||
|
||||
for i := 0; i < len(categoryResps); i++ {
|
||||
if parentId <= 0 && categoryResps[i].ParentId == models.LevelOneTransactionParentId {
|
||||
if parentId <= 0 && categoryResps[i].ParentId == models.LevelOneTransactionCategoryParentId {
|
||||
sort.Sort(categoryResps[i].SubCategories)
|
||||
finalCategoryResps = append(finalCategoryResps, categoryResps[i])
|
||||
} else if parentId > 0 && categoryResps[i].ParentId == parentId {
|
||||
|
||||
@@ -959,7 +959,7 @@ func (l *UserDataCli) checkTransactionCategory(c *core.CliContext, transaction *
|
||||
return errs.ErrTransactionCategoryNotFound
|
||||
}
|
||||
|
||||
if category.ParentCategoryId == models.LevelOneTransactionParentId {
|
||||
if category.ParentCategoryId == models.LevelOneTransactionCategoryParentId {
|
||||
log.CliErrorf(c, "[user_data.checkTransactionCategory] the transaction category \"id:%d\" of transaction \"id:%d\" is not a sub category", transaction.CategoryId, transaction.TransactionId)
|
||||
return errs.ErrOperationFailed
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ func (c *DataTableTransactionDataExporter) getExportedTransactionCategoryName(da
|
||||
return ""
|
||||
}
|
||||
|
||||
if category.ParentCategoryId == 0 {
|
||||
if category.ParentCategoryId == models.LevelOneTransactionCategoryParentId {
|
||||
return dataTableBuilder.ReplaceDelimiters(category.Name)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package models
|
||||
|
||||
// LevelOneTransactionParentId represents the parent id of level-one transaction category
|
||||
const LevelOneTransactionParentId = 0
|
||||
// LevelOneTransactionCategoryParentId represents the parent id of level-one transaction category
|
||||
const LevelOneTransactionCategoryParentId = 0
|
||||
|
||||
// TransactionCategoryType represents transaction category type
|
||||
type TransactionCategoryType byte
|
||||
|
||||
@@ -161,7 +161,7 @@ func (s *TransactionCategoryService) GetMaxDisplayOrder(c core.Context, uid int6
|
||||
}
|
||||
|
||||
category := &models.TransactionCategory{}
|
||||
has, err := s.UserDataDB(uid).NewSession(c).Cols("uid", "deleted", "parent_category_id", "display_order").Where("uid=? AND deleted=? AND type=? AND parent_category_id=?", uid, false, categoryType, models.LevelOneTransactionParentId).OrderBy("display_order desc").Limit(1).Get(category)
|
||||
has, err := s.UserDataDB(uid).NewSession(c).Cols("uid", "deleted", "parent_category_id", "display_order").Where("uid=? AND deleted=? AND type=? AND parent_category_id=?", uid, false, categoryType, models.LevelOneTransactionCategoryParentId).OrderBy("display_order desc").Limit(1).Get(category)
|
||||
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -463,7 +463,7 @@ func (s *TransactionCategoryService) GetSubCategoryNameMapByList(categories []*m
|
||||
for i := 0; i < len(categories); i++ {
|
||||
category := categories[i]
|
||||
|
||||
if category.ParentCategoryId == models.LevelOneTransactionParentId {
|
||||
if category.ParentCategoryId == models.LevelOneTransactionCategoryParentId {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@@ -2191,7 +2191,7 @@ func (s *TransactionService) isCategoryValid(sess *xorm.Session, transaction *mo
|
||||
return errs.ErrCannotUseHiddenTransactionCategory
|
||||
}
|
||||
|
||||
if category.ParentCategoryId < 1 {
|
||||
if category.ParentCategoryId == models.LevelOneTransactionCategoryParentId {
|
||||
return errs.ErrCannotUsePrimaryCategoryForTransaction
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user