Handle new Payees
This commit is contained in:
parent
a6eb2a2253
commit
953d348bed
@ -35,8 +35,6 @@ func (h *Handler) newTransaction(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("%v\n", payload)
|
|
||||||
|
|
||||||
amount := postgres.Numeric{}
|
amount := postgres.Numeric{}
|
||||||
err = amount.Set(payload.Amount)
|
err = amount.Set(payload.Amount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -44,12 +42,29 @@ func (h *Handler) newTransaction(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
payeeID := payload.Payee.ID
|
||||||
|
if !payeeID.Valid && payload.Payee.Name != "" {
|
||||||
|
newPayee := postgres.CreatePayeeParams{
|
||||||
|
Name: payload.Payee.Name,
|
||||||
|
BudgetID: payload.BudgetID,
|
||||||
|
}
|
||||||
|
payee, err := h.Service.CreatePayee(c.Request.Context(), newPayee)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("create payee: %w", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
payeeID = uuid.NullUUID{
|
||||||
|
UUID: payee.ID,
|
||||||
|
Valid: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
newTransaction := postgres.CreateTransactionParams{
|
newTransaction := postgres.CreateTransactionParams{
|
||||||
Memo: payload.Memo,
|
Memo: payload.Memo,
|
||||||
Date: time.Time(payload.Date),
|
Date: time.Time(payload.Date),
|
||||||
Amount: amount,
|
Amount: amount,
|
||||||
AccountID: payload.AccountID,
|
AccountID: payload.AccountID,
|
||||||
PayeeID: payload.Payee.ID,
|
PayeeID: payeeID,
|
||||||
CategoryID: payload.Category.ID,
|
CategoryID: payload.Category.ID,
|
||||||
Status: postgres.TransactionStatus(payload.State),
|
Status: postgres.TransactionStatus(payload.State),
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user