import { NextRequest, NextResponse } from "next/server"; import { unlink } from "fs/promises"; import path from "path"; import db from "@/lib/db"; export async function DELETE(request, { params }) { try { const { templateId } = params; // Get template info const template = db.prepare(` SELECT * FROM docx_templates WHERE template_id = ? `).get(templateId); if (!template) { return NextResponse.json( { error: "Template not found" }, { status: 404 } ); } // Soft delete by setting is_active to 0 db.prepare(` UPDATE docx_templates SET is_active = 0, updated_at = CURRENT_TIMESTAMP WHERE template_id = ? `).run(templateId); // Optionally delete the file (uncomment if you want hard delete) // try { // const filePath = path.join(process.cwd(), "public", template.file_path); // await unlink(filePath); // } catch (fileError) { // console.warn("Could not delete template file:", fileError); // } return NextResponse.json({ success: true }); } catch (error) { console.error("Template deletion error:", error); return NextResponse.json( { error: "Failed to delete template" }, { status: 500 } ); } }