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,38 @@
import db from "./src/lib/db.js";
// Migration to add docx_templates table
const migration = () => {
console.log("Running migration: add-docx-templates-table");
try {
db.exec(`
-- Table: docx_templates
CREATE TABLE IF NOT EXISTS docx_templates (
template_id INTEGER PRIMARY KEY AUTOINCREMENT,
template_name TEXT NOT NULL,
description TEXT,
original_filename TEXT NOT NULL,
stored_filename TEXT NOT NULL,
file_path TEXT NOT NULL,
file_size INTEGER NOT NULL,
mime_type TEXT NOT NULL,
is_active INTEGER DEFAULT 1,
created_at TEXT DEFAULT CURRENT_TIMESTAMP,
created_by TEXT,
updated_at TEXT DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (created_by) REFERENCES users(id)
);
-- Indexes for templates
CREATE INDEX IF NOT EXISTS idx_docx_templates_active ON docx_templates(is_active);
CREATE INDEX IF NOT EXISTS idx_docx_templates_created_by ON docx_templates(created_by);
`);
console.log("Migration completed successfully");
} catch (error) {
console.error("Migration failed:", error);
throw error;
}
};
migration();