feat: Add document template management functionality

- Created migration script to add `docx_templates` table with necessary fields and indexes.
- Implemented API routes for uploading, fetching, and deleting document templates.
- Developed document generation feature using selected templates and project data.
- Added UI components for template upload and listing, including a modal for document generation.
- Integrated document generation into the project view page, allowing users to generate documents based on selected templates.
- Enhanced error handling and user feedback for template operations.
This commit is contained in:
2025-12-16 09:50:19 +01:00
parent abad26b68a
commit c0d357efdd
12 changed files with 1291 additions and 3 deletions

View File

@@ -0,0 +1,46 @@
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 }
);
}
}