@@ -101,7 +101,7 @@ export class WebPortal {
101101 delete options . exception ;
102102 }
103103
104- console . log ( options )
104+ console . log ( options ) ;
105105 let header ;
106106 if ( options . authenticated ) {
107107 header = await this . session . get_headers ( ) ; // Assumes calling method is authenticated
@@ -139,7 +139,7 @@ export class WebPortal {
139139 throw new exception ( "JIIT Web Portal server is temporarily unavailable (HTTP 513). Please try again later." ) ;
140140 }
141141 if ( response . status === 401 ) {
142- throw new SessionExpired ( response . error ) ;
142+ throw new SessionExpired ( response . error ) ;
143143 }
144144
145145 const resp = await response . json ( ) ;
@@ -150,7 +150,7 @@ export class WebPortal {
150150 return resp ;
151151 } catch ( error ) {
152152 // Handle CORS errors
153- if ( error instanceof TypeError && error . message . includes ( ' CORS' ) ) {
153+ if ( error instanceof TypeError && error . message . includes ( " CORS" ) ) {
154154 throw new exception ( "JIIT Web Portal server is temporarily unavailable. Please try again later." ) ;
155155 }
156156 throw new exception ( error . message || "Unknown error" ) ;
@@ -507,6 +507,101 @@ export class WebPortal {
507507 const resp = await this . __hit ( "POST" , API + ENDPOINT , { json : payload , authenticated : true } ) ;
508508 return resp [ "response" ] ;
509509 }
510+
511+ async fill_feedback_form ( feedback_option ) {
512+ const SEMESTER_ENDPOINT = "/feedbackformcontroller/getFeedbackEvent" ;
513+ const payload = {
514+ instituteid : this . session . instituteid ,
515+ } ;
516+ const resp = await this . __hit ( "POST" , API + SEMESTER_ENDPOINT , { json : payload , authenticated : true } ) ;
517+ let semesters = resp [ "response" ] [ "eventList" ] ;
518+ let latest_semester = semesters [ semesters . length - 1 ] ;
519+ let latest_semester_code = latest_semester [ "eventcode" ] ;
520+ let latest_semester_event_id = latest_semester [ "eventid" ] ;
521+ let latest_semester_event_description = latest_semester [ "eventdescription" ] ;
522+
523+ const GRID_ENDPOINT = "/feedbackformcontroller/getGriddataForFeedback" ;
524+ const grid_payload = await serialize_payload ( {
525+ instituteid : this . session . instituteid ,
526+ studentid : this . session . memberid ,
527+ eventid : latest_semester_event_id ,
528+ } ) ;
529+ const grid_resp = await this . __hit ( "POST" , API + GRID_ENDPOINT , { json : grid_payload , authenticated : true } ) ;
530+ let grid_data = grid_resp [ "response" ] [ "gridData" ] ;
531+
532+ // instituteid
533+ // eventid
534+ // eventdescription
535+ let question_feedback_payload_array = grid_data . map ( ( data ) => {
536+ return {
537+ instituteid : this . session . instituteid ,
538+ eventid : latest_semester_event_id ,
539+ eventdescription : latest_semester_event_description ,
540+ facultyid : data [ "employeeid" ] ,
541+ facultyname : data [ "employeename" ] ,
542+ registrationid : data [ "registrationid" ] ,
543+ studentid : data [ "studentid" ] ,
544+ subjectcode : data [ "subjectcode" ] ,
545+ subjectcomponentcode : data [ "subjectcomponentcode" ] ,
546+ subjectcomponentid : data [ "subjectcomponentid" ] ,
547+ subjectdescription : data [ "subjectdescription" ] ,
548+ subjectid : data [ "subjectid" ] ,
549+ } ;
550+ } ) ;
551+ const GET_QUESTIONS_ENDPOINT = "/feedbackformcontroller/getIemQuestion" ;
552+ const SAVE_ENDPOINT = "/feedbackformcontroller/savedatalist" ;
553+
554+ for ( let question_feedback_payload of question_feedback_payload_array ) {
555+ try {
556+ const questions_api_resp = await this . __hit ( "POST" , API + GET_QUESTIONS_ENDPOINT , {
557+ json : question_feedback_payload ,
558+ authenticated : true ,
559+ } ) ;
560+ } catch ( error ) {
561+ continue ;
562+ }
563+
564+ // Process the response to get the list of questions
565+ if ( ! questions_api_resp || ! questions_api_resp . response || ! questions_api_resp . response . questionList ) {
566+ console . error (
567+ "Failed to retrieve question list or invalid response structure for payload:" ,
568+ question_feedback_payload ,
569+ "Response:" ,
570+ questions_api_resp
571+ ) ;
572+ // Skip to the next feedback item if data is missing
573+ continue ;
574+ }
575+ let actual_question_list = questions_api_resp [ "response" ] [ "questionList" ] ;
576+
577+ // Update each question with the provided feedback_option
578+ let questions_to_submit = actual_question_list . map ( ( q ) => ( {
579+ ...q , // Spread existing question properties
580+ rating : feedback_option , // Set the rating using the function's argument
581+ } ) ) ;
582+
583+ // Construct the payload for saving the feedback
584+ let save_data_payload = {
585+ instituteid : question_feedback_payload . instituteid , // This comes from this.session.instituteid via map
586+ studentid : this . session . memberid , // Logged-in user's ID
587+ eventid : question_feedback_payload . eventid , // This comes from latest_semester_event_id via map
588+ subjectid : question_feedback_payload . subjectid , // From the specific grid item
589+ facultyid : question_feedback_payload . facultyid , // From the specific grid item
590+ registrationid : question_feedback_payload . registrationid , // From the specific grid item
591+ questionid : questions_to_submit , // The list of questions with updated ratings
592+ facultycomments : null , // Defaulting to null; can be parameterized if needed
593+ coursecomments : null , // Defaulting to null; can be parameterized if needed
594+ } ;
595+ save_data_payload = await serialize_payload ( save_data_payload ) ;
596+
597+ // Send the feedback data to the SAVE_ENDPOINT
598+ await this . __hit ( "POST" , API + SAVE_ENDPOINT , {
599+ json : save_data_payload ,
600+ authenticated : true ,
601+ } ) ;
602+ // Optionally, collect or handle the response from SAVE_ENDPOINT
603+ }
604+ }
510605}
511606
512607/**
0 commit comments