T.ME/BIBIL_0DAY
CasperSecurity


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/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/gositeme/domains/lavocat.quebec/private_html/scripts/test-lawyer-api.js
const { PrismaClient } = require('@prisma/client');

const prisma = new PrismaClient();

async function testLawyerAPI() {
  console.log('šŸ” Testing Lawyer API Endpoint...\n');

  try {
    // 1. Test the API endpoint directly
    console.log('1. Testing /api/admin/users?role=LAWYER,ADMIN endpoint...');
    
    // Simulate what the frontend would receive
    const lawyers = await prisma.user.findMany({
      where: {
        role: {
          in: ['LAWYER', 'ADMIN', 'SUPERADMIN']
        }
      },
      select: {
        id: true,
        email: true,
        name: true,
        role: true,
        title: true,
        specialization: true,
        lawFirmId: true,
        lawFirm: {
          select: {
            name: true,
            shortName: true
          }
        },
        createdAt: true,
        updatedAt: true,
      },
      orderBy: {
        name: 'asc',
      },
    });

    console.log(`āœ… Found ${lawyers.length} lawyers/admins`);
    
    if (lawyers.length === 0) {
      console.log('āŒ No lawyers found - this is the problem!');
      return;
    }

    // 2. Display first few lawyers
    console.log('\n2. Sample lawyers:');
    lawyers.slice(0, 5).forEach((lawyer, index) => {
      console.log(`   ${index + 1}. ${lawyer.name} (${lawyer.role})`);
      console.log(`      ID: ${lawyer.id}`);
      console.log(`      Email: ${lawyer.email}`);
      console.log(`      Title: ${lawyer.title || 'N/A'}`);
      console.log(`      Specialization: ${lawyer.specialization || 'N/A'}`);
      console.log(`      Law Firm: ${lawyer.lawFirm?.name || 'N/A'}`);
      console.log('');
    });

    // 3. Test the specific case's current lead lawyer
    console.log('3. Testing current case lead lawyer...');
    const caseId = 'cmcpzyax8000avjz0ao7zkw1g';
    
    const currentCase = await prisma.legalCase.findUnique({
      where: { id: caseId },
      include: {
        leadLawyer: {
          select: {
            id: true,
            name: true,
            email: true,
            role: true,
            title: true,
            specialization: true
          }
        }
      }
    });

    if (currentCase) {
      console.log(`   Current case: ${currentCase.title}`);
      console.log(`   Lead Lawyer: ${currentCase.leadLawyer?.name || 'None'} (${currentCase.leadLawyer?.id || 'None'})`);
      console.log(`   Lead Lawyer Role: ${currentCase.leadLawyer?.role || 'None'}`);
    } else {
      console.log('   āŒ Case not found');
    }

    // 4. Check if the current lead lawyer is in the lawyers list
    if (currentCase?.leadLawyer) {
      const isInList = lawyers.some(lawyer => lawyer.id === currentCase.leadLawyer.id);
      console.log(`   Is current lead lawyer in dropdown list: ${isInList ? 'āœ… Yes' : 'āŒ No'}`);
    }

    // 5. Test form data structure
    console.log('\n4. Testing form data structure...');
    const formData = {
      leadLawyerId: currentCase?.leadLawyerId || '',
      lawyers: lawyers.map(lawyer => ({
        id: lawyer.id,
        name: lawyer.name,
        role: lawyer.role,
        title: lawyer.title,
        specialization: lawyer.specialization
      }))
    };

    console.log('   Form data structure:');
    console.log(`   - Current leadLawyerId: "${formData.leadLawyerId}"`);
    console.log(`   - Available lawyers: ${formData.lawyers.length}`);
    console.log(`   - Lawyers with LAWYER role: ${formData.lawyers.filter(l => l.role === 'LAWYER').length}`);
    console.log(`   - Lawyers with ADMIN role: ${formData.lawyers.filter(l => l.role === 'ADMIN').length}`);
    console.log(`   - Lawyers with SUPERADMIN role: ${formData.lawyers.filter(l => l.role === 'SUPERADMIN').length}`);

    // 6. Test dropdown options
    console.log('\n5. Testing dropdown options...');
    const dropdownOptions = lawyers.map(lawyer => ({
      value: lawyer.id,
      label: `${lawyer.name} ${lawyer.title ? `(${lawyer.title})` : ''} ${lawyer.specialization ? `- ${lawyer.specialization}` : ''}`
    }));

    console.log('   Sample dropdown options:');
    dropdownOptions.slice(0, 3).forEach((option, index) => {
      console.log(`   ${index + 1}. Value: "${option.value}"`);
      console.log(`      Label: "${option.label}"`);
    });

    // 7. Check for potential issues
    console.log('\n6. Checking for potential issues...');
    
    // Check for empty names
    const emptyNames = lawyers.filter(l => !l.name || l.name.trim() === '');
    if (emptyNames.length > 0) {
      console.log(`   āš ļø  Found ${emptyNames.length} lawyers with empty names`);
    } else {
      console.log('   āœ… All lawyers have names');
    }

    // Check for duplicate IDs
    const ids = lawyers.map(l => l.id);
    const uniqueIds = new Set(ids);
    if (ids.length !== uniqueIds.size) {
      console.log('   āš ļø  Found duplicate IDs');
    } else {
      console.log('   āœ… All lawyer IDs are unique');
    }

    // Check if current lead lawyer exists
    if (currentCase?.leadLawyerId && !lawyers.some(l => l.id === currentCase.leadLawyerId)) {
      console.log('   āš ļø  Current lead lawyer is not in the dropdown list');
    } else if (currentCase?.leadLawyerId) {
      console.log('   āœ… Current lead lawyer is in the dropdown list');
    }

    // 8. Summary
    console.log('\n7. šŸ“‹ SUMMARY:');
    console.log(`   āœ… Total lawyers/admins available: ${lawyers.length}`);
    console.log(`   āœ… Current case has lead lawyer: ${currentCase?.leadLawyer ? 'Yes' : 'No'}`);
    console.log(`   āœ… API should return data correctly`);
    console.log(`   āœ… Dropdown should populate with ${lawyers.length} options`);

    if (lawyers.length > 0) {
      console.log('\nšŸŽ‰ The lawyer dropdown should work correctly!');
      console.log('   If you still can\'t select a lawyer, check:');
      console.log('   1. Browser console for JavaScript errors');
      console.log('   2. Network tab for API request failures');
      console.log('   3. Authentication/session issues');
    } else {
      console.log('\nāŒ No lawyers found - this needs to be fixed!');
    }

  } catch (error) {
    console.error('āŒ Test failed:', error);
  } finally {
    await prisma.$disconnect();
  }
}

// Run the test
testLawyerAPI(); 

CasperSecurity Mini