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
+14 -17
View File
@@ -1,6 +1,6 @@
from core.access.check import holds
import json
from fastapi import APIRouter, Depends, HTTPException, status
from fastapi import APIRouter, Depends, status
from pydantic import BaseModel
from sqlalchemy.orm import Session
from typing import List
@@ -239,19 +239,19 @@ def reparent_category(category_id: int, body: CategoryReparentRequest, db: Sessi
"""
cat = db.query(Category).filter(Category.id == category_id).first()
if not cat:
raise HTTPException(status_code=404, detail="Category not found")
raise XeniaError("catalog.category_not_found")
if body.parent_id is not None:
new_parent = db.query(Category).filter(Category.id == body.parent_id).first()
if not new_parent:
raise HTTPException(status_code=404, detail="Target parent category not found")
raise XeniaError("catalog.parent_not_found")
if new_parent.parent_id is not None:
raise HTTPException(status_code=400, detail="Cannot nest more than two levels deep")
raise XeniaError("catalog.too_deep")
if body.parent_id == category_id:
raise HTTPException(status_code=400, detail="A category cannot be its own parent")
raise XeniaError("catalog.own_parent")
# If cat currently has children and is being made a sub, block it
has_children = db.query(Category).filter(Category.parent_id == category_id).count() > 0
if has_children and body.parent_id is not None:
raise HTTPException(status_code=400, detail="Cannot nest a category that has subcategories")
raise XeniaError("catalog.nest_has_children")
# Assign new sort_order at the end of the destination level
sibling_count = db.query(Category).filter(Category.parent_id == body.parent_id).count()
cat.parent_id = body.parent_id
@@ -266,7 +266,7 @@ def reparent_category(category_id: int, body: CategoryReparentRequest, db: Sessi
def update_category(category_id: int, body: CategoryUpdate, db: Session = Depends(get_db), user: User = Depends(require_menu_manager)):
cat = db.query(Category).filter(Category.id == category_id).first()
if not cat:
raise HTTPException(status_code=404, detail="Category not found")
raise XeniaError("catalog.category_not_found")
for field, value in body.model_dump(exclude_none=True, exclude={"media_id"}).items():
setattr(cat, field, value)
if "media_id" in body.model_fields_set:
@@ -281,7 +281,7 @@ def update_category(category_id: int, body: CategoryUpdate, db: Session = Depend
def delete_category(category_id: int, db: Session = Depends(get_db), user: User = Depends(require_menu_manager)):
cat = db.query(Category).filter(Category.id == category_id).first()
if not cat:
raise HTTPException(status_code=404, detail="Category not found")
raise XeniaError("catalog.category_not_found")
from services.catalog import remove_category
remove_category(db, category_id) # its listings go; products whose main category it was get their next one
db.delete(cat)
@@ -428,7 +428,7 @@ def update_product(product_id: int, body: ProductUpdate, db: Session = Depends(g
# system products (the delivery fee line, S.5) are not part of the catalogue
product = db.query(Product).filter(Product.id == product_id, Product.system_key.is_(None)).first()
if not product:
raise HTTPException(status_code=404, detail="Product not found")
raise XeniaError("product.not_found")
scalar_fields = body.model_dump(
exclude_none=True,
exclude={"quick_options", "options", "ingredients", "preference_sets", "cost_breakdown", "prep_zone_ids", "tags", "modifier_groups",
@@ -485,7 +485,7 @@ def create_modifier_group(product_id: int, body: ModifierGroupCreate, db: Sessio
# system products (the delivery fee line, S.5) are not part of the catalogue
product = db.query(Product).filter(Product.id == product_id, Product.system_key.is_(None)).first()
if not product:
raise HTTPException(status_code=404, detail="Product not found")
raise XeniaError("product.not_found")
g = ProductModifierGroup(product_id=product_id, modifier_type=body.modifier_type, name=body.name, sort_order=body.sort_order)
db.add(g)
db.commit()
@@ -498,7 +498,7 @@ def create_modifier_group(product_id: int, body: ModifierGroupCreate, db: Sessio
def update_modifier_group(product_id: int, group_id: int, body: ModifierGroupCreate, db: Session = Depends(get_db), user: User = Depends(require_menu_manager)):
g = db.query(ProductModifierGroup).filter(ProductModifierGroup.id == group_id, ProductModifierGroup.product_id == product_id).first()
if not g:
raise HTTPException(status_code=404, detail="Group not found")
raise XeniaError("catalog.group_not_found")
g.name = body.name
g.sort_order = body.sort_order
db.commit()
@@ -511,7 +511,7 @@ def update_modifier_group(product_id: int, group_id: int, body: ModifierGroupCre
def delete_modifier_group(product_id: int, group_id: int, db: Session = Depends(get_db), user: User = Depends(require_menu_manager)):
g = db.query(ProductModifierGroup).filter(ProductModifierGroup.id == group_id, ProductModifierGroup.product_id == product_id).first()
if not g:
raise HTTPException(status_code=404, detail="Group not found")
raise XeniaError("catalog.group_not_found")
# Un-group all items in this group before deleting
db.query(ProductOption).filter(ProductOption.group_id == group_id).update({"group_id": None})
db.query(ProductIngredient).filter(ProductIngredient.group_id == group_id).update({"group_id": None})
@@ -526,14 +526,11 @@ def delete_product(product_id: int, hard: bool = False, db: Session = Depends(ge
# system products (the delivery fee line, S.5) are not part of the catalogue
product = db.query(Product).filter(Product.id == product_id, Product.system_key.is_(None)).first()
if not product:
raise HTTPException(status_code=404, detail="Product not found")
raise XeniaError("product.not_found")
if hard:
has_orders = db.query(OrderItem).filter(OrderItem.product_id == product_id).first()
if has_orders:
raise HTTPException(
status_code=400,
detail="Cannot permanently delete a product that appears in past orders. Archive it instead."
)
raise XeniaError("product.in_past_orders")
db.delete(product)
else:
# If product has order history, archive it; otherwise hard delete