fix: add card detail and store transactions endpoints for loyalty terminal
Some checks failed
Some checks failed
- Fix GET /cards/{card_id} 500 error (program_type → loyalty_type)
- Add GET /transactions endpoint for store-wide recent transactions
- Add get_store_transactions service method (merchant-scoped, store-filterable)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -640,6 +640,31 @@ class CardService:
|
||||
|
||||
return transactions, total
|
||||
|
||||
def get_store_transactions(
|
||||
self,
|
||||
db: Session,
|
||||
merchant_id: int,
|
||||
*,
|
||||
store_id: int | None = None,
|
||||
skip: int = 0,
|
||||
limit: int = 10,
|
||||
) -> tuple[list[LoyaltyTransaction], int]:
|
||||
"""Get recent transactions for a merchant (optionally filtered by store)."""
|
||||
query = (
|
||||
db.query(LoyaltyTransaction)
|
||||
.join(LoyaltyCard, LoyaltyTransaction.card_id == LoyaltyCard.id)
|
||||
.options(joinedload(LoyaltyTransaction.store))
|
||||
.filter(LoyaltyCard.merchant_id == merchant_id)
|
||||
)
|
||||
if store_id:
|
||||
query = query.filter(LoyaltyTransaction.store_id == store_id)
|
||||
|
||||
query = query.order_by(LoyaltyTransaction.transaction_at.desc())
|
||||
total = query.count()
|
||||
transactions = query.offset(skip).limit(limit).all()
|
||||
|
||||
return transactions, total
|
||||
|
||||
def get_customer_transactions_with_store_names(
|
||||
self,
|
||||
db: Session,
|
||||
|
||||
Reference in New Issue
Block a user