![]() 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.ca/public_html/scripts/ |
const { PrismaClient } = require('@prisma/client');
const bcrypt = require('bcryptjs');
const prisma = new PrismaClient();
async function createAdditionalClients() {
try {
console.log('👥 Creating additional demo clients...');
const additionalClients = [
{
email: 'marie.tremblay@example.com',
name: 'Marie Tremblay',
password: 'demo123',
role: 'CLIENT',
phone: '514-555-0101',
address: '123 Rue Saint-Denis, Montréal, QC',
occupation: 'Teacher',
language: 'fr'
},
{
email: 'jean.bouchard@example.com',
name: 'Jean Bouchard',
password: 'demo123',
role: 'CLIENT',
phone: '514-555-0102',
address: '456 Avenue du Parc, Montréal, QC',
occupation: 'Construction Worker',
language: 'fr'
},
{
email: 'sophie.levesque@example.com',
name: 'Sophie Lévesque',
password: 'demo123',
role: 'CLIENT',
phone: '514-555-0103',
address: '789 Boulevard René-Lévesque, Montréal, QC',
occupation: 'Nurse',
language: 'fr'
},
{
email: 'marc.dubois@example.com',
name: 'Marc Dubois',
password: 'demo123',
role: 'CLIENT',
phone: '514-555-0104',
address: '321 Rue Sherbrooke, Montréal, QC',
occupation: 'Student',
language: 'en'
},
{
email: 'lucie.morin@example.com',
name: 'Lucie Morin',
password: 'demo123',
role: 'CLIENT',
phone: '514-555-0105',
address: '654 Rue Ontario, Montréal, QC',
occupation: 'Social Worker',
language: 'fr'
}
];
const createdClients = [];
for (const clientData of additionalClients) {
try {
const hashedPassword = await bcrypt.hash(clientData.password, 12);
const client = await prisma.user.create({
data: {
email: clientData.email,
name: clientData.name,
password: hashedPassword,
role: clientData.role,
phone: clientData.phone,
address: clientData.address,
occupation: clientData.occupation,
language: clientData.language,
notifications: true,
theme: 'light'
}
});
createdClients.push(client);
console.log(` âś… Created client: ${client.name} (${client.email})`);
} catch (error) {
if (error.code === 'P2002') {
console.log(` ⚠️ Client already exists: ${clientData.name} (${clientData.email})`);
} else {
console.error(` ❌ Error creating client ${clientData.name}:`, error.message);
}
}
}
console.log(`\nâś… Successfully created ${createdClients.length} additional clients`);
// Now link these new clients to cases
console.log('\nđź”— Linking new clients to cases...');
const cases = await prisma.legalCase.findMany({
select: {
id: true,
caseNumber: true,
title: true
}
});
const lawyer = await prisma.user.findFirst({
where: {
role: 'LAWYER'
},
select: {
id: true,
name: true
}
});
if (!lawyer) {
console.log('❌ No lawyer found to assign cases.');
return;
}
let totalLinks = 0;
for (const client of createdClients) {
// Assign 1-3 random cases to each client
const numCases = Math.floor(Math.random() * 3) + 1; // 1-3 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: client.phone || '514-555-0123',
birthDate: new Date('1990-01-01'),
gender: 'Other',
relationship: 'CLIENT',
preferredLanguage: client.language || '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} additional client-case relationships`);
// Show summary of all clients
const allClients = await prisma.user.findMany({
where: {
role: 'CLIENT'
},
select: {
id: true,
name: true,
email: true,
phone: true,
occupation: true
}
});
console.log('\nđź“‹ All Demo Clients:');
allClients.forEach(client => {
console.log(` 👤 ${client.name} - ${client.email} (${client.occupation || 'N/A'})`);
});
console.log(`\n🎉 Total clients available for testing: ${allClients.length}`);
} catch (error) {
console.error('❌ Error creating additional clients:', error);
} finally {
await prisma.$disconnect();
}
}
// Run the script
createAdditionalClients();