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);
});
});
});
},
};