![]() 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 testAdminCaseEdit() {
console.log('š Testing Admin Case Edit Functionality...\n');
try {
// 1. Find a test case
console.log('1. Finding a test case...');
const testCase = await prisma.legalCase.findFirst({
include: {
leadLawyer: {
select: {
id: true,
name: true,
email: true,
role: true
}
}
}
});
if (!testCase) {
console.log('ā No test case found. Creating one...');
// Create a test case if none exists
const testCase = await prisma.legalCase.create({
data: {
title: 'Test Case for Edit',
description: 'This is a test case for editing functionality',
caseNumber: '2024QCCS9999',
caseType: 'CLASS_ACTION',
jurisdiction: 'Quebec',
court: 'QUEBEC_SUPERIOR',
leadLawyerId: 'test-lawyer-id', // You'll need to replace with actual lawyer ID
priority: 'medium',
status: 'pending',
isAcceptingApplications: true,
createdBy: 'test-admin-id' // You'll need to replace with actual admin ID
}
});
console.log('ā
Test case created:', testCase.id);
} else {
console.log('ā
Found test case:', testCase.id);
console.log(' Title:', testCase.title);
console.log(' Lead Lawyer:', testCase.leadLawyer?.name || 'None');
}
// 2. Check API endpoint structure
console.log('\n2. Checking API endpoint structure...');
console.log(' Expected fields for PUT /api/admin/cases/[id]:');
console.log(' - title (string)');
console.log(' - description (string)');
console.log(' - caseNumber (string) - SINGULAR');
console.log(' - caseType (string) - SINGULAR');
console.log(' - jurisdiction (string) - SINGULAR');
console.log(' - court (string) - SINGULAR');
console.log(' - leadLawyerId (string)');
console.log(' - priority (string)');
console.log(' - budget (number or null)');
console.log(' - status (string)');
console.log(' - applicationDeadline (date string or null)');
console.log(' - isAcceptingApplications (boolean)');
// 3. Check frontend form structure
console.log('\n3. Frontend form structure issues:');
console.log(' ā Frontend sends: caseNumbers (array)');
console.log(' ā
API expects: caseNumber (string)');
console.log(' ā Frontend sends: caseTypes (array)');
console.log(' ā
API expects: caseType (string)');
console.log(' ā Frontend sends: jurisdictions (array)');
console.log(' ā
API expects: jurisdiction (string)');
console.log(' ā Frontend sends: courts (array)');
console.log(' ā
API expects: court (string)');
// 4. Test API call simulation
console.log('\n4. Simulating API call with correct data structure...');
const testUpdateData = {
title: 'Updated Test Case',
description: 'This is an updated test case description',
caseNumber: '2024QCCS9999', // SINGULAR
caseType: 'CLASS_ACTION', // SINGULAR
jurisdiction: 'Quebec', // SINGULAR
court: 'QUEBEC_SUPERIOR', // SINGULAR
leadLawyerId: testCase.leadLawyerId,
priority: 'high',
budget: 50000,
status: 'active',
applicationDeadline: '2024-12-31',
isAcceptingApplications: true
};
console.log(' Test update data:', JSON.stringify(testUpdateData, null, 2));
// 5. Check database schema
console.log('\n5. Checking database schema...');
const caseFields = await prisma.$queryRaw`
SELECT column_name, data_type, is_nullable
FROM information_schema.columns
WHERE table_name = 'LegalCase'
ORDER BY ordinal_position
`;
console.log(' LegalCase table fields:');
caseFields.forEach(field => {
console.log(` - ${field.column_name}: ${field.data_type} (nullable: ${field.is_nullable})`);
});
// 6. Recommendations
console.log('\n6. š§ RECOMMENDATIONS TO FIX:');
console.log(' a) Update frontend form to send singular fields:');
console.log(' - caseNumbers[0] ā caseNumber');
console.log(' - caseTypes[0] ā caseType');
console.log(' - jurisdictions[0] ā jurisdiction');
console.log(' - courts[0] ā court');
console.log(' b) Or update API to handle arrays and convert to singular');
console.log(' c) Add proper error handling for missing required fields');
console.log(' d) Add validation for case number format');
console.log(' e) Add logging to track API requests and responses');
console.log('\nā
Test completed successfully!');
} catch (error) {
console.error('ā Test failed:', error);
} finally {
await prisma.$disconnect();
}
}
// Run the test
testAdminCaseEdit();