Pass amount as string and add transaction correctly
This commit is contained in:
@ -13,8 +13,8 @@ import (
|
||||
)
|
||||
|
||||
type ReconcileTransactionsRequest struct {
|
||||
TransactionIDs []uuid.UUID `json:"transactionIds"`
|
||||
ReconcilationTransactionAmount numeric.Numeric `json:"reconciliationTransactionAmount"`
|
||||
TransactionIDs []uuid.UUID `json:"transactionIds"`
|
||||
ReconcilationTransactionAmount string `json:"reconciliationTransactionAmount"`
|
||||
}
|
||||
|
||||
type ReconcileTransactionsResponse struct {
|
||||
@ -37,6 +37,13 @@ func (h *Handler) reconcileTransactions(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
var amount numeric.Numeric
|
||||
err = amount.Set(request.ReconcilationTransactionAmount)
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusBadRequest, fmt.Errorf("parse request: %w", err))
|
||||
return
|
||||
}
|
||||
|
||||
tx, err := h.Service.BeginTx(c.Request.Context(), &sql.TxOptions{})
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("begin tx: %w", err))
|
||||
@ -52,7 +59,7 @@ func (h *Handler) reconcileTransactions(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
reconciliationTransaction, err := h.CreateReconcilationTransaction(request, accountUUID, db, c)
|
||||
reconciliationTransaction, err := h.CreateReconcilationTransaction(amount, accountUUID, db, c)
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("insert new transaction: %w", err))
|
||||
return
|
||||
@ -70,15 +77,15 @@ func (h *Handler) reconcileTransactions(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
func (*Handler) CreateReconcilationTransaction(request ReconcileTransactionsRequest, accountUUID uuid.UUID, db *postgres.Queries, c *gin.Context) (*postgres.DisplayTransaction, error) {
|
||||
if request.ReconcilationTransactionAmount.IsZero() {
|
||||
func (*Handler) CreateReconcilationTransaction(amount numeric.Numeric, accountUUID uuid.UUID, db *postgres.Queries, c *gin.Context) (*postgres.DisplayTransaction, error) {
|
||||
if amount.IsZero() {
|
||||
return nil, nil //nolint: nilnil
|
||||
}
|
||||
|
||||
createTransaction := postgres.CreateTransactionParams{
|
||||
Date: time.Now(),
|
||||
Memo: "Reconciliation Transaction",
|
||||
Amount: request.ReconcilationTransactionAmount,
|
||||
Amount: amount,
|
||||
AccountID: accountUUID,
|
||||
Status: "Reconciled",
|
||||
}
|
||||
|
Reference in New Issue
Block a user