HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux vmi1674223.contaboserver.net 5.4.0-182-generic #202-Ubuntu SMP Fri Apr 26 12:29:36 UTC 2024 x86_64
User: root (0)
PHP: 7.4.3-4ubuntu2.22
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //home/evaluation-leave/controllers/courseController.js
const Course = require("../models/course");

module.exports = {
  courseEvaluations: async (req, res) => {
    try {
      const result = await Course.findAllCourses();
      if (!result) {
        return res
          .status(404)
          .json({ message: "Sorry no data for courseEvaluation setup." });
      }

      console.log(`coursesEvaluation, successfully pulled on ${new Date()} `);

      return res.status(200).json(result);
    } catch (error) {
      console.error("Error occurred:", error);
      res.status(500).json({ error: true, message: "Internal Server Error" });
    }
  },

  courseEvaluationById: async (req, res) => {
    const { id } = req.body;
    try {
      const result = await Course.findcourseById(id);
      if (!result) {
        return res.status(404).json({
          message: "Sorry their is no CourseEvaluation with that id.",
        });
      }

      console.log(
        `CourseEvaluation with id ${id}, successfully pulled on ${new Date()} `
      );

      return res.status(200).json(result);
    } catch (error) {
      console.error("Error occurred:", error);
      res.status(500).json({ error: true, message: "Internal Server Error" });
    }
  },

  pendingCourseEvaluation: async (req, res) => {
    try {
      const result = await Course.findPendingCoursesEvaluationRecord(
        req.userId
      );
      if (!result) {
        return res.status(404).json({
          message: "Sorry no Pending CourseEvaluation for this user.",
        });
      }

      console.log(
        `Pending CourseEvaluation for user with id ${
          req.userId
        }, successfully pulled on ${new Date()} `
      );

      return res.status(200).json(result);
    } catch (error) {
      console.error("Error occurred:", error);
      res.status(500).json({ error: true, message: "Internal Server Error" });
    }
  },

  actionDvcCourseEvaluation: async (req, res) => {
    const { userId, sessionId } = req.body;

    try {
      const dvcData = {
        userId,
        sessionId,
      };
      const result = await Course.findCoursesForEvaluationDvc(dvcData);
      if (!result) {
        return res.status(404).json({
          message: "Sorry no CourseEvaluation recored for this user.",
        });
      }

      console.log(
        `Existing CourseEvaluation for user with id ${
          dvcData.userId
        }, successfully pulled on ${new Date()} by DVC `
      );

      return res.status(200).json(result);
    } catch (error) {
      console.error("Error occurred:", error);
      res.status(500).json({ error: true, message: "Internal Server Error" });
    }
  },

  courseForUserCompilation: async (req, res) => {
    const { sessionId } = req.body;

    try {
      const userData = {
        userId: req.userId,
        sessionId,
      };
      const result = await Course.findUserCourseForCompilation(userData);
      if (!result) {
        return res.status(404).json({
          message: "Sorry no CourseEvaluation recored for this user.",
        });
      }

      console.log(
        `Existing User CourseEvaluation for user with id ${
          userData.userId
        }, successfully pulled on ${new Date()}  `
      );

      return res.status(200).json(result);
    } catch (error) {
      console.error("Error occurred:", error);
      res.status(500).json({ error: true, message: "Internal Server Error" });
    }
  },

  courseForHodCompilation: async (req, res) => {
    const { userId, sessionId } = req.body;

    try {
      const hodData = {
        userId,
        sessionId,
      };
      const result = await Course.findHodCourseForCompilation(hodData);
      if (!result) {
        return res.status(404).json({
          message: "Sorry no CourseEvaluation recored for this user.",
        });
      }

      console.log(
        `Existing HOD CourseEvaluation for user with id ${
          hodData.userId
        }, successfully pulled on ${new Date()} by ${req.email} `
      );

      return res.status(200).json(result);
    } catch (error) {
      console.error("Error occurred:", error);
      res.status(500).json({ error: true, message: "Internal Server Error" });
    }
  },

  createCourseEvaluation: async (req, res) => {
    const {
      matrixId,
      sessionId,
      course_class_ontime,
      course_consultation_time,
      course_hosted_guest,
      course_instructional_tech,
      course_appropriate_design,
      course_multimedia_type,
      course_quality_instructional,
      course_updated_record,
      course_draft_exam,
      course_standard_exam,
      course_administer_exams,
      course_mark_script,
      course_process_grades,
      course_attend_school_meetings,
      course_support_school_activity,
    } = req.body;

    try {
      const newCourseEvaluation = {
        userId: req.userId,
        matrixId,
        sessionId,
        course_class_ontime,
        course_consultation_time,
        course_hosted_guest,
        course_instructional_tech,
        course_appropriate_design,
        course_multimedia_type,
        course_quality_instructional,
        course_updated_record,
        course_draft_exam,
        course_standard_exam,
        course_administer_exams,
        course_mark_script,
        course_process_grades,
        course_attend_school_meetings,
        course_support_school_activity,
        created_by: req.userId,
        self_submite_yn: "Y",
      };

      const result = await Course.createCorse(newCourseEvaluation);

      console.log(
        `successfully Created an anew CourseEvaluation Record on ${new Date()}`
      );
      return res.status(201).json(result);
    } catch (error) {
      console.error("Error occurred:", error);
      res.status(500).json({ error: true, message: "Internal Server Error" });
    }
  },

  updateCourseEvaluation: async (req, res) => {
    const {
      id,
      course_class_ontime_h,
      course_consultation_time_h,
      course_hosted_guest_h,
      course_instructional_tech_h,
      course_appropriate_design_h,
      course_multimedia_type_h,
      course_quality_instructional_h,
      course_updated_record_h,
      course_draft_exam_h,
      course_standard_exam_h,
      course_administer_exams_h,
      course_mark_script_h,
      course_process_grades_h,
      course_attend_school_meetings_h,
      course_support_school_activity_h,
    } = req.body;

    try {
      const serv = await Course.findcourseById(id);
      if (!serv) {
        return res.status(400).json({
          message: "Sorry there seems to be a problem. Try again latter",
        });
      }

      const updatedCourseEvaluation = {
        id,
        course_class_ontime_h,
        course_consultation_time_h,
        course_hosted_guest_h,
        course_instructional_tech_h,
        course_appropriate_design_h,
        course_multimedia_type_h,
        course_quality_instructional_h,
        course_updated_record_h,
        course_draft_exam_h,
        course_standard_exam_h,
        course_administer_exams_h,
        course_mark_script_h,
        course_process_grades_h,
        course_attend_school_meetings_h,
        course_support_school_activity_h,
        updated_by: req.userId,
        updatedAt: new Date(),
        hod_submited_yn: "Y",
      };

      const result = await Course.updateCourseEvaluation(
        updatedCourseEvaluation
      );

      console.log(
        `successfully Updated CourseEvaluation ${
          updatedCourseEvaluation.id
        } at ${new Date()}`
      );
      return res.status(201).json(result);
    } catch (error) {
      console.error("Error occurred:", error);
      res.status(500).json({ error: true, message: "Internal Server Error" });
    }
  },
};