add /order-id
This commit is contained in:
1 parent
235ef5ec9e
commit
ac94e0dd8a
7 files changed
+274
No files matched your search
@@ -75,6 +75,48 @@ func (r *repository) List(ctx context.Context, filter paymenthistory.ListFilter)
|
||||
return paymenthistory.ListPaymentHistoryDTO{Count: count, Items: items}, nil
|
||||
}
|
||||
|
||||
// OwnerInfo returns orderID's owning user/branch, so the handler can run
|
||||
// rbac.GuardOrder before returning its logs to a branch/own-scoped caller.
|
||||
func (r *repository) OwnerInfo(ctx context.Context, orderID int64) (*int64, int64, error) {
|
||||
var userID *int64
|
||||
var branchID int64
|
||||
err := r.client.QueryRow(ctx,
|
||||
`SELECT user_id, branch_id FROM visa_master_payment_orders WHERE id = $1 AND deleted_at IS NULL`, orderID,
|
||||
).Scan(&userID, &branchID)
|
||||
return userID, branchID, err
|
||||
}
|
||||
|
||||
func (r *repository) Logs(ctx context.Context, orderID int64) ([]paymenthistory.PaymentLogDTO, error) {
|
||||
rows, err := r.client.Query(ctx,
|
||||
`SELECT l.id, l.order_id, l.step, l.detail, l.created_by, `+shared.UserDisplaySQL+`, l.created_at
|
||||
FROM visa_master_payment_logs l
|
||||
LEFT JOIN users u ON u.id = l.created_by
|
||||
WHERE l.order_id = $1
|
||||
ORDER BY l.id ASC`,
|
||||
orderID,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
items := []paymenthistory.PaymentLogDTO{}
|
||||
for rows.Next() {
|
||||
var item paymenthistory.PaymentLogDTO
|
||||
if err := rows.Scan(
|
||||
&item.Id, &item.OrderId, &item.Step, &item.Detail, &item.CreatedById, &item.CreatedByName, &item.CreatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, item)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return items, nil
|
||||
}
|
||||
|
||||
func buildListQuery(filter paymenthistory.ListFilter) (whereClause string, args []interface{}) {
|
||||
conditions := []string{"p.deleted_at IS NULL", "o.deleted_at IS NULL"}
|
||||
|
||||
|
||||
Reference in new issue
Block a user