feat(loyalty): implement Phase 2 - company-wide points system
Complete implementation of loyalty module Phase 2 features: Database & Models: - Add company_id to LoyaltyProgram for chain-wide loyalty - Add company_id to LoyaltyCard for multi-location support - Add CompanyLoyaltySettings model for admin-controlled settings - Add points expiration, welcome bonus, and minimum redemption fields - Add POINTS_EXPIRED, WELCOME_BONUS transaction types Services: - Update program_service for company-based queries - Update card_service with enrollment and welcome bonus - Update points_service with void_points for returns - Update stamp_service for company context - Update pin_service for company-wide operations API Endpoints: - Admin: Program listing with stats, company detail views - Vendor: Terminal operations, card management, settings - Storefront: Customer card/transactions, self-enrollment UI Templates: - Admin: Programs dashboard, company detail, settings - Vendor: Terminal, cards list, card detail, settings, stats, enrollment - Storefront: Dashboard, history, enrollment, success pages Background Tasks: - Point expiration task (daily, based on inactivity) - Wallet sync task (hourly) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
# app/modules/loyalty/schemas/points.py
|
||||
"""
|
||||
Pydantic schemas for points operations.
|
||||
|
||||
Company-based points:
|
||||
- Points earned at any vendor count toward company total
|
||||
- Points can be redeemed at any vendor within the company
|
||||
- Supports voiding points for returns
|
||||
"""
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
@@ -67,6 +72,9 @@ class PointsEarnResponse(BaseModel):
|
||||
points_balance: int
|
||||
total_points_earned: int
|
||||
|
||||
# Location
|
||||
vendor_id: int | None = None
|
||||
|
||||
|
||||
class PointsRedeemRequest(BaseModel):
|
||||
"""Schema for redeeming points for a reward."""
|
||||
@@ -122,3 +130,108 @@ class PointsRedeemResponse(BaseModel):
|
||||
card_number: str
|
||||
points_balance: int
|
||||
total_points_redeemed: int
|
||||
|
||||
# Location
|
||||
vendor_id: int | None = None
|
||||
|
||||
|
||||
class PointsVoidRequest(BaseModel):
|
||||
"""Schema for voiding points (for returns)."""
|
||||
|
||||
card_id: int | None = Field(
|
||||
None,
|
||||
description="Card ID (use this or qr_code)",
|
||||
)
|
||||
qr_code: str | None = Field(
|
||||
None,
|
||||
description="QR code data from card scan",
|
||||
)
|
||||
card_number: str | None = Field(
|
||||
None,
|
||||
description="Card number (manual entry)",
|
||||
)
|
||||
|
||||
# Points to void (use one method)
|
||||
points_to_void: int | None = Field(
|
||||
None,
|
||||
gt=0,
|
||||
description="Number of points to void",
|
||||
)
|
||||
original_transaction_id: int | None = Field(
|
||||
None,
|
||||
description="ID of original transaction to void",
|
||||
)
|
||||
order_reference: str | None = Field(
|
||||
None,
|
||||
max_length=100,
|
||||
description="Order reference to find and void",
|
||||
)
|
||||
|
||||
# Authentication
|
||||
staff_pin: str | None = Field(
|
||||
None,
|
||||
min_length=4,
|
||||
max_length=6,
|
||||
description="Staff PIN for verification",
|
||||
)
|
||||
|
||||
# Required metadata
|
||||
notes: str | None = Field(
|
||||
None,
|
||||
max_length=500,
|
||||
description="Reason for voiding",
|
||||
)
|
||||
|
||||
|
||||
class PointsVoidResponse(BaseModel):
|
||||
"""Schema for points void response."""
|
||||
|
||||
success: bool = True
|
||||
message: str = "Points voided successfully"
|
||||
|
||||
# Void info
|
||||
points_voided: int
|
||||
|
||||
# Card state after void
|
||||
card_id: int
|
||||
card_number: str
|
||||
points_balance: int
|
||||
|
||||
# Location
|
||||
vendor_id: int | None = None
|
||||
|
||||
|
||||
class PointsAdjustRequest(BaseModel):
|
||||
"""Schema for manual points adjustment (admin)."""
|
||||
|
||||
points_delta: int = Field(
|
||||
...,
|
||||
description="Points to add (positive) or remove (negative)",
|
||||
)
|
||||
reason: str = Field(
|
||||
...,
|
||||
min_length=5,
|
||||
max_length=500,
|
||||
description="Reason for adjustment (required)",
|
||||
)
|
||||
staff_pin: str | None = Field(
|
||||
None,
|
||||
min_length=4,
|
||||
max_length=6,
|
||||
description="Staff PIN for verification",
|
||||
)
|
||||
|
||||
|
||||
class PointsAdjustResponse(BaseModel):
|
||||
"""Schema for points adjustment response."""
|
||||
|
||||
success: bool = True
|
||||
message: str = "Points adjusted successfully"
|
||||
|
||||
# Adjustment info
|
||||
points_delta: int
|
||||
|
||||
# Card state after adjustment
|
||||
card_id: int
|
||||
card_number: str
|
||||
points_balance: int
|
||||
|
||||
Reference in New Issue
Block a user