Replace hardcoded strings with common constants

This commit is contained in:
Stefan Kostic
2022-02-09 22:17:49 +01:00
parent c74bdf28f4
commit 3152f6f2e6
4 changed files with 37 additions and 24 deletions

View File

@@ -5,6 +5,7 @@ import (
"database/sql"
"math/rand"
"github.com/getAlby/lndhub.go/common"
"github.com/getAlby/lndhub.go/db/models"
"github.com/getAlby/lndhub.go/lib/security"
"github.com/uptrace/bun"
@@ -28,7 +29,12 @@ func (svc *LndhubService) CreateUser(ctx context.Context) (user *models.User, er
if _, err := tx.NewInsert().Model(user).Exec(ctx); err != nil {
return err
}
accountTypes := []string{"incoming", "current", "outgoing", "fees"}
accountTypes := []string{
common.AccountTypeIncoming,
common.AccountTypeCurrent,
common.AccountTypeOutgoing,
common.AccountTypeFees,
}
for _, accountType := range accountTypes {
account := models.Account{UserID: user.ID, Type: accountType}
if _, err := tx.NewInsert().Model(&account).Exec(ctx); err != nil {
@@ -55,7 +61,7 @@ func (svc *LndhubService) FindUser(ctx context.Context, userId int64) (*models.U
func (svc *LndhubService) CurrentUserBalance(ctx context.Context, userId int64) (int64, error) {
var balance int64
account, err := svc.AccountFor(ctx, "current", userId)
account, err := svc.AccountFor(ctx, common.AccountTypeCurrent, userId)
if err != nil {
return balance, err
}
@@ -74,7 +80,7 @@ func (svc *LndhubService) InvoicesFor(ctx context.Context, userId int64, invoice
query := svc.DB.NewSelect().Model(&invoices).Where("user_id = ?", userId)
if invoiceType != "" {
query.Where("type = ? AND state <> ?", invoiceType, "initialized")
query.Where("type = ? AND state <> ?", invoiceType, common.InvoiceStateInitialized)
}
query.OrderExpr("id DESC").Limit(100)
err := query.Scan(ctx)