feat: foundations for the manager conversion (platform-v2 step 6.1)

- Backend: every HTTPException in routers/ is an error code now (260 raises, ~105 new codes,
  texts in en + el); XeniaError(detail=...) keeps the three v1-shaped answers old pages read;
  bad / unknown tokens answer auth.session_ended; test_errors refuses new HTTPExceptions.
- Manager: v2.json is the list of pages on the v2 rules: scripts/lint.mjs lints them,
  tests/v2-guards.test.mjs refuses Greek and colour literals, `strict` paths make
  set-state-in-effect an error.
- src/live/useLiveQuery.js (react-query + live events + refresh on reconnect); Signed in now
  uses it.
- Dead manager files removed (3.1k lines unreachable from main.jsx).
- Tests: backend 544 passed, manager unit 33, run-all (no Android) passed (manager's live
  bell check passed on a rerun).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-18 04:31:36 +02:00
co-authored by Claude Opus 5.5
parent 218a6c9c5e
commit 2dc5da446e
48 changed files with 918 additions and 3498 deletions
+25 -24
View File
@@ -1,6 +1,6 @@
from core.access.check import holds
from core.timeutil import utcnow
from fastapi import APIRouter, Depends, HTTPException, status
from fastapi import APIRouter, Depends, status
from sqlalchemy.orm import Session
from typing import Optional
from datetime import datetime, timezone
@@ -13,6 +13,7 @@ from models.settings import PosSettings
from models.user import User
from schemas.shift import StartShiftRequest, EndShiftRequest
from routers.deps import get_current_user, require_manager
from core.errors import XeniaError
router = APIRouter()
@@ -163,25 +164,25 @@ def start_shift(
if target_id and target_id != user.id:
if not holds(user, "core.dashboard.access"):
raise HTTPException(status_code=403, detail="Only managers can start shifts for other staff")
raise XeniaError("shift.others_need_manager")
target = db.query(User).filter(User.id == target_id, User.is_active == True).first()
if not target:
raise HTTPException(status_code=404, detail="Staff member not found")
raise XeniaError("staff.not_found")
else:
target_id = user.id
if not holds(user, "core.dashboard.access") and _get_setting(db, "shifts.waiter_self_start") != "true":
raise HTTPException(status_code=403, detail="Shift start requires manager confirmation")
raise XeniaError("shift.start_needs_manager")
active_day = db.query(BusinessDay).filter(BusinessDay.status == "open").first()
if not active_day:
raise HTTPException(status_code=400, detail="No open business day — manager must open the restaurant first")
raise XeniaError("business_day.closed", status=400)
existing = db.query(WaiterShift).filter(
WaiterShift.waiter_id == target_id,
WaiterShift.ended_at == None,
).first()
if existing:
raise HTTPException(status_code=400, detail="Waiter already has an active shift")
raise XeniaError("shift.already_active")
target_user = db.query(User).filter(User.id == target_id).first()
shift = WaiterShift(
@@ -203,14 +204,14 @@ def end_shift(
user: User = Depends(get_current_user),
):
if not holds(user, "core.dashboard.access") and _get_setting(db, "shifts.waiter_self_end") != "true":
raise HTTPException(status_code=403, detail="Shift end requires manager confirmation")
raise XeniaError("shift.end_needs_manager")
shift = db.query(WaiterShift).filter(
WaiterShift.waiter_id == user.id,
WaiterShift.ended_at == None,
).first()
if not shift:
raise HTTPException(status_code=404, detail="No active shift found")
raise XeniaError("shift.none_active")
now = utcnow()
total = compute_shift_total(shift.id, db)
@@ -240,22 +241,22 @@ def manager_start_shift(
user: User = Depends(require_manager),
):
if not body.waiter_id:
raise HTTPException(status_code=400, detail="waiter_id is required")
raise XeniaError("validation.missing", field='waiter_id')
target = db.query(User).filter(User.id == body.waiter_id, User.is_active == True).first()
if not target:
raise HTTPException(status_code=404, detail="Waiter not found")
raise XeniaError("staff.not_found")
active_day = db.query(BusinessDay).filter(BusinessDay.status == "open").first()
if not active_day:
raise HTTPException(status_code=400, detail="No open business day")
raise XeniaError("business_day.none_open", status=400)
existing = db.query(WaiterShift).filter(
WaiterShift.waiter_id == body.waiter_id,
WaiterShift.ended_at == None,
).first()
if existing:
raise HTTPException(status_code=400, detail="Waiter already has an active shift")
raise XeniaError("shift.already_active")
shift = WaiterShift(
waiter_id=body.waiter_id,
@@ -281,7 +282,7 @@ def manager_end_shift(
WaiterShift.ended_at == None,
).first()
if not shift:
raise HTTPException(status_code=404, detail="Active shift not found")
raise XeniaError("shift.none_active")
now = utcnow()
total = compute_shift_total(shift.id, db)
@@ -312,17 +313,17 @@ def start_break(
):
shift = db.query(WaiterShift).filter(WaiterShift.id == shift_id).first()
if not shift:
raise HTTPException(status_code=404, detail="Shift not found")
raise XeniaError("shift.not_found")
if shift.waiter_id != user.id and not holds(user, "core.dashboard.access"):
raise HTTPException(status_code=403, detail="Access denied")
raise XeniaError("shift.not_yours")
if shift.ended_at:
raise HTTPException(status_code=400, detail="Shift already ended")
raise XeniaError("shift.ended")
open_break = db.query(ShiftBreak).filter(
ShiftBreak.shift_id == shift_id, ShiftBreak.ended_at == None
).first()
if open_break:
raise HTTPException(status_code=400, detail="Break already in progress")
raise XeniaError("shift.on_break")
b = ShiftBreak(shift_id=shift_id)
db.add(b)
@@ -339,15 +340,15 @@ def end_break(
):
shift = db.query(WaiterShift).filter(WaiterShift.id == shift_id).first()
if not shift:
raise HTTPException(status_code=404, detail="Shift not found")
raise XeniaError("shift.not_found")
if shift.waiter_id != user.id and not holds(user, "core.dashboard.access"):
raise HTTPException(status_code=403, detail="Access denied")
raise XeniaError("shift.not_yours")
open_break = db.query(ShiftBreak).filter(
ShiftBreak.shift_id == shift_id, ShiftBreak.ended_at == None
).first()
if not open_break:
raise HTTPException(status_code=404, detail="No active break found")
raise XeniaError("shift.no_break")
open_break.ended_at = utcnow()
db.commit()
@@ -382,7 +383,7 @@ def get_shift(
):
shift = db.query(WaiterShift).filter(WaiterShift.id == shift_id).first()
if not shift:
raise HTTPException(status_code=404, detail="Shift not found")
raise XeniaError("shift.not_found")
return _enrich_shift(shift, db)
@@ -398,9 +399,9 @@ def delete_shift(
shift = db.query(WaiterShift).filter(WaiterShift.id == shift_id).first()
if not shift:
raise HTTPException(status_code=404, detail="Shift not found")
raise XeniaError("shift.not_found")
if shift.ended_at is None:
raise HTTPException(status_code=400, detail="Cannot delete an active shift — end it first")
raise XeniaError("shift.delete_active")
# Find all orders opened during this shift's time window by this waiter
orders = db.query(Order).filter(
@@ -440,7 +441,7 @@ def get_shift_summary(
shift = db.query(WaiterShift).filter(WaiterShift.id == shift_id).first()
if not shift:
raise HTTPException(status_code=404, detail="Shift not found")
raise XeniaError("shift.not_found")
waiter_id = shift.waiter_id