![]() 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/ |
import { PrismaClient } from '@prisma/client';
import bcrypt from 'bcryptjs';
const prisma = new PrismaClient();
async function createDemoData() {
console.log('ποΈ Creating Case Assignment Demo Data...\n');
try {
// Create sample users with different roles
const defaultPassword = await bcrypt.hash('demo123', 10);
const users = await Promise.all([
prisma.user.upsert({
where: { email: 'lead.attorney@lmep.ca' },
update: {},
create: {
name: 'Marie Dubois',
email: 'lead.attorney@lmep.ca',
password: defaultPassword,
role: 'LAWYER',
title: 'Senior Attorney',
specialization: 'Criminal Defense',
phone: '514-555-0101'
}
}),
prisma.user.upsert({
where: { email: 'assistant.lawyer@lmep.ca' },
update: {},
create: {
name: 'Jean-Pierre Martin',
email: 'assistant.lawyer@lmep.ca',
password: defaultPassword,
role: 'LAWYER',
title: 'Associate Attorney',
specialization: 'Legal Research',
phone: '514-555-0102'
}
}),
prisma.user.upsert({
where: { email: 'law.clerk@lmep.ca' },
update: {},
create: {
name: 'Sophie Tremblay',
email: 'law.clerk@lmep.ca',
password: defaultPassword,
role: 'CLERK',
title: 'Law Clerk',
phone: '514-555-0103'
}
}),
prisma.user.upsert({
where: { email: 'legal.secretary@lmep.ca' },
update: {},
create: {
name: 'Isabelle Gagnon',
email: 'legal.secretary@lmep.ca',
password: defaultPassword,
role: 'SECRETARY',
title: 'Legal Secretary',
phone: '514-555-0104'
}
})
]);
console.log('β
Created demo team members:');
users.forEach(user => {
console.log(` β’ ${user.name} (${user.role}) - ${user.email}`);
});
// Create sample registrations (cases)
const registrations = await Promise.all([
prisma.registration.create({
data: {
firstName: 'Pierre',
lastName: 'Leblanc',
email: 'pierre.leblanc@email.com',
phone: '438-555-0201',
birthDate: new Date('1985-03-15'),
gender: 'Male',
relationship: 'Self',
preferredLanguage: 'French',
preferredContactMethod: 'Email',
message: 'Seeking legal assistance for wrongful conviction appeal',
status: 'PENDING',
reasonForJoining: 'Wrongful conviction - need appeal assistance',
urgentNeeds: 'Court date approaching in 30 days',
detaineeInfo: {
create: {
name: 'Pierre Leblanc',
facility: 'bordeaux',
inmateId: 'BDX-2024-001',
incarcerationDate: new Date('2023-06-01'),
expectedReleaseDate: new Date('2026-06-01')
}
},
address: {
create: {
street: '123 Rue Saint-Denis',
city: 'Montreal',
state: 'Quebec',
postalCode: 'H2X 1K5',
country: 'Canada'
}
}
}
}),
prisma.registration.create({
data: {
firstName: 'Marie',
lastName: 'Bouchard',
email: 'marie.bouchard@email.com',
phone: '514-555-0202',
birthDate: new Date('1978-11-22'),
gender: 'Female',
relationship: 'Mother',
preferredLanguage: 'French',
preferredContactMethod: 'Phone',
message: 'My son needs legal representation for his case',
status: 'DOCUMENTS_UNDER_REVIEW',
reasonForJoining: 'Son facing serious charges, need experienced lawyer',
urgentNeeds: 'Bail hearing scheduled next week',
detaineeInfo: {
create: {
name: 'Marc Bouchard',
facility: 'leclerc',
inmateId: 'LCL-2024-045',
incarcerationDate: new Date('2024-01-15'),
expectedReleaseDate: new Date('2025-01-15')
}
},
address: {
create: {
street: '456 Boulevard RenΓ©-LΓ©vesque',
city: 'Laval',
state: 'Quebec',
postalCode: 'H7M 2G8',
country: 'Canada'
}
}
}
}),
prisma.registration.create({
data: {
firstName: 'Robert',
lastName: 'Caron',
email: 'robert.caron@email.com',
phone: '450-555-0203',
birthDate: new Date('1992-07-08'),
gender: 'Male',
relationship: 'Self',
preferredLanguage: 'English',
preferredContactMethod: 'Email',
message: 'Need help with sentence reduction appeal',
status: 'APPROVED',
reasonForJoining: 'Sentence seems excessive for the crime',
urgentNeeds: 'Appeal deadline in 60 days',
detaineeInfo: {
create: {
name: 'Robert Caron',
facility: 'sherbrooke',
inmateId: 'SHB-2024-089',
incarcerationDate: new Date('2023-09-10'),
expectedReleaseDate: new Date('2028-09-10')
}
},
address: {
create: {
street: '789 Rue King Ouest',
city: 'Sherbrooke',
state: 'Quebec',
postalCode: 'J1H 1R3',
country: 'Canada'
}
}
}
})
]);
console.log('\nβ
Created demo cases:');
registrations.forEach(reg => {
console.log(` β’ ${reg.firstName} ${reg.lastName} - Status: ${reg.status}`);
});
// Use the first user as the assigner for demo purposes
const assignerId = users[0].id;
// Create case assignments
const assignments = await Promise.all([
// Case 1: Pierre Leblanc - Full team
prisma.caseAssignment.create({
data: {
registrationId: registrations[0].id,
userId: users[0].id, // Marie Dubois as lead attorney
role: 'primary_lawyer',
assignedBy: assignerId
}
}),
prisma.caseAssignment.create({
data: {
registrationId: registrations[0].id,
userId: users[1].id, // Jean-Pierre Martin as assistant
role: 'assistant_lawyer',
assignedBy: assignerId
}
}),
prisma.caseAssignment.create({
data: {
registrationId: registrations[0].id,
userId: users[3].id, // Isabelle Gagnon as secretary
role: 'secretary',
assignedBy: assignerId
}
}),
// Case 2: Marie Bouchard - Lead attorney + clerk
prisma.caseAssignment.create({
data: {
registrationId: registrations[1].id,
userId: users[0].id, // Marie Dubois as lead attorney
role: 'primary_lawyer',
assignedBy: assignerId
}
}),
prisma.caseAssignment.create({
data: {
registrationId: registrations[1].id,
userId: users[2].id, // Sophie Tremblay as assistant (clerk)
role: 'assistant_lawyer',
assignedBy: assignerId
}
}),
// Case 3: Robert Caron - Just lead attorney
prisma.caseAssignment.create({
data: {
registrationId: registrations[2].id,
userId: users[1].id, // Jean-Pierre Martin as lead attorney
role: 'primary_lawyer',
assignedBy: assignerId
}
})
]);
console.log('\nβ
Created case assignments:');
console.log(' π Case 1 (Pierre Leblanc):');
console.log(' βοΈ Lead Attorney: Marie Dubois');
console.log(' π€ Assistant Attorney: Jean-Pierre Martin');
console.log(' π Secretary: Isabelle Gagnon');
console.log(' π Case 2 (Marie Bouchard):');
console.log(' βοΈ Lead Attorney: Marie Dubois');
console.log(' π€ Assistant Attorney: Sophie Tremblay (Clerk)');
console.log(' π Case 3 (Robert Caron):');
console.log(' βοΈ Lead Attorney: Jean-Pierre Martin');
console.log('\nπ Demo data created successfully!');
console.log('\nπ Summary:');
console.log(` β’ ${users.length} team members created`);
console.log(` β’ ${registrations.length} cases created`);
console.log(` β’ ${assignments.length} assignments created`);
console.log('\nπ Access your Case Assignment Dashboard at:');
console.log(' http://localhost:3000/admin/case-assignments');
console.log('\nπ₯ Team Member Logins (password: demo123):');
users.forEach(user => {
console.log(` β’ ${user.name}: ${user.email}`);
});
} catch (error) {
console.error('β Error creating demo data:', error);
} finally {
await prisma.$disconnect();
}
}
async function cleanupDemoData() {
console.log('π§Ή Cleaning up demo data...\n');
try {
// Delete demo assignments for demo users
const demoUsers = await prisma.user.findMany({
where: {
email: {
in: [
'lead.attorney@lmep.ca',
'assistant.lawyer@lmep.ca',
'law.clerk@lmep.ca',
'legal.secretary@lmep.ca'
]
}
}
});
if (demoUsers.length > 0) {
await prisma.caseAssignment.deleteMany({
where: {
OR: [
{ assignedBy: { in: demoUsers.map(u => u.id) } },
{ userId: { in: demoUsers.map(u => u.id) } }
]
}
});
}
// Delete demo registrations (will cascade to addresses and detainee info)
await prisma.registration.deleteMany({
where: {
email: {
in: ['pierre.leblanc@email.com', 'marie.bouchard@email.com', 'robert.caron@email.com']
}
}
});
// Delete demo users
await prisma.user.deleteMany({
where: {
email: {
in: [
'lead.attorney@lmep.ca',
'assistant.lawyer@lmep.ca',
'law.clerk@lmep.ca',
'legal.secretary@lmep.ca'
]
}
}
});
console.log('β
Demo data cleaned up successfully!');
} catch (error) {
console.error('β Error cleaning up demo data:', error);
} finally {
await prisma.$disconnect();
}
}
// Command line interface
const command = process.argv[2];
if (command === 'create') {
createDemoData();
} else if (command === 'cleanup') {
cleanupDemoData();
} else {
console.log('ποΈ Case Assignment Demo Script');
console.log('\nUsage:');
console.log(' npm run demo-assignments create - Create demo data');
console.log(' npm run demo-assignments cleanup - Remove demo data');
console.log('\nThis script creates:');
console.log(' β’ 4 team members (lawyer, assistant, clerk, secretary)');
console.log(' β’ 3 sample cases with different statuses');
console.log(' β’ 6 case assignments showing team workflow');
}