Files
orion/app/modules/loyalty/schemas/pin.py
Samir Boulahtit 6161d69ba2 feat(loyalty): cross-persona page alignment with shared components
Align loyalty pages across admin, merchant, and store personas so each
sees the same page set scoped to their access level. Admin acts as a
superset of merchant with "on behalf" capabilities.

New pages:
- Store: Staff PINs management (CRUD)
- Merchant: Cards, Card Detail, Transactions, Staff PINs (CRUD), Settings (read-only)
- Admin: Merchant Cards, Card Detail, Transactions, PINs (read-only)

Architecture:
- 4 shared Jinja2 partials (cards-list, card-detail, transactions, pins)
- 4 shared JS factory modules parameterized by apiPrefix/scope
- Persona templates are thin wrappers including shared partials
- PinDetailResponse schema for cross-store PIN listings

API: 17 new endpoints (11 merchant, 6 admin on-behalf)
Tests: 38 new integration tests, arch-check green
i18n: ~130 new keys across en/fr/de/lb
Docs: pages-and-navigation.md with full page matrix

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-22 19:28:07 +01:00

113 lines
2.4 KiB
Python

# app/modules/loyalty/schemas/pin.py
"""
Pydantic schemas for staff PIN operations.
"""
from datetime import datetime
from pydantic import BaseModel, ConfigDict, Field
class PinCreate(BaseModel):
"""Schema for creating a staff PIN."""
name: str = Field(
...,
min_length=1,
max_length=100,
description="Staff member name",
)
staff_id: str | None = Field(
None,
max_length=50,
description="Optional employee ID",
)
pin: str = Field(
...,
min_length=4,
max_length=6,
pattern="^[0-9]+$",
description="4-6 digit PIN",
)
class PinUpdate(BaseModel):
"""Schema for updating a staff PIN."""
model_config = ConfigDict(from_attributes=True)
name: str | None = Field(
None,
min_length=1,
max_length=100,
)
staff_id: str | None = Field(
None,
max_length=50,
)
pin: str | None = Field(
None,
min_length=4,
max_length=6,
pattern="^[0-9]+$",
description="New PIN (if changing)",
)
is_active: bool | None = None
class PinResponse(BaseModel):
"""Schema for staff PIN response (never includes actual PIN)."""
model_config = ConfigDict(from_attributes=True)
id: int
name: str
staff_id: str | None = None
is_active: bool
is_locked: bool = False
locked_until: datetime | None = None
last_used_at: datetime | None = None
created_at: datetime
class PinListResponse(BaseModel):
"""Schema for listing staff PINs."""
pins: list[PinResponse]
total: int
class PinDetailResponse(PinResponse):
"""Extended PIN response including store context for cross-store listings."""
store_id: int | None = None
store_name: str | None = None
class PinDetailListResponse(BaseModel):
"""Schema for listing staff PINs with store context."""
pins: list[PinDetailResponse]
total: int
class PinVerifyRequest(BaseModel):
"""Schema for verifying a staff PIN."""
pin: str = Field(
...,
min_length=4,
max_length=6,
pattern="^[0-9]+$",
description="PIN to verify",
)
class PinVerifyResponse(BaseModel):
"""Schema for PIN verification response."""
valid: bool
staff_name: str | None = None
remaining_attempts: int | None = None
locked_until: datetime | None = None