Delete transaction when amount is zero
This commit is contained in:
parent
ae9e9d34c9
commit
05099e469f
@ -13,10 +13,9 @@ UPDATE transactions
|
||||
SET date = $1,
|
||||
memo = $2,
|
||||
amount = $3,
|
||||
account_id = $4,
|
||||
payee_id = $5,
|
||||
category_id = $6
|
||||
WHERE id = $7;
|
||||
payee_id = $4,
|
||||
category_id = $5
|
||||
WHERE id = $6;
|
||||
|
||||
-- name: DeleteTransaction :exec
|
||||
DELETE FROM transactions
|
||||
|
@ -294,17 +294,15 @@ UPDATE transactions
|
||||
SET date = $1,
|
||||
memo = $2,
|
||||
amount = $3,
|
||||
account_id = $4,
|
||||
payee_id = $5,
|
||||
category_id = $6
|
||||
WHERE id = $7
|
||||
payee_id = $4,
|
||||
category_id = $5
|
||||
WHERE id = $6
|
||||
`
|
||||
|
||||
type UpdateTransactionParams struct {
|
||||
Date time.Time
|
||||
Memo string
|
||||
Amount numeric.Numeric
|
||||
AccountID uuid.UUID
|
||||
PayeeID uuid.NullUUID
|
||||
CategoryID uuid.NullUUID
|
||||
ID uuid.UUID
|
||||
@ -315,7 +313,6 @@ func (q *Queries) UpdateTransaction(ctx context.Context, arg UpdateTransactionPa
|
||||
arg.Date,
|
||||
arg.Memo,
|
||||
arg.Amount,
|
||||
arg.AccountID,
|
||||
arg.PayeeID,
|
||||
arg.CategoryID,
|
||||
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) {
|
||||
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{
|
||||
Memo: payload.Memo,
|
||||
Date: time.Time(payload.Date),
|
||||
Amount: amount,
|
||||
PayeeID: payload.Payee.ID,
|
||||
CategoryID: payload.CategoryID,
|
||||
ID: uuid.MustParse(transactionID),
|
||||
ID: transactionUUID,
|
||||
}
|
||||
|
||||
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 response = await result.json();
|
||||
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