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/models/professionalism.js
const config = require("../config/config");
const mysql = require("mysql2"); // Use mysql2 for connection pooling

// Create a connection pool
const pool = mysql.createPool({
  host: config.connection.host,
  user: config.connection.user,
  password: config.connection.password,
  database: config.connection.database,
  waitForConnections: true,
  connectionLimit: 10, // Adjust as needed
  queueLimit: 0, // Unlimited queue size
});

module.exports = {
  findAllProffesionalism: async () => {
    return new Promise((resolve, reject) => {
      pool.getConnection((err, connection) => {
        if (err) {
          return reject(err);
        }

        connection.query(
          "SELECT * FROM professionalism_evaluation",
          (error, result) => {
            connection.release();

            if (error) {
              return reject(error);
            }
            resolve(result);
          }
        );
      });
    });
  },

  createProffesonalismRecord: async (proffesionalism) => {
    return new Promise((resolve, reject) => {
      pool.getConnection((err, connection) => {
        if (err) {
          return reject(err);
        }

        connection.query(
          "INSERT INTO professionalism_evaluation SET ?",
          proffesionalism,
          (error, result) => {
            connection.release();

            if (error) {
              return reject(error);
            }
            resolve(result);
          }
        );
      });
    });
  },
  findProffesionalismRecordById: async (id) => {
    return new Promise((resolve, reject) => {
      pool.getConnection((err, connection) => {
        if (err) {
          return reject(err);
        }

        connection.query(
          "SELECT * FROM professionalism_evaluation where id=?",
          id,
          (error, result) => {
            connection.release();

            if (error) {
              return reject(error);
            }
            resolve(result[0]);
          }
        );
      });
    });
  },

  findPendingProffesionalismRecord: async (id) => {
    return new Promise((resolve, reject) => {
      pool.getConnection((err, connection) => {
        if (err) {
          return reject(err);
        }

        connection.query(
          "SELECT * FROM professionalism_evaluation where userId=? AND status = 'Pending'",
          id,
          (error, result) => {
            connection.release();

            if (error) {
              return reject(error);
            }
            resolve(result[0]);
          }
        );
      });
    });
  },

  findProffessionalismForEvaluationDvc: async (data) => {
    return new Promise((resolve, reject) => {
      pool.getConnection((err, connection) => {
        if (err) {
          return reject(err);
        }

        connection.query(
          "SELECT * FROM professionalism_evaluation where userId=? AND sessionId=? AND status = 'Pending'", // Change status to Evaluated
          [data.userId, data.sessionId],
          (error, result) => {
            connection.release();

            if (error) {
              return reject(error);
            }
            resolve(result[0]);
          }
        );
      });
    });
  },

  findUserProffesionalismForCompilation(data) {
    return new Promise((resolve, reject) => {
      pool.getConnection((err, connection) => {
        if (err) {
          return reject(err);
        }

        connection.query(
          "SELECT * FROM professionalism_evaluation where userId =? and sessionId=? and self_submite_yn='Y'",
          [data.userId, data.sessionId],
          (error, result) => {
            connection.release();

            if (error) {
              return reject(error);
            }
            resolve(result[0]);
          }
        );
      });
    });
  },

  findHodProffessionalismForCompilation(data) {
    return new Promise((resolve, reject) => {
      pool.getConnection((err, connection) => {
        if (err) {
          return reject(err);
        }

        connection.query(
          "SELECT * FROM professionalism_evaluation where userId =? and sessionId=? and status = 'Pending' and self_submite_yn='Y'",
          [data.userId, data.sessionId],
          (error, result) => {
            connection.release();

            if (error) {
              return reject(error);
            }
            resolve(result[0]);
          }
        );
      });
    });
  },

  updateProffesionalismRecord: async (updatedProff) => {
    return new Promise((resolve, reject) => {
      pool.getConnection((err, connection) => {
        if (err) {
          return reject(err);
        }

        const query = `
                  UPDATE professionalism_evaluation SET
              proffesionalism_memeber_board_h= ?,
              proffesionalism_exhibits_respect_h= ?,
              proffesionalism_student_respect_h= ?,
              proffesionalism_initiative_h= ?,
              proffesionalism_manage_emotions_h= ?,
              proffesionalism_continued_developement_h= ?,
              proffesionalism_complete_tasks_h= ?,
              updatedAt= ?,
              updated_by= ?,
              hod_submited_yn= ?
              WHERE id = ?`;

        const values = [
          updatedProff.proffesionalism_memeber_board_h,
          updatedProff.proffesionalism_exhibits_respect_h,
          updatedProff.proffesionalism_student_respect_h,
          updatedProff.proffesionalism_initiative_h,
          updatedProff.proffesionalism_manage_emotions_h,
          updatedProff.proffesionalism_continued_developement_h,
          updatedProff.proffesionalism_complete_tasks_h,
          updatedProff.updatedAt,
          updatedProff.updated_by,
          updatedProff.hod_submited_yn,
          updatedProff.id,
        ];
        connection.query(query, values, (error, result) => {
          connection.release();

          if (error) {
            return reject(error);
          }
          resolve(result);
        });
      });
    });
  },
};