mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-14 15:07:33 +08:00
code refactor
This commit is contained in:
@@ -278,13 +278,17 @@ func (s *AccountService) DeleteAccount(uid int64, accountId int64) error {
|
||||
|
||||
exists, err := sess.Cols("uid", "deleted", "source_account_id").Where("uid=? AND deleted=?", uid, false).In("source_account_id", accountAndSubAccountIds).Limit(1).Exist(&models.Transaction{})
|
||||
|
||||
if exists {
|
||||
if err != nil {
|
||||
return err
|
||||
} else if exists {
|
||||
return errs.ErrAccountInUseCannotBeDeleted
|
||||
}
|
||||
|
||||
exists, err = sess.Cols("uid", "deleted", "destination_account_id").Where("uid=? AND deleted=?", uid, false).In("destination_account_id", accountAndSubAccountIds).Limit(1).Exist(&models.Transaction{})
|
||||
|
||||
if exists {
|
||||
if err != nil {
|
||||
return err
|
||||
} else if exists {
|
||||
return errs.ErrAccountInUseCannotBeDeleted
|
||||
}
|
||||
|
||||
|
||||
@@ -248,6 +248,10 @@ func (s *TokenService) createToken(user *models.User, tokenType core.TokenType,
|
||||
jwtToken := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
|
||||
tokenString, err := jwtToken.SignedString([]byte(tokenRecord.Secret))
|
||||
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
err = s.createTokenRecord(tokenRecord)
|
||||
|
||||
if err != nil {
|
||||
|
||||
@@ -286,7 +286,9 @@ func (s *TransactionCategoryService) DeleteCategory(uid int64, categoryId int64)
|
||||
|
||||
exists, err := sess.Cols("uid", "deleted", "category_id").Where("uid=? AND deleted=?", uid, false).In("category_id", categoryAndSubCategoryIds).Limit(1).Exist(&models.Transaction{})
|
||||
|
||||
if exists {
|
||||
if err != nil {
|
||||
return err
|
||||
} else if exists {
|
||||
return errs.ErrTransactionCategoryInUseCannotBeDeleted
|
||||
}
|
||||
|
||||
|
||||
@@ -214,7 +214,9 @@ func (s *TransactionTagService) DeleteTag(uid int64, tagId int64) error {
|
||||
return s.UserDataDB(uid).DoTransaction(func(sess *xorm.Session) error {
|
||||
exists, err := sess.Cols("uid", "tag_id").Where("uid=? AND tag_id=?", uid, tagId).Limit(1).Exist(&models.TransactionTagIndex{})
|
||||
|
||||
if exists {
|
||||
if err != nil {
|
||||
return err
|
||||
} else if exists {
|
||||
return errs.ErrTransactionTagInUseCannotBeDeleted
|
||||
}
|
||||
|
||||
|
||||
@@ -465,6 +465,10 @@ func (s *TransactionService) ModifyTransaction(transaction *models.Transaction,
|
||||
|
||||
has, err = sess.Where("uid=? AND deleted=? AND transaction_time>=? AND transaction_time<=?", transaction.Uid, false, minTransactionTime, maxTransactionTime).OrderBy("transaction_time desc").Limit(1).Get(sameSecondLatestTransaction)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if has && sameSecondLatestTransaction.TransactionTime < maxTransactionTime-1 {
|
||||
transaction.TransactionTime = sameSecondLatestTransaction.TransactionTime + 1
|
||||
} else if has && sameSecondLatestTransaction.TransactionTime == maxTransactionTime-1 {
|
||||
|
||||
Reference in New Issue
Block a user