From e531cea8a49b85ac0dce8e016ccaf3d8cdda22b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?IT=E7=8B=97?= Date: Tue, 21 Jul 2026 13:10:46 +0800 Subject: [PATCH] Add leaves reset, split holidays/leave resets, support multi-table reset --- backend/main.py | 18 ++++++++++++------ frontend/src/pages/Settings.jsx | 10 ++++++++-- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/backend/main.py b/backend/main.py index 8800603..08db882 100644 --- a/backend/main.py +++ b/backend/main.py @@ -1936,19 +1936,25 @@ async def reset_section( db: Session = Depends(get_db), ): """Reset (truncate) a specific data section. Creates auto-backup first.""" - valid = {"attendance": AttendanceRecord, "holidays": Holiday, "leaves": LeaveRecord, "accident": Accident} - if section not in valid: + single_models = {"attendance": AttendanceRecord, "accident": Accident} + if section not in single_models and section not in ("holidays", "leaves"): raise HTTPException(status_code=400, detail=f"Unknown section: {section}") # Auto-backup before reset src = Path(DB_PATH) + auto_dst = None if src.exists(): auto_dst = _backup_path(f"auto_pre_{section}_reset") shutil.copy2(src, auto_dst) - # Truncate table - model = valid[section] - db.execute(model.__table__.delete()) + # Truncate table(s) + if section == "holidays": + db.execute(Holiday.__table__.delete()) + db.execute(LeaveRecord.__table__.delete()) + elif section == "leaves": + db.execute(LeaveRecord.__table__.delete()) + else: + db.execute(single_models[section].__table__.delete()) db.commit() - return {"reset": section, "auto_backup": auto_dst.name} + return {"reset": section, "auto_backup": auto_dst.name if auto_dst else None} @app.get("/api/version") diff --git a/frontend/src/pages/Settings.jsx b/frontend/src/pages/Settings.jsx index 685b2d7..81651bd 100644 --- a/frontend/src/pages/Settings.jsx +++ b/frontend/src/pages/Settings.jsx @@ -18,10 +18,16 @@ const RESET_SECTIONS = [ }, { key: "holidays", - label: "假期 Holidays + Leave", - description: "刪除所有公眾假期 + 員工請假記錄", + label: "假期 Holidays", + description: "刪除所有公眾假期記錄", color: "amber", }, + { + key: "leaves", + label: "請假 Leaves", + description: "刪除所有員工請假記錄", + color: "lime", + }, ] export default function Settings() {