feat: Implement user tracking in projects

- Added user tracking features to the projects module, including:
  - Database schema updates to track project creator and assignee.
  - API enhancements for user management and project filtering by user.
  - UI components for user assignment in project forms and listings.
  - New query functions for retrieving users and filtering projects.
  - Security integration with role-based access and authentication requirements.

chore: Create utility scripts for database checks and project testing

- Added scripts to check the structure of the projects table.
- Created tests for project creation and user tracking functionality.
- Implemented API tests to verify project retrieval and user assignment.

fix: Update project creation and update functions to include user tracking

- Modified createProject and updateProject functions to handle user IDs for creator and assignee.
- Ensured that project updates reflect the correct user assignments and timestamps.
This commit is contained in:
Chop
2025-06-25 23:08:15 +02:00
parent 81afa09f3a
commit 294d8343d3
19 changed files with 790 additions and 35 deletions

View File

@@ -3,22 +3,41 @@ import {
updateProject,
deleteProject,
} from "@/lib/queries/projects";
import initializeDatabase from "@/lib/init-db";
import { NextResponse } from "next/server";
import { withReadAuth, withUserAuth } from "@/lib/middleware/auth";
async function getProjectHandler(_, { params }) {
const project = getProjectById(params.id);
// Make sure the DB is initialized before queries run
initializeDatabase();
async function getProjectHandler(req, { params }) {
const { id } = await params;
const project = getProjectById(parseInt(id));
if (!project) {
return NextResponse.json({ error: "Project not found" }, { status: 404 });
}
return NextResponse.json(project);
}
async function updateProjectHandler(req, { params }) {
const { id } = await params;
const data = await req.json();
updateProject(params.id, data);
return NextResponse.json({ success: true });
// Get user ID from authenticated request
const userId = req.user?.id;
updateProject(parseInt(id), data, userId);
// Return the updated project
const updatedProject = getProjectById(parseInt(id));
return NextResponse.json(updatedProject);
}
async function deleteProjectHandler(_, { params }) {
deleteProject(params.id);
async function deleteProjectHandler(req, { params }) {
const { id } = await params;
deleteProject(parseInt(id));
return NextResponse.json({ success: true });
}