assigment and reports groundwork

This commit is contained in:
dimitar committed 2026-03-19 04:36:35 +01:00
1 parent 74f0d0dbed
commit 06973ccfb2
9 files changed
+299 -49

No files matched your search

@@ -35,22 +35,18 @@ export async function DELETE(
const { id } = await params;
// Get all assignments for the trainer to find the one with this ID
// Note: We need to find the assignment ID, not the trainer or client ID
// For now, we'll deactivate by finding the assignment through the trainer
// This is a simplified approach - in production you'd want a direct getById method
// Try to find the assignment by checking trainer's assignments first
const trainerAssignments = await db.getTrainerClientAssignments(
currentUser.id,
);
const assignment = trainerAssignments.find((a) => a.id === id);
let assignment = trainerAssignments.find((a) => a.id === id);
if (!assignment) {
// Check if any trainer has this assignment
const allAssignments = await db.getTrainerClientAssignments("");
const foundAssignment = allAssignments.find((a) => a.id === id);
// Check all assignments to find the one with this ID
const allAssignments = await db.getAllTrainerClientAssignments();
assignment = allAssignments.find((a) => a.id === id);
if (!foundAssignment) {
if (!assignment) {
return NextResponse.json(
{ error: "Assignment not found" },
{ status: 404 },
@@ -48,8 +48,7 @@ export async function GET(request: NextRequest) {
}
} else {
// Get all assignments (for admins, filtered by gym)
assignments = await db.getTrainerClientAssignments("");
// TODO: Filter by gym once gymId is properly set
assignments = await db.getAllTrainerClientAssignments();
}
return NextResponse.json({ assignments });