Improve editing and creating of transactions
This commit is contained in:
parent
faef975f1a
commit
4c6d21c2b4
@ -6,7 +6,7 @@ WHERE id = $1;
|
|||||||
INSERT INTO transactions
|
INSERT INTO transactions
|
||||||
(date, memo, amount, account_id, payee_id, category_id, group_id, status)
|
(date, memo, amount, account_id, payee_id, category_id, group_id, status)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
||||||
RETURNING *;
|
RETURNING id;
|
||||||
|
|
||||||
-- name: UpdateTransaction :exec
|
-- name: UpdateTransaction :exec
|
||||||
UPDATE transactions
|
UPDATE transactions
|
||||||
|
@ -15,7 +15,7 @@ const createTransaction = `-- name: CreateTransaction :one
|
|||||||
INSERT INTO transactions
|
INSERT INTO transactions
|
||||||
(date, memo, amount, account_id, payee_id, category_id, group_id, status)
|
(date, memo, amount, account_id, payee_id, category_id, group_id, status)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
||||||
RETURNING id, date, memo, amount, account_id, category_id, payee_id, group_id, status
|
RETURNING id
|
||||||
`
|
`
|
||||||
|
|
||||||
type CreateTransactionParams struct {
|
type CreateTransactionParams struct {
|
||||||
@ -29,7 +29,7 @@ type CreateTransactionParams struct {
|
|||||||
Status TransactionStatus
|
Status TransactionStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) CreateTransaction(ctx context.Context, arg CreateTransactionParams) (Transaction, error) {
|
func (q *Queries) CreateTransaction(ctx context.Context, arg CreateTransactionParams) (uuid.UUID, error) {
|
||||||
row := q.db.QueryRowContext(ctx, createTransaction,
|
row := q.db.QueryRowContext(ctx, createTransaction,
|
||||||
arg.Date,
|
arg.Date,
|
||||||
arg.Memo,
|
arg.Memo,
|
||||||
@ -40,19 +40,9 @@ func (q *Queries) CreateTransaction(ctx context.Context, arg CreateTransactionPa
|
|||||||
arg.GroupID,
|
arg.GroupID,
|
||||||
arg.Status,
|
arg.Status,
|
||||||
)
|
)
|
||||||
var i Transaction
|
var id uuid.UUID
|
||||||
err := row.Scan(
|
err := row.Scan(&id)
|
||||||
&i.ID,
|
return id, err
|
||||||
&i.Date,
|
|
||||||
&i.Memo,
|
|
||||||
&i.Amount,
|
|
||||||
&i.AccountID,
|
|
||||||
&i.CategoryID,
|
|
||||||
&i.PayeeID,
|
|
||||||
&i.GroupID,
|
|
||||||
&i.Status,
|
|
||||||
)
|
|
||||||
return i, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const deleteAllTransactions = `-- name: DeleteAllTransactions :execrows
|
const deleteAllTransactions = `-- name: DeleteAllTransactions :execrows
|
||||||
|
@ -89,12 +89,12 @@ func (*Handler) CreateReconcilationTransaction(amount numeric.Numeric, accountUU
|
|||||||
AccountID: accountUUID,
|
AccountID: accountUUID,
|
||||||
Status: "Reconciled",
|
Status: "Reconciled",
|
||||||
}
|
}
|
||||||
newTransaction, err := db.CreateTransaction(c.Request.Context(), createTransaction)
|
transactionUUID, err := db.CreateTransaction(c.Request.Context(), createTransaction)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("insert new transaction: %w", err)
|
return nil, fmt.Errorf("insert new transaction: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
transaction, err := db.GetTransaction(c.Request.Context(), newTransaction.ID)
|
transaction, err := db.GetTransaction(c.Request.Context(), transactionUUID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("get created transaction: %w", err)
|
return nil, fmt.Errorf("get created transaction: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -70,11 +70,18 @@ func (h *Handler) newTransaction(c *gin.Context) {
|
|||||||
newTransaction.PayeeID = payeeID
|
newTransaction.PayeeID = payeeID
|
||||||
}
|
}
|
||||||
|
|
||||||
transaction, err := h.Service.CreateTransaction(c.Request.Context(), newTransaction)
|
transactionUUID, err := h.Service.CreateTransaction(c.Request.Context(), newTransaction)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("create transaction: %w", err))
|
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("create transaction: %w", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
transaction, err := h.Service.GetTransaction(c.Request.Context(), transactionUUID)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("get transaction: %w", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
c.JSON(http.StatusOK, transaction)
|
c.JSON(http.StatusOK, transaction)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +107,16 @@ func (h *Handler) UpdateTransaction(payload NewTransactionPayload, amount numeri
|
|||||||
err := h.Service.UpdateTransaction(c.Request.Context(), editTransaction)
|
err := h.Service.UpdateTransaction(c.Request.Context(), editTransaction)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("edit transaction: %w", err))
|
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("edit transaction: %w", err))
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
transaction, err := h.Service.GetTransaction(c.Request.Context(), transactionUUID)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("get transaction: %w", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, transaction)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) CreateTransferForOtherAccount(newTransaction postgres.CreateTransactionParams, amount numeric.Numeric, payload NewTransactionPayload, c *gin.Context) error {
|
func (h *Handler) CreateTransferForOtherAccount(newTransaction postgres.CreateTransactionParams, amount numeric.Numeric, payload NewTransactionPayload, c *gin.Context) error {
|
||||||
|
@ -8,6 +8,8 @@ const props = defineProps<{
|
|||||||
transactionid: string
|
transactionid: string
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits(["save"]);
|
||||||
|
|
||||||
const accountStore = useAccountStore();
|
const accountStore = useAccountStore();
|
||||||
const TX = accountStore.Transactions.get(props.transactionid)!;
|
const TX = accountStore.Transactions.get(props.transactionid)!;
|
||||||
const payeeType = ref<string|undefined>(undefined);
|
const payeeType = ref<string|undefined>(undefined);
|
||||||
@ -28,6 +30,7 @@ const payload = computed(() => JSON.stringify({
|
|||||||
function saveTransaction(e: MouseEvent) {
|
function saveTransaction(e: MouseEvent) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
accountStore.editTransaction(TX.ID, payload.value);
|
accountStore.editTransaction(TX.ID, payload.value);
|
||||||
|
emit('save');
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ const Reconciling = computed(() => useAccountStore().Reconciling);
|
|||||||
<input type="checkbox" v-model="transaction.Reconciled" />
|
<input type="checkbox" v-model="transaction.Reconciled" />
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<TransactionEditRow v-if="edit" :transactionid="transaction.ID" />
|
<TransactionEditRow v-if="edit" :transactionid="transaction.ID" @save="edit = false" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
@ -206,12 +206,13 @@ export const useAccountStore = defineStore("budget/account", {
|
|||||||
async saveTransaction(payload: string) {
|
async saveTransaction(payload: string) {
|
||||||
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.AddTransaction(this.CurrentAccount!, response);
|
||||||
|
this.CurrentAccount?.Transactions.unshift(response.ID);
|
||||||
},
|
},
|
||||||
async editTransaction(transactionid: string, payload: string) {
|
async editTransaction(transactionid: string, payload: string) {
|
||||||
const result = await POST("/transaction/" + transactionid, payload);
|
const result = await POST("/transaction/" + transactionid, payload);
|
||||||
const response = await result.json();
|
const response = await result.json();
|
||||||
this.CurrentAccount?.Transactions.unshift(response);
|
this.AddTransaction(this.CurrentAccount!, response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user