![]() 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 prisma = new PrismaClient();
async function setupDefaultChatRooms() {
console.log('šļø Setting up default chat rooms...');
try {
// Find admin user
const adminUser = await prisma.user.findFirst({
where: { role: 'ADMIN' }
});
if (!adminUser) {
console.log('ā No admin user found. Please create an admin user first.');
return;
}
// Default chat rooms to create
const defaultRooms = [
{
name: 'General',
description: 'General discussion for all members',
type: 'GROUP',
isPublic: true
},
{
name: 'Legal Support',
description: 'Legal questions and support discussions',
type: 'GROUP',
isPublic: true
},
{
name: 'Announcements',
description: 'Important announcements and updates',
type: 'GROUP',
isPublic: true
}
];
for (const roomData of defaultRooms) {
// Check if room already exists
const existingRoom = await prisma.chatRoom.findFirst({
where: { name: roomData.name }
});
if (existingRoom) {
console.log(`ā
Room "${roomData.name}" already exists`);
continue;
}
// Create the room with admin as creator
const newRoom = await prisma.chatRoom.create({
data: {
...roomData,
createdBy: { connect: { id: adminUser.id } },
participants: {
create: {
userId: adminUser.id,
role: 'ADMIN'
}
}
},
include: {
participants: {
include: {
user: { select: { id: true, name: true, email: true, role: true } }
}
}
}
});
console.log(`ā
Created room "${newRoom.name}" with ID: ${newRoom.id}`);
}
// Get all users and add them to public rooms
const allUsers = await prisma.user.findMany();
const publicRooms = await prisma.chatRoom.findMany({
where: { isPublic: true },
include: { participants: true }
});
console.log(`š„ Adding ${allUsers.length} users to ${publicRooms.length} public rooms...`);
for (const room of publicRooms) {
for (const user of allUsers) {
// Check if user is already a participant
const isParticipant = room.participants.some(p => p.userId === user.id);
if (!isParticipant) {
await prisma.chatParticipant.create({
data: {
userId: user.id,
chatRoomId: room.id,
role: user.role === 'ADMIN' ? 'ADMIN' : 'MEMBER'
}
});
console.log(` Added ${user.name} to "${room.name}"`);
}
}
}
console.log('š Chat rooms setup completed successfully!');
// Show summary
const roomCount = await prisma.chatRoom.count();
const participantCount = await prisma.chatParticipant.count();
console.log(`\nš Summary:`);
console.log(` š¬ Total chat rooms: ${roomCount}`);
console.log(` š„ Total participants: ${participantCount}`);
} catch (error) {
console.error('ā Error setting up chat rooms:', error);
} finally {
await prisma.$disconnect();
}
}
setupDefaultChatRooms();