- 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.
34 lines
916 B
JavaScript
34 lines
916 B
JavaScript
import {
|
|
getAllUsersForAssignment,
|
|
updateProjectAssignment,
|
|
} from "@/lib/queries/projects";
|
|
import initializeDatabase from "@/lib/init-db";
|
|
import { NextResponse } from "next/server";
|
|
import { withUserAuth } from "@/lib/middleware/auth";
|
|
|
|
// Make sure the DB is initialized before queries run
|
|
initializeDatabase();
|
|
|
|
async function getUsersHandler(req) {
|
|
const users = getAllUsersForAssignment();
|
|
return NextResponse.json(users);
|
|
}
|
|
|
|
async function updateAssignmentHandler(req) {
|
|
const { projectId, assignedToUserId } = await req.json();
|
|
|
|
if (!projectId) {
|
|
return NextResponse.json(
|
|
{ error: "Project ID is required" },
|
|
{ status: 400 }
|
|
);
|
|
}
|
|
|
|
updateProjectAssignment(projectId, assignedToUserId);
|
|
return NextResponse.json({ success: true });
|
|
}
|
|
|
|
// Protected routes - require authentication
|
|
export const GET = withUserAuth(getUsersHandler);
|
|
export const POST = withUserAuth(updateAssignmentHandler);
|