Delete transaction when amount is zero
This commit is contained in:
parent
ae9e9d34c9
commit
05099e469f
@ -13,10 +13,9 @@ UPDATE transactions
|
|||||||
SET date = $1,
|
SET date = $1,
|
||||||
memo = $2,
|
memo = $2,
|
||||||
amount = $3,
|
amount = $3,
|
||||||
account_id = $4,
|
payee_id = $4,
|
||||||
payee_id = $5,
|
category_id = $5
|
||||||
category_id = $6
|
WHERE id = $6;
|
||||||
WHERE id = $7;
|
|
||||||
|
|
||||||
-- name: DeleteTransaction :exec
|
-- name: DeleteTransaction :exec
|
||||||
DELETE FROM transactions
|
DELETE FROM transactions
|
||||||
|
@ -294,17 +294,15 @@ UPDATE transactions
|
|||||||
SET date = $1,
|
SET date = $1,
|
||||||
memo = $2,
|
memo = $2,
|
||||||
amount = $3,
|
amount = $3,
|
||||||
account_id = $4,
|
payee_id = $4,
|
||||||
payee_id = $5,
|
category_id = $5
|
||||||
category_id = $6
|
WHERE id = $6
|
||||||
WHERE id = $7
|
|
||||||
`
|
`
|
||||||
|
|
||||||
type UpdateTransactionParams struct {
|
type UpdateTransactionParams struct {
|
||||||
Date time.Time
|
Date time.Time
|
||||||
Memo string
|
Memo string
|
||||||
Amount numeric.Numeric
|
Amount numeric.Numeric
|
||||||
AccountID uuid.UUID
|
|
||||||
PayeeID uuid.NullUUID
|
PayeeID uuid.NullUUID
|
||||||
CategoryID uuid.NullUUID
|
CategoryID uuid.NullUUID
|
||||||
ID uuid.UUID
|
ID uuid.UUID
|
||||||
@ -315,7 +313,6 @@ func (q *Queries) UpdateTransaction(ctx context.Context, arg UpdateTransactionPa
|
|||||||
arg.Date,
|
arg.Date,
|
||||||
arg.Memo,
|
arg.Memo,
|
||||||
arg.Amount,
|
arg.Amount,
|
||||||
arg.AccountID,
|
|
||||||
arg.PayeeID,
|
arg.PayeeID,
|
||||||
arg.CategoryID,
|
arg.CategoryID,
|
||||||
arg.ID,
|
arg.ID,
|
||||||
|
@ -79,13 +79,22 @@ func (h *Handler) newTransaction(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) UpdateTransaction(payload NewTransactionPayload, amount numeric.Numeric, transactionID string, c *gin.Context) {
|
func (h *Handler) UpdateTransaction(payload NewTransactionPayload, amount numeric.Numeric, transactionID string, c *gin.Context) {
|
||||||
|
transactionUUID := uuid.MustParse(transactionID)
|
||||||
|
if amount.IsZero() {
|
||||||
|
err := h.Service.DeleteTransaction(c.Request.Context(), transactionUUID)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("delete transaction: %w", err))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
editTransaction := postgres.UpdateTransactionParams{
|
editTransaction := postgres.UpdateTransactionParams{
|
||||||
Memo: payload.Memo,
|
Memo: payload.Memo,
|
||||||
Date: time.Time(payload.Date),
|
Date: time.Time(payload.Date),
|
||||||
Amount: amount,
|
Amount: amount,
|
||||||
PayeeID: payload.Payee.ID,
|
PayeeID: payload.Payee.ID,
|
||||||
CategoryID: payload.CategoryID,
|
CategoryID: payload.CategoryID,
|
||||||
ID: uuid.MustParse(transactionID),
|
ID: transactionUUID,
|
||||||
}
|
}
|
||||||
|
|
||||||
err := h.Service.UpdateTransaction(c.Request.Context(), editTransaction)
|
err := h.Service.UpdateTransaction(c.Request.Context(), editTransaction)
|
||||||
|
@ -163,6 +163,11 @@ export const useAccountStore = defineStore("budget/account", {
|
|||||||
const result = await POST("/transaction/new", payload);
|
const result = await POST("/transaction/new", payload);
|
||||||
const response = await result.json();
|
const response = await result.json();
|
||||||
this.CurrentAccount?.Transactions.unshift(response);
|
this.CurrentAccount?.Transactions.unshift(response);
|
||||||
|
},
|
||||||
|
async editTransaction(transactionid : string, payload: string) {
|
||||||
|
const result = await POST("/transaction/" + transactionid, payload);
|
||||||
|
const response = await result.json();
|
||||||
|
this.CurrentAccount?.Transactions.unshift(response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user