Initial Switch to V2. Completely Overhauled Backend, Frontend and General Structure.
This commit is contained in:
@@ -157,6 +157,33 @@ async def update_staff_password(staff_id: str, new_password: str, current_user_r
|
||||
return {"message": "Password updated successfully"}
|
||||
|
||||
|
||||
async def get_preferences(staff_id: str) -> dict:
|
||||
"""Return the ui_prefs map for a staff member, defaulting to {} if not set."""
|
||||
db = get_db()
|
||||
doc = db.collection("admin_users").document(staff_id).get()
|
||||
if not doc.exists:
|
||||
raise NotFoundError("Staff member not found")
|
||||
return doc.to_dict().get("ui_prefs", {})
|
||||
|
||||
|
||||
async def update_preferences(staff_id: str, page_key: str, prefs: dict) -> dict:
|
||||
"""Merge a page-level preferences dict into ui_prefs.<page_key> on the staff document.
|
||||
Only the supplied keys are overwritten — other keys in the same page block survive.
|
||||
"""
|
||||
db = get_db()
|
||||
doc_ref = db.collection("admin_users").document(staff_id)
|
||||
doc = doc_ref.get()
|
||||
if not doc.exists:
|
||||
raise NotFoundError("Staff member not found")
|
||||
|
||||
existing_prefs = doc.to_dict().get("ui_prefs", {})
|
||||
page_prefs = {**existing_prefs.get(page_key, {}), **prefs}
|
||||
existing_prefs[page_key] = page_prefs
|
||||
|
||||
doc_ref.update({"ui_prefs": existing_prefs})
|
||||
return existing_prefs
|
||||
|
||||
|
||||
async def delete_staff(staff_id: str, current_user_role: str, current_user_id: str) -> dict:
|
||||
db = get_db()
|
||||
doc_ref = db.collection("admin_users").document(staff_id)
|
||||
|
||||
Reference in New Issue
Block a user