feat(transaction): #66 refine inputs
Some checks failed
Build Docker Image / Build-Docker-Image (push) Failing after 4m55s
Some checks failed
Build Docker Image / Build-Docker-Image (push) Failing after 4m55s
This commit is contained in:
@@ -83,9 +83,9 @@ func (s TransactionImpl) Update(user *types.User, input types.TransactionInput)
|
||||
return nil, fmt.Errorf("could not parse Id: %w", ErrBadRequest)
|
||||
}
|
||||
|
||||
var transaction *types.Transaction
|
||||
err = s.db.Select(transaction, `SELECT * FROM "transaction" WHERE user_id = ? AND id = ?`, user.Id, uuid)
|
||||
err = db.TransformAndLogDbError("transaction Get", nil, err)
|
||||
transaction := &types.Transaction{}
|
||||
err = s.db.Get(transaction, `SELECT * FROM "transaction" WHERE user_id = ? AND id = ?`, user.Id, uuid)
|
||||
err = db.TransformAndLogDbError("transaction Update", nil, err)
|
||||
if err != nil {
|
||||
if err == db.ErrNotFound {
|
||||
return nil, fmt.Errorf("transaction %v not found: %w", input.Id, ErrBadRequest)
|
||||
@@ -99,7 +99,7 @@ func (s TransactionImpl) Update(user *types.User, input types.TransactionInput)
|
||||
}
|
||||
|
||||
r, err := s.db.NamedExec(`
|
||||
UPDATE transaction
|
||||
UPDATE "transaction"
|
||||
SET
|
||||
account_id = :account_id,
|
||||
treasure_chest_id = :treasure_chest_id,
|
||||
@@ -182,8 +182,8 @@ func (s TransactionImpl) validateAndEnrichTransaction(transaction *types.Transac
|
||||
|
||||
var (
|
||||
id uuid.UUID
|
||||
accountUuid uuid.UUID
|
||||
treasureChestUuid uuid.UUID
|
||||
accountUuid *uuid.UUID
|
||||
treasureChestUuid *uuid.UUID
|
||||
createdAt time.Time
|
||||
createdBy uuid.UUID
|
||||
updatedAt *time.Time
|
||||
@@ -210,12 +210,13 @@ func (s TransactionImpl) validateAndEnrichTransaction(transaction *types.Transac
|
||||
}
|
||||
|
||||
if input.AccountId != "" {
|
||||
accountUuid, err = uuid.Parse(input.AccountId)
|
||||
temp, err := uuid.Parse(input.AccountId)
|
||||
if err != nil {
|
||||
log.Error("transaction validate: %v", err)
|
||||
return nil, fmt.Errorf("could not parse accountId: %w", ErrBadRequest)
|
||||
}
|
||||
err = s.db.Select(&rowCount, `SELECT COUNT(*) FROM account WHERE id = ? AND user_id = ?`, accountUuid, userId)
|
||||
accountUuid = &temp
|
||||
err = s.db.Get(&rowCount, `SELECT COUNT(*) FROM account WHERE id = ? AND user_id = ?`, accountUuid, userId)
|
||||
err = db.TransformAndLogDbError("transaction validate", nil, err)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -228,12 +229,13 @@ func (s TransactionImpl) validateAndEnrichTransaction(transaction *types.Transac
|
||||
}
|
||||
|
||||
if input.TreasureChestId != "" {
|
||||
treasureChestUuid, err = uuid.Parse(input.TreasureChestId)
|
||||
temp, err := uuid.Parse(input.TreasureChestId)
|
||||
if err != nil {
|
||||
log.Error("transaction validate: %v", err)
|
||||
return nil, fmt.Errorf("could not parse treasureChestId: %w", ErrBadRequest)
|
||||
}
|
||||
err = s.db.Select(&rowCount, `SELECT COUNT(*) FROM treasure_chest WHERE id = ? AND user_id = ?`, accountUuid, userId)
|
||||
treasureChestUuid = &temp
|
||||
err = s.db.Get(&rowCount, `SELECT COUNT(*) FROM treasure_chest WHERE id = ? AND user_id = ?`, treasureChestUuid, userId)
|
||||
err = db.TransformAndLogDbError("transaction validate", nil, err)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -276,8 +278,8 @@ func (s TransactionImpl) validateAndEnrichTransaction(transaction *types.Transac
|
||||
Id: id,
|
||||
UserId: userId,
|
||||
|
||||
AccountId: &accountUuid,
|
||||
TreasureChestId: &treasureChestUuid,
|
||||
AccountId: accountUuid,
|
||||
TreasureChestId: treasureChestUuid,
|
||||
Value: valueInt,
|
||||
Timestamp: timestampTime,
|
||||
Note: input.Note,
|
||||
|
||||
Reference in New Issue
Block a user