@@ -99,6 +99,14 @@ async function main() {
9999 'billing.claim.manage' ,
100100 'billing.discount.approve' ,
101101
102+ // Appointment Module (3)
103+ 'appointment.create' ,
104+ 'appointment.read' ,
105+ 'appointment.update' ,
106+
107+ // Doctor Module (1)
108+ 'doctor.read' ,
109+
102110 // Beds/Inventory Module (3)
103111 'beds.status.read' ,
104112 'beds.assign.manage' ,
@@ -149,6 +157,10 @@ async function main() {
149157 RECEPTIONIST : [
150158 // Patient registration & management
151159 'patient.create' , 'patient.read' , 'patient.update' , 'patient.history.read' ,
160+ // Appointment scheduling
161+ 'appointment.create' , 'appointment.read' , 'appointment.update' ,
162+ // Doctor information for scheduling
163+ 'doctor.read' ,
152164 // Bed management
153165 'beds.status.read' , 'beds.assign.manage' ,
154166 // View own permissions
@@ -322,45 +334,134 @@ async function main() {
322334 }
323335
324336 const adminEmail = envAdminEmail ?? 'admin@neon.example' ;
325- const adminPassword = envAdminPassword ?? 'Admin123!' ;
337+ const adminPassword = envAdminPassword ;
338+
339+ if ( ! adminPassword ) {
340+ throw new Error ( 'RBAC_ADMIN_PASSWORD environment variable must be set before seeding' ) ;
341+ }
342+
326343 const hashed = await bcrypt . hash ( adminPassword , 10 ) ;
327344
328345 const adminUser = await prisma . user . upsert ( {
329346 where : { email : adminEmail } ,
330- update : { password : hashed , role : 'ADMIN' , roleEntityId : roleMap . ADMINISTRATOR . id } ,
347+ update : { password : hashed , role : 'ADMIN' as unknown as any , roleEntityId : roleMap . ADMINISTRATOR . id } ,
331348 create : {
332349 email : adminEmail ,
333350 password : hashed ,
334351 name : 'CureOS Administrator' ,
335- role : 'ADMIN' ,
352+ role : 'ADMIN' as unknown as any ,
336353 roleEntityId : roleMap . ADMINISTRATOR . id ,
337354 } ,
338355 } ) ;
339356
340357 console . log ( `✅ Created/updated admin user: ${ adminUser . email } \n` ) ;
341358
359+ // ========== CREATE TEST USERS FOR EACH ROLE ==========
360+ const testUsers = [
361+ { email : 'keshav@example.com' , name : 'Keshav Sharma' , role : 'RECEPTIONIST' } ,
362+ { email : 'doctor@example.com' , name : 'Dr. John Doe' , role : 'DOCTOR' } ,
363+ { email : 'nurse@example.com' , name : 'Jane Smith' , role : 'NURSE' } ,
364+ { email : 'pharmacist@example.com' , name : 'Alex Johnson' , role : 'PHARMACIST' } ,
365+ { email : 'labtech@example.com' , name : 'Rita Patel' , role : 'LAB_TECH' } ,
366+ ] ;
367+
368+ const testPassword = process . env . RBAC_TEST_PASSWORD ;
369+
370+ if ( ! testPassword ) {
371+ throw new Error ( 'RBAC_TEST_PASSWORD environment variable must be set before seeding' ) ;
372+ }
373+
374+ const testHashedPassword = await bcrypt . hash ( testPassword , 10 ) ;
375+
376+ console . log ( '📝 Creating/Updating test users with roles...' ) ;
377+ for ( const testUser of testUsers ) {
378+ const role = roleMap [ testUser . role ] ;
379+ if ( ! role ) {
380+ console . warn ( `⚠️ Role ${ testUser . role } not found, skipping ${ testUser . email } ` ) ;
381+ continue ;
382+ }
383+
384+ await prisma . user . upsert ( {
385+ where : { email : testUser . email } ,
386+ update : {
387+ password : testHashedPassword ,
388+ role : testUser . role as unknown as any ,
389+ roleEntityId : role . id
390+ } ,
391+ create : {
392+ email : testUser . email ,
393+ password : testHashedPassword ,
394+ name : testUser . name ,
395+ role : testUser . role as unknown as any ,
396+ roleEntityId : role . id ,
397+ } ,
398+ } ) ;
399+ console . log ( ` ✓ ${ testUser . email } (${ testUser . role } )` ) ;
400+ }
401+ console . log ( '' ) ;
402+
403+ // ========== CREATE DUMMY DOCTORS ==========
404+ console . log ( '📋 Creating dummy doctors...' ) ;
405+ // Create dummy doctors with separate user accounts
406+ const dummyDoctors = [
407+ { email : 'cardio-doc@hospital.com' , name : 'Dr. John Doe' , specialization : 'Cardiology' , license : 'LIC001' } ,
408+ { email : 'derm-doc@hospital.com' , name : 'Dr. Sarah Johnson' , specialization : 'Dermatology' , license : 'LIC002' } ,
409+ { email : 'neuro-doc@hospital.com' , name : 'Dr. Michael Chen' , specialization : 'Neurology' , license : 'LIC003' } ,
410+ { email : 'ortho-doc@hospital.com' , name : 'Dr. Emily Davis' , specialization : 'Orthopedics' , license : 'LIC004' } ,
411+ { email : 'peds-doc@hospital.com' , name : 'Dr. Robert Wilson' , specialization : 'Pediatrics' , license : 'LIC005' } ,
412+ ] ;
413+
414+ const doctorRole = await prisma . roleEntity . findFirst ( {
415+ where : { name : 'DOCTOR' } ,
416+ } ) ;
417+
418+ for ( const docData of dummyDoctors ) {
419+ // Create or update doctor user
420+ const doctorUser = await prisma . user . upsert ( {
421+ where : { email : docData . email } ,
422+ update : { name : docData . name } ,
423+ create : {
424+ email : docData . email ,
425+ name : docData . name ,
426+ password : await bcrypt . hash ( process . env . RBAC_DOCTOR_PASSWORD || 'temp' , 10 ) ,
427+ role : 'DOCTOR' as unknown as any ,
428+ roleEntityId : doctorRole ?. id ,
429+ } ,
430+ } ) ;
431+
432+ // Create or update doctor record
433+ await prisma . doctor . upsert ( {
434+ where : { licenseNumber : docData . license } ,
435+ update : { specialization : docData . specialization } ,
436+ create : {
437+ specialization : docData . specialization ,
438+ licenseNumber : docData . license ,
439+ userId : doctorUser . id ,
440+ } ,
441+ } ) ;
442+
443+ console . log ( ` ✓ ${ docData . name } (${ docData . specialization } )` ) ;
444+ }
445+ console . log ( '' ) ;
446+
342447 // ========== SEED COMPLETE - SUMMARY ==========
343448 console . log ( '╔════════════════════════════════════════════════════════════╗' ) ;
344449 console . log ( '║ RBAC SEEDING COMPLETE - HOSPITAL SYSTEM ║' ) ;
345450 console . log ( '╠════════════════════════════════════════════════════════════╣' ) ;
346451 console . log ( `║ Permissions: ${ allPermissions . length } ` . padEnd ( 62 ) + '║' ) ;
347452 console . log ( `║ Roles: ${ Object . keys ( roleMap ) . length } (Admin, Doctor, Nurse, Pharmacist, Lab Tech, ...)` . padEnd ( 62 ) + '║' ) ;
348- console . log ( `║ Users: 1 Administrator ` . padEnd ( 62 ) + '║' ) ;
453+ console . log ( `║ Users: 6 (1 Admin + 5 Test Users) ` . padEnd ( 62 ) + '║' ) ;
349454 console . log ( '╠════════════════════════════════════════════════════════════╣' ) ;
350455 console . log ( '║ Role Summary:' . padEnd ( 62 ) + '║' ) ;
351456 for ( const [ roleName , perms ] of Object . entries ( rolePermissions ) ) {
352457 const summary = `${ roleName } : ${ perms . length } permissions` ;
353458 console . log ( `║ ${ summary } ` . padEnd ( 62 ) + '║' ) ;
354459 }
355460 console . log ( '╠════════════════════════════════════════════════════════════╣' ) ;
356- if ( ! isProdLike ) {
357- console . log ( `║ 🔐 Admin Credentials: ║` ) ;
358- console . log ( `║ Email: ${ adminEmail } ` . padEnd ( 62 ) + '║' ) ;
359- console . log ( `║ Password: ${ adminPassword } ` . padEnd ( 62 ) + '║' ) ;
360- console . log ( '║ ⚠️ CHANGE credentials before production deployment ║' ) ;
361- } else {
362- console . log ( '║ ✓ Production mode - admin password not displayed ║' ) ;
363- }
461+ console . log ( '║ ⚠️ IMPORTANT: Set these environment variables before seeding:║' ) ;
462+ console . log ( '║ - RBAC_ADMIN_PASSWORD ║' ) ;
463+ console . log ( '║ - RBAC_TEST_PASSWORD ║' ) ;
464+ console . log ( '║ - RBAC_DOCTOR_PASSWORD ║' ) ;
364465 console . log ( '╚════════════════════════════════════════════════════════════╝\n' ) ;
365466}
366467
0 commit comments