feat: add contact management functionality

- Implemented ContactForm component for creating and editing contacts.
- Added ProjectContactSelector component to manage project-specific contacts.
- Updated ProjectForm to include ProjectContactSelector for associating contacts with projects.
- Enhanced Card component with a new CardTitle subcomponent for better structure.
- Updated Navigation to include a link to the contacts page.
- Added translations for contact-related terms in the i18n module.
- Initialized contacts database schema and created necessary tables for contact management.
- Developed queries for CRUD operations on contacts, including linking and unlinking contacts to projects.
- Created a test script to validate contact queries against the database.
This commit is contained in:
2025-12-03 16:23:05 +01:00
parent c9b7355f3c
commit 60b79fa360
18 changed files with 2332 additions and 10 deletions

View File

@@ -0,0 +1,40 @@
import { NextResponse } from "next/server";
import db from "@/lib/db";
import { withAuth } from "@/lib/middleware/auth";
// GET /api/contacts/[id]/projects - Get all projects linked to a contact
export const GET = withAuth(async (request, { params }) => {
try {
const contactId = params.id;
// Get all projects linked to this contact with relationship details
const projects = db
.prepare(
`
SELECT
p.project_id,
p.project_name,
p.project_status,
pc.relationship_type,
pc.is_primary,
pc.added_at
FROM projects p
INNER JOIN project_contacts pc ON p.project_id = pc.project_id
WHERE pc.contact_id = ?
ORDER BY pc.is_primary DESC, p.project_name ASC
`
)
.all(contactId);
return NextResponse.json({
projects,
count: projects.length,
});
} catch (error) {
console.error("Error fetching contact projects:", error);
return NextResponse.json(
{ error: "Failed to fetch projects" },
{ status: 500 }
);
}
});