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() {