![]() 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 checkAndFixUserApplicationMismatch() {
try {
console.log('š Checking for user application mismatches...\n');
// Get all registrations
const registrations = await prisma.registration.findMany({
include: {
user: true,
creator: true
}
});
console.log(`š Found ${registrations.length} total registrations\n`);
// Get all users
const users = await prisma.user.findMany();
console.log(`š„ Found ${users.length} total users\n`);
// Check for registrations with null userId but matching email
const nullUserIdRegistrations = registrations.filter(r => r.userId === null);
console.log(`š Found ${nullUserIdRegistrations.length} registrations with null userId\n`);
// Check for registrations that might belong to SUPERADMIN
const superadminUsers = users.filter(u => u.role === 'SUPERADMIN');
console.log(`š Found ${superadminUsers.length} SUPERADMIN users:\n`);
superadminUsers.forEach(user => {
console.log(` - ${user.name} (${user.email}) - ID: ${user.id}`);
});
// Find registrations that might belong to SUPERADMIN users
for (const superadmin of superadminUsers) {
console.log(`\nš Checking registrations for SUPERADMIN: ${superadmin.name} (${superadmin.email})`);
// Find registrations by email match
const emailMatches = registrations.filter(r =>
r.email === superadmin.email && r.userId !== superadmin.id
);
if (emailMatches.length > 0) {
console.log(` š§ Found ${emailMatches.length} registrations with matching email but different userId:`);
emailMatches.forEach(reg => {
console.log(` - Registration ID: ${reg.id}`);
console.log(` Name: ${reg.firstName} ${reg.lastName}`);
console.log(` Email: ${reg.email}`);
console.log(` Current userId: ${reg.userId}`);
console.log(` Created by: ${reg.createdBy}`);
console.log(` Status: ${reg.status}`);
console.log(` Created: ${reg.createdAt}`);
});
// Ask if we should fix these
console.log(`\nā Should I link these registrations to SUPERADMIN ${superadmin.name}? (y/n)`);
// For now, let's just log what would be fixed
console.log(` š§ Would update ${emailMatches.length} registrations to userId: ${superadmin.id}`);
} else {
console.log(` ā
No email matches found for this SUPERADMIN`);
}
}
// Check for any registrations created by SUPERADMIN but not linked to them
for (const superadmin of superadminUsers) {
const createdBySuperadmin = registrations.filter(r =>
r.createdBy === superadmin.id && r.userId !== superadmin.id
);
if (createdBySuperadmin.length > 0) {
console.log(`\nš Found ${createdBySuperadmin.length} registrations created by SUPERADMIN ${superadmin.name} but not linked to them:`);
createdBySuperadmin.forEach(reg => {
console.log(` - Registration ID: ${reg.id}`);
console.log(` Name: ${reg.firstName} ${reg.lastName}`);
console.log(` Email: ${reg.email}`);
console.log(` Current userId: ${reg.userId}`);
console.log(` Status: ${reg.status}`);
});
}
}
// Show all registrations for debugging
console.log('\nš All registrations summary:');
registrations.forEach(reg => {
console.log(` - ${reg.id}: ${reg.firstName} ${reg.lastName} (${reg.email})`);
console.log(` userId: ${reg.userId}, createdBy: ${reg.createdBy}, status: ${reg.status}`);
});
} catch (error) {
console.error('ā Error:', error);
} finally {
await prisma.$disconnect();
}
}
checkAndFixUserApplicationMismatch();