@@ -56,6 +56,7 @@ interface RoutineData {
5656
5757async function processRoutineData ( routineData : RoutineData ) {
5858 try {
59+ // Create or update the routine
5960 const routine = await prisma . routine . upsert ( {
6061 where : {
6162 id : routineData . timeTables . length > 0 ? routineData . timeTables [ 0 ] . newRoutineId : 0 ,
@@ -72,23 +73,27 @@ async function processRoutineData(routineData: RoutineData) {
7273 } ) ;
7374
7475 for ( const timeTableData of routineData . timeTables ) {
76+ // Find or create the teacher based on email
77+ const teacherId = Math . floor ( Math . random ( ) * 100000 ) ; // Generate a random ID
7578 const teacher = await prisma . teacher . upsert ( {
76- where : { id : parseInt ( timeTableData . newRoutineId . toString ( ) + timeTableData . lecturerEmail . length , 10 ) % 1000000000 } ,
79+ where : { id : teacherId } , // Use the generated ID
7780 update : {
7881 email : timeTableData . lecturerEmail ,
7982 name : timeTableData . lecturerEmail . split ( '@' ) [ 0 ] ,
8083 } ,
8184 create : {
82- id : parseInt ( timeTableData . newRoutineId . toString ( ) + timeTableData . lecturerEmail . length , 10 ) % 1000000000 ,
85+ id : teacherId ,
8386 name : timeTableData . lecturerEmail . split ( '@' ) [ 0 ] ,
8487 email : timeTableData . lecturerEmail ,
8588 } ,
8689 } ) ;
8790
91+ // Extract subject name and code from the subject string
8892 const subjectParts = timeTableData . subject . split ( ' ' ) ;
8993 const subjectCode = subjectParts [ 0 ] ;
9094 const subjectName = subjectParts . slice ( 1 ) . join ( ' ' ) ;
9195
96+ // Find or create the subject
9297 const subject = await prisma . subject . upsert ( {
9398 where : {
9499 id : parseInt ( subjectCode . replace ( / \D / g, '' ) , 10 ) || Math . floor ( Math . random ( ) * 100000 )
@@ -103,6 +108,7 @@ async function processRoutineData(routineData: RoutineData) {
103108 } ,
104109 } ) ;
105110
111+ // Create or update the time table entry
106112 await prisma . timeTable . upsert ( {
107113 where : {
108114 id : parseInt ( timeTableData . newRoutineId . toString ( ) + timeTableData . day , 10 ) % 1000000000
0 commit comments