![]() Server : Apache/2 System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 User : gositeme ( 1004) PHP Version : 8.2.29 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/gositeme/domains/lavocat.quebec/private_html/scripts/ |
const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();
async function testCaseSelection() {
try {
console.log('๐งช Testing case selection functionality...\n');
// Get all clients
const clients = await prisma.user.findMany({
where: {
role: 'CLIENT'
},
select: {
id: true,
name: true,
email: true
}
});
console.log(`๐ Found ${clients.length} clients:`);
clients.forEach(client => {
console.log(` ๐ค ${client.name} (${client.email})`);
});
// Test each client's case access
console.log('\n๐ Testing case access for each client:');
for (const client of clients) {
console.log(`\n๐ค Testing client: ${client.name} (${client.email})`);
// Simulate the API endpoint logic
const cases = await prisma.legalCase.findMany({
where: {
OR: [
{ registrations: { some: { userId: client.id } } },
{ caseAssignments: { some: { userId: client.id } } }
]
},
select: {
id: true,
title: true,
caseType: true,
status: true,
priority: true,
budget: true,
description: true,
createdAt: true,
isAcceptingApplications: true,
caseNumber: true
},
orderBy: { createdAt: 'desc' }
});
if (cases.length > 0) {
console.log(` โ
Found ${cases.length} cases:`);
cases.forEach(caseItem => {
console.log(` ๐ ${caseItem.caseNumber || 'N/A'}: ${caseItem.title}`);
console.log(` Type: ${caseItem.caseType} | Status: ${caseItem.status} | Priority: ${caseItem.priority}`);
console.log(` Budget: $${caseItem.budget || 'N/A'} | Accepting: ${caseItem.isAcceptingApplications ? 'Yes' : 'No'}`);
});
} else {
console.log(` โ No cases found for this client`);
}
// Check registrations
const registrations = await prisma.registration.findMany({
where: {
userId: client.id
},
include: {
legalCase: {
select: {
caseNumber: true,
title: true
}
}
}
});
console.log(` ๐ Registrations: ${registrations.length}`);
registrations.forEach(reg => {
console.log(` - ${reg.legalCase?.caseNumber || 'N/A'}: ${reg.legalCase?.title || 'Unknown Case'}`);
});
// Check case assignments
const assignments = await prisma.caseAssignment.findMany({
where: {
userId: client.id
},
include: {
legalCase: {
select: {
caseNumber: true,
title: true
}
}
}
});
console.log(` ๐ค Case Assignments: ${assignments.length}`);
assignments.forEach(assignment => {
console.log(` - ${assignment.legalCase?.caseNumber || 'N/A'}: ${assignment.legalCase?.title || 'Unknown Case'} (Role: ${assignment.role})`);
});
}
// Summary
console.log('\n๐ Summary:');
const totalCases = await prisma.legalCase.count();
const totalRegistrations = await prisma.registration.count();
const totalAssignments = await prisma.caseAssignment.count();
console.log(` โข Total cases in database: ${totalCases}`);
console.log(` โข Total registrations: ${totalRegistrations}`);
console.log(` โข Total case assignments: ${totalAssignments}`);
console.log(` โข Total clients: ${clients.length}`);
// Test the actual API endpoint logic
console.log('\n๐ Testing API endpoint logic:');
const testClient = clients[0]; // Use first client for testing
if (testClient) {
const apiCases = await prisma.legalCase.findMany({
where: {
OR: [
{ registrations: { some: { userId: testClient.id } } },
{ caseAssignments: { some: { userId: testClient.id } } }
]
},
select: {
id: true,
title: true,
caseType: true,
status: true,
priority: true,
budget: true,
description: true,
createdAt: true,
isAcceptingApplications: true
},
orderBy: { createdAt: 'desc' }
});
console.log(` API response for ${testClient.name}:`);
console.log(` Status: โ
Success`);
console.log(` Cases returned: ${apiCases.length}`);
console.log(` Response structure: ${JSON.stringify(apiCases, null, 2)}`);
}
console.log('\nโ
Case selection testing completed successfully!');
console.log('\n๐ฏ Next steps:');
console.log(' 1. Log in as any client user');
console.log(' 2. Navigate to /hire/case-selection');
console.log(' 3. Verify that cases are displayed properly');
console.log(' 4. Test case selection and hiring functionality');
} catch (error) {
console.error('โ Error testing case selection:', error);
} finally {
await prisma.$disconnect();
}
}
// Run the test
testCaseSelection();