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/backups/lavocat.quebec/backup-20250730-021618/scripts/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/gositeme/backups/lavocat.quebec/backup-20250730-021618/scripts/link-clients-to-cases.js
const { PrismaClient } = require('@prisma/client');

const prisma = new PrismaClient();

async function linkClientsToCases() {
  try {
    console.log('šŸ”— Linking clients to cases...');

    // Get all clients
    const clients = await prisma.user.findMany({
      where: {
        role: 'CLIENT'
      },
      select: {
        id: true,
        email: true,
        name: true
      }
    });

    console.log(`Found ${clients.length} clients`);

    // Get all cases
    const cases = await prisma.legalCase.findMany({
      select: {
        id: true,
        caseNumber: true,
        title: true,
        status: true
      }
    });

    console.log(`Found ${cases.length} cases`);

    if (clients.length === 0) {
      console.log('āŒ No clients found. Please run the demo data scripts first.');
      return;
    }

    if (cases.length === 0) {
      console.log('āŒ No cases found. Please run the demo data scripts first.');
      return;
    }

    // Get a lawyer to assign cases
    const lawyer = await prisma.user.findFirst({
      where: {
        role: 'LAWYER'
      },
      select: {
        id: true,
        name: true
      }
    });

    if (!lawyer) {
      console.log('āŒ No lawyer found to assign cases. Please run the demo data scripts first.');
      return;
    }

    console.log(`Using lawyer: ${lawyer.name} (${lawyer.id})`);

    // Link each client to multiple cases through registrations and case assignments
    let totalLinks = 0;

    for (const client of clients) {
      // Assign 2-4 random cases to each client
      const numCases = Math.floor(Math.random() * 3) + 2; // 2-4 cases
      const shuffledCases = cases.sort(() => 0.5 - Math.random());
      const selectedCases = shuffledCases.slice(0, numCases);

      for (const caseItem of selectedCases) {
        try {
          // Create a registration for this client-case combination
          const registration = await prisma.registration.create({
            data: {
              firstName: client.name?.split(' ')[0] || 'Demo',
              lastName: client.name?.split(' ').slice(1).join(' ') || 'Client',
              email: client.email,
              phone: '514-555-0123',
              birthDate: new Date('1990-01-01'),
              gender: 'Other',
              relationship: 'CLIENT',
              preferredLanguage: 'en',
              preferredContactMethod: 'email',
              message: `Demo registration for case ${caseItem.caseNumber}`,
              userId: client.id,
              caseId: caseItem.id,
              createdBy: lawyer.id
            }
          });

          // Create a case assignment
          await prisma.caseAssignment.create({
            data: {
              registrationId: registration.id,
              userId: client.id,
              role: 'CLIENT',
              assignedBy: lawyer.id,
              caseId: caseItem.id
            }
          });

          totalLinks++;
          console.log(`   āœ… Linked ${client.name} to case ${caseItem.caseNumber}: ${caseItem.title}`);

        } catch (error) {
          if (error.code === 'P2002') {
            console.log(`   āš ļø  Link already exists for ${client.name} and case ${caseItem.caseNumber}`);
          } else {
            console.error(`   āŒ Error linking ${client.name} to case ${caseItem.caseNumber}:`, error.message);
          }
        }
      }
    }

    console.log(`\nāœ… Successfully created ${totalLinks} client-case relationships`);

    // Verify the links by checking the API endpoint logic
    const verification = await prisma.legalCase.findMany({
      where: {
        OR: [
          { registrations: { some: { userId: { in: clients.map(c => c.id) } } } },
          { caseAssignments: { some: { userId: { in: clients.map(c => c.id) } } } }
        ]
      },
      include: {
        registrations: {
          include: {
            user: {
              select: {
                name: true,
                email: true
              }
            }
          }
        },
        caseAssignments: {
          include: {
            user: {
              select: {
                name: true,
                email: true
              }
            }
          }
        }
      }
    });

    console.log('\nšŸ“‹ Verification - Cases with Client Links:');
    verification.forEach(caseItem => {
      console.log(`\n   Case: ${caseItem.caseNumber} - ${caseItem.title}`);
      
      // Show registrations
      caseItem.registrations.forEach(reg => {
        console.log(`     šŸ“ Registration: ${reg.user.name} (${reg.user.email})`);
      });
      
      // Show case assignments
      caseItem.caseAssignments.forEach(assignment => {
        console.log(`     šŸ‘¤ Assignment: ${assignment.user.name} (${assignment.user.email}) - Role: ${assignment.role}`);
      });
    });

    console.log(`\nāœ… Total cases with client links: ${verification.length}`);

  } catch (error) {
    console.error('āŒ Error linking clients to cases:', error);
  } finally {
    await prisma.$disconnect();
  }
}

// Run the script
linkClientsToCases(); 

CasperSecurity Mini