diff --git a/database/Models/Etudiants.js b/database/Models/Etudiants.js index 3b8c76e..59ed8e9 100644 --- a/database/Models/Etudiants.js +++ b/database/Models/Etudiants.js @@ -261,7 +261,7 @@ async function createTranche(etudiant_id, tranchename, montant) { const sql = 'INSERT INTO trancheecolage (etudiant_id, tranchename, montant) VALUES (?, ?, ?)' try { - let [result] = pool.query(sql, [etudiant_id, tranchename, montant]) + let [result] = await pool.query(sql, [etudiant_id, tranchename, montant]) return { success: true, @@ -273,46 +273,66 @@ async function createTranche(etudiant_id, tranchename, montant) { } async function getTranche(id) { - const query = database.prepare('SELECT * FROM trancheecolage WHERE etudiant_id = ?') + const sql = 'SELECT * FROM trancheecolage WHERE etudiant_id = ?' try { - let response = query.all(id) + let [rows] = await pool.query(sql, [id]) - return response + return rows } catch (error) { return error } } async function updateTranche(id, tranchename, montant) { - const query = database.prepare( - 'UPDATE trancheecolage SET tranchename = ?, montant = ? WHERE id = ?' - ) + const sql = 'UPDATE trancheecolage SET tranchename = ?, montant = ? WHERE id = ?' try { - let response = query.run(tranchename, montant, id) + const [result] = await pool.query(sql, [tranchename, montant, id]) - return response + if (result.affectedRows === 0) { + return { + success: false, + message: 'Année universitaire non trouvé.' + } + } + + return { + success: true, + message: 'Année universitaire supprimé avec succès.' + } } catch (error) { return error } } async function deleteTranche(id) { - const query = database.prepare('DELETE FROM trancheecolage WHERE id = ?') + const sql = 'DELETE FROM trancheecolage WHERE id = ?' try { - let response = query.run(id) + let [result] = await pool.query(sql, [id]) - return response + if (result.affectedRows === 0) { + return { + success: false, + message: 'Année universitaire non trouvé.' + } + } + + return { + success: true, + message: 'Année universitaire supprimé avec succès.' + } } catch (error) { return error } } async function getSingleTranche(id) { + const sql = 'SELECT * FROM trancheecolage WHERE id = ?' try { - return await database.prepare('SELECT * FROM trancheecolage WHERE id = ?').get(id) + const [rows] = await pool.query(sql, [id]) + return rows[0] } catch (error) { return error } diff --git a/database/Models/NoteRepechage.js b/database/Models/NoteRepechage.js index e544dd9..8cd2dd7 100644 --- a/database/Models/NoteRepechage.js +++ b/database/Models/NoteRepechage.js @@ -1,6 +1,4 @@ -const { database } = require('../database.backup') -const { getNiveau } = require('./Niveau') -const { matiereSysteme } = require('../function/System') +const { pool } = require('../database') /** * Function to insert notes into the database @@ -16,28 +14,32 @@ async function insertNoteRepech( formData, annee_scolaire ) { - // Extract keys and values dynamically - const matiere_id = Object.keys(formData) + const matiere_ids = Object.keys(formData) const values = Object.values(formData) - const query = database.prepare( - `INSERT INTO notesrepech (etudiant_id, matiere_id, etudiant_niveau, mention_id, note, annee_scolaire) VALUES (?, ?, ?, ?, ?, ?)` - ) - console.log(annee_scolaire) + const query = ` + INSERT INTO notesrepech + (etudiant_id, matiere_id, etudiant_niveau, mention_id, note, annee_scolaire) + VALUES (?, ?, ?, ?, ?, ?) + ` + try { let response - for (let j = 0; j < matiere_id.length; j++) { - response = await query.run( + for (let j = 0; j < matiere_ids.length; j++) { + const note = parseFloat(values[j].replace(',', '.')) || 0 + const [result] = await pool.query(query, [ etudiant_id, - matiere_id[j], + matiere_ids[j], etudiant_niveau, mention_id, - parseFloat(values[j].replace(',', '.')) || 0, + note, annee_scolaire - ) + ]) + response = result } return response } catch (error) { + console.error('Insert error:', error) return error } } @@ -47,12 +49,12 @@ async function insertNoteRepech( * @returns promise */ async function getNoteOnline() { - const query = database.prepare('SELECT notes.* FROM notes ') + const sql = 'SELECT notes.* FROM notes ' try { - let response = await query.all() + let [rows] = await pool.query(sql) - return response + return rows } catch (error) { return error } @@ -63,17 +65,19 @@ async function getNoteOnline() { * @returns promise */ async function getNoteRepech(id, niveau) { - let semestre = await matiereSysteme(niveau) - - const query2 = database.prepare( - 'SELECT notesrepech.*, matieres.* FROM notesrepech JOIN matieres ON (notesrepech.matiere_id = matieres.id) WHERE notesrepech.etudiant_id = ? AND notesrepech.etudiant_niveau = ?' - ) + const query = ` + SELECT notesrepech.*, matieres.* + FROM notesrepech + JOIN matieres ON notesrepech.matiere_id = matieres.id + WHERE notesrepech.etudiant_id = ? + AND notesrepech.etudiant_niveau = ? + ` try { - let response2 = query2.all(id, niveau) - return response2 + const [rows] = await pool.query(query, [id, niveau]) + return rows } catch (error) { - console.error('Error in query2:', error) + console.error('Error in getNoteRepech:', error) return error } } @@ -83,15 +87,11 @@ async function getNoteRepech(id, niveau) { * @returns {Promise} - Promise resolving to an array of notes or an empty array */ async function verifyEtudiantIfHeHasNotesRepech() { - try { - // Prepare the query to filter by etudiant_id and etudiant_niveau - const query = database.prepare('SELECT DISTINCT etudiant_id, etudiant_niveau FROM notesrepech') - - // Execute the query with the provided parameters - const response = query.all() + const query = `SELECT DISTINCT etudiant_id, etudiant_niveau FROM notesrepech` - // Return the response - return response + try { + const [rows] = await pool.query(query) + return rows } catch (error) { console.error('Error verifying student notes:', error) throw error @@ -104,25 +104,32 @@ async function verifyEtudiantIfHeHasNotesRepech() { * @returns promise */ async function showMoyenRepech(niveau, scolaire) { - const query = database.prepare( - `SELECT DISTINCT etudiant_id FROM notesrepech WHERE etudiant_niveau = ? AND annee_scolaire = ?` - ) - - let etudiantWithNotes = await query.all(niveau, scolaire) + try { + // 1. Get distinct student IDs with notes repech + const [etudiantWithNotes] = await pool.query( + `SELECT DISTINCT etudiant_id FROM notesrepech WHERE etudiant_niveau = ? AND annee_scolaire = ?`, + [niveau, scolaire] + ) - let allEtudiantWithNotes = [] + const query2 = ` + SELECT notesrepech.*, etudiants.*, matieres.id AS matiere_id, matieres.nom AS nomMat, matieres.credit + FROM notesrepech + INNER JOIN etudiants ON notesrepech.etudiant_id = etudiants.id + INNER JOIN matieres ON notesrepech.matiere_id = matieres.id + WHERE notesrepech.etudiant_id = ? + ` - const query2 = database.prepare( - 'SELECT notesrepech.*, etudiants.*, matieres.id, matieres.nom AS nomMat, matieres.credit FROM notesrepech INNER JOIN etudiants ON (notesrepech.etudiant_id = etudiants.id) INNER JOIN matieres ON (notesrepech.matiere_id = matieres.id) WHERE notesrepech.etudiant_id = ?' - ) + let allEtudiantWithNotes = [] - try { - for (let index = 0; index < etudiantWithNotes.length; index++) { - allEtudiantWithNotes.push(query2.all(etudiantWithNotes[index].etudiant_id)) + // 2. Loop over each student and get their notes repech + for (const etudiant of etudiantWithNotes) { + const [rows] = await pool.query(query2, [etudiant.etudiant_id]) + allEtudiantWithNotes.push(rows) } return allEtudiantWithNotes } catch (error) { + console.error('Error in showMoyenRepech:', error) return error } } @@ -134,57 +141,80 @@ async function showMoyenRepech(niveau, scolaire) { * @returns {Promise} - Promise resolving to the database response or an error */ async function updateNoteRepech(formData, niveau, id) { - // Extract keys and values dynamically - const matiere_id = Object.keys(formData) + const matiere_ids = Object.keys(formData) const values = Object.values(formData) - const query = database.prepare( - 'UPDATE notesrepech SET note= ? WHERE etudiant_id = ? AND etudiant_niveau = ? AND matiere_id = ?' - ) + const query = ` + UPDATE notesrepech + SET note = ? + WHERE etudiant_id = ? AND etudiant_niveau = ? AND matiere_id = ? + ` try { let response - for (let index = 0; index < matiere_id.length; index++) { + for (let index = 0; index < matiere_ids.length; index++) { let data = values[index] + + // Convert string number with comma to float, e.g. "12,5" => 12.5 if (typeof data === 'string') { - console.log(parseFloat(data.replace(',', '.'))) + data = parseFloat(data.replace(',', '.')) } else { - console.log(parseFloat(String(data).replace(',', '.'))) + data = parseFloat(String(data).replace(',', '.')) } - response = await query.run(data, id, niveau, matiere_id[index]) + + // Optional: console log to verify conversion + console.log(data) + + const [result] = await pool.query(query, [data, id, niveau, matiere_ids[index]]) + response = result } return response } catch (error) { + console.error('Error updating notes repech:', error) return error } } async function blockShowMoyeneRepech() { - const query = database.prepare( - 'SELECT DISTINCT etudiant_niveau, annee_scolaire FROM notesrepech ORDER BY annee_scolaire DESC' - ) - - const queryMention = database.prepare('SELECT * FROM mentions') + const query = ` + SELECT DISTINCT etudiant_niveau, annee_scolaire + FROM notesrepech + ORDER BY annee_scolaire DESC + ` + + const queryMention = `SELECT * FROM mentions` + + const query2 = ` + SELECT notesrepech.*, + etudiants.id AS etudiantsId, + etudiants.mention_id AS mentionId, + etudiants.niveau, + matieres.* + FROM notesrepech + INNER JOIN etudiants ON notesrepech.etudiant_id = etudiants.id + INNER JOIN matieres ON notesrepech.matiere_id = matieres.id + WHERE notesrepech.etudiant_niveau = ? AND notesrepech.annee_scolaire = ? + ` try { - let response = await query.all() - let mention = await queryMention.all() - let niveau = response.map((item) => item.etudiant_niveau) - let annee_scolaire = response.map((item) => item.annee_scolaire) - const query2 = database.prepare( - `SELECT notesrepech.*, etudiants.id AS etudiantsId, etudiants.mention_id AS mentionId, etudiants.niveau, matieres.* FROM notesrepech INNER JOIN etudiants ON (notesrepech.etudiant_id = etudiants.id) INNER JOIN matieres ON (notesrepech.matiere_id = matieres.id) WHERE notesrepech.etudiant_niveau = ? AND notesrepech.annee_scolaire = ?` - ) + const [response] = await pool.query(query) + const [mention] = await pool.query(queryMention) + + const niveau = response.map((item) => item.etudiant_niveau) + const annee_scolaire = response.map((item) => item.annee_scolaire) let allData = [] - for (let index = 0; index < niveau.length; index++) { - allData.push(await query2.all(niveau[index], annee_scolaire[index])) + for (let i = 0; i < niveau.length; i++) { + const [rows] = await pool.query(query2, [niveau[i], annee_scolaire[i]]) + allData.push(rows) } return { response, allData, mention } } catch (error) { + console.error('Error in blockShowMoyeneRepech:', error) return error } } @@ -197,15 +227,20 @@ async function blockShowMoyeneRepech() { * @returns promise */ async function getMatiereAndNoteRepech(id, niveau, annee_scolaire) { - const query = database.prepare( - 'SELECT * FROM notesrepech INNER JOIN matieres ON (notesrepech.matiere_id = matieres.id) WHERE notesrepech.etudiant_id = ? AND notesrepech.etudiant_niveau = ? AND notesrepech.annee_scolaire = ?' - ) + const query = ` + SELECT * + FROM notesrepech + INNER JOIN matieres ON notesrepech.matiere_id = matieres.id + WHERE notesrepech.etudiant_id = ? + AND notesrepech.etudiant_niveau = ? + AND notesrepech.annee_scolaire = ? + ` try { - let response = await query.all(id, niveau, annee_scolaire) - - return response + const [rows] = await pool.query(query, [id, niveau, annee_scolaire]) + return rows } catch (error) { + console.error('Error in getMatiereAndNoteRepech:', error) return error } } diff --git a/database/Models/NoteSysrem.js b/database/Models/NoteSysrem.js index b544a79..1978ae4 100644 --- a/database/Models/NoteSysrem.js +++ b/database/Models/NoteSysrem.js @@ -1,16 +1,16 @@ -const { database } = require('../database.backup') +const { pool } = require('../database') /** * function to get all Systeme note * @returns promise */ async function getSysteme() { - const query = database.prepare('SELECT * FROM notesystems') + const sql = 'SELECT * FROM notesystems' try { - let response = await query.get() + let [rows] = await pool.query(sql) - return response + return rows[0] } catch (error) { return error } @@ -25,14 +25,22 @@ async function getSysteme() { * @returns promise */ async function updateSysteme(id, admis, redouble, renvoyer) { - const query = database.prepare( - 'UPDATE notesystems SET admis = ?, redouble = ?, renvoyer = ? WHERE id = ?' - ) + const sql = 'UPDATE notesystems SET admis = ?, redouble = ?, renvoyer = ? WHERE id = ?' try { - let response = await query.run(admis, redouble, renvoyer, id) + let [result] = await pool.query(sql, [admis, redouble, renvoyer, id]) - return response + if (result.affectedRows === 0) { + return { + success: false, + message: 'Année universitaire non trouvé.' + } + } + + return { + success: true, + message: 'Année universitaire supprimé avec succès.' + } } catch (error) { return error } diff --git a/database/Models/Notes copy.js b/database/Models/Notes copy.js new file mode 100644 index 0000000..af101e4 --- /dev/null +++ b/database/Models/Notes copy.js @@ -0,0 +1,320 @@ +const { pool } = require('../database') +const { matiereSysteme } = require('../function/System') + +/** + * Function to insert notes into the database + * @param {Object} formData - The form data containing subject names and values + * @param {number} etudiant_id - The student ID + * @param {string} etudiant_niveau - The student level + * @returns {Promise} - Promise resolving to the database response or an error + */ +async function insertNote(etudiant_id, etudiant_niveau, mention_id, formData, annee_scolaire) { + const matiere_id = Object.keys(formData) + const values = Object.values(formData) + + const insertNoteSQL = ` + INSERT INTO notes (etudiant_id, matiere_id, etudiant_niveau, mention_id, note, annee_scolaire) + VALUES (?, ?, ?, ?, ?, ?) + ` + + const insertRepechSQL = ` + INSERT INTO notesrepech (etudiant_id, matiere_id, etudiant_niveau, mention_id, note, annee_scolaire) + VALUES (?, ?, ?, ?, ?, ?) + ` + + const connection = await pool.getConnection() + let newMatiereId = [] + + try { + await connection.beginTransaction() + + // Insert into notes table + for (let j = 0; j < matiere_id.length; j++) { + const noteValue = parseFloat(values[j].replace(',', '.')) || 0 + if (noteValue < 10) { + newMatiereId.push(matiere_id[j]) + } + + await connection.execute(insertNoteSQL, [ + etudiant_id, + matiere_id[j], + etudiant_niveau, + mention_id, + noteValue, + annee_scolaire + ]) + } + + // Insert into notesrepech with note = 0 + for (let j = 0; j < newMatiereId.length; j++) { + await connection.execute(insertRepechSQL, [ + etudiant_id, + newMatiereId[j], + etudiant_niveau, + mention_id, + 0, + annee_scolaire + ]) + } + + await connection.commit() + return { success: true } + } catch (error) { + await connection.rollback() + console.error('Error inserting notes:', error) + return { error: error.message } + } finally { + connection.release() + } +} + +/** + * + * @returns promise + */ +async function getNoteOnline() { + const sql = 'SELECT notes.* FROM notes ' + + try { + let [rows] = await pool.query(sql) + + return rows + } catch (error) { + return error + } +} + +/** + * + * @returns promise + */ +async function getNote(id, niveau, mention_id) { + // let semestre = await matiereSysteme(niveau) + + const query = database.prepare( + 'SELECT notes.*, matieres.* FROM notes JOIN matieres ON (notes.matiere_id = matieres.id) WHERE notes.etudiant_id = ? AND notes.etudiant_niveau = ?' + ) + // const matiereQuery = database.prepare(` + // SELECT DISTINCT m.* + // FROM matieres m + // JOIN matiere_semestre ms ON m.id = ms.matiere_id + // JOIN semestres s ON ms.semestre_id = s.id + // WHERE (s.nom LIKE ? OR s.nom LIKE ?) + // AND ms.mention_id = ? + // `) + + // let res = await matiereQuery.all(`%${semestre[0]}%`, `%${semestre[1]}%`, mention_id) + + let response = await query.all(id, niveau) + // const infoEtudiants = database.prepare('SELECT * FROM etudiants WHERE id = ?') + // let etudiant = await infoEtudiants.get(id) + + let arrayResponseIdMatiere = [] + for (let index = 0; index < response.length; index++) { + arrayResponseIdMatiere.push(response[index].matiere_id) + } + + // const filteredIds = res + // .filter((matiere) => !arrayResponseIdMatiere.includes(matiere.id)) + // .map((matiere) => matiere.id) + + // const json = filteredIds.reduce((acc, id) => { + // acc[id] = '0' + // return acc + // }, {}) + + const query2 = database.prepare( + 'SELECT notes.*, matieres.* FROM notes JOIN matieres ON (notes.matiere_id = matieres.id) WHERE notes.etudiant_id = ? AND notes.etudiant_niveau = ?' + ) + + try { + let response2 = query2.all(id, niveau) + return response2 + } catch (error) { + console.error('Error in query2:', error) + return error + } +} + +/** + * Verify if a student has notes + * @returns {Promise} - Promise resolving to an array of notes or an empty array + */ +async function verifyEtudiantIfHeHasNotes() { + try { + // Prepare the query to filter by etudiant_id and etudiant_niveau + const query = database.prepare('SELECT DISTINCT etudiant_id, etudiant_niveau FROM notes') + + // Execute the query with the provided parameters + const response = query.all() + + // Return the response + return response + } catch (error) { + console.error('Error verifying student notes:', error) + throw error + } +} + +/** + * function to show moyenne in screen + * + * @returns promise + */ +async function showMoyen(niveau, scolaire) { + const query = database.prepare( + `SELECT DISTINCT etudiant_id FROM notes WHERE etudiant_niveau = ? AND annee_scolaire = ?` + ) + + let etudiantWithNotes = await query.all(niveau, scolaire) + + let allEtudiantWithNotes = [] + + const query2 = database.prepare( + 'SELECT notes.*, etudiants.*, matieres.id, matieres.nom AS nomMat, matieres.credit FROM notes INNER JOIN etudiants ON (notes.etudiant_id = etudiants.id) INNER JOIN matieres ON (notes.matiere_id = matieres.id) WHERE notes.etudiant_id = ?' + ) + + try { + for (let index = 0; index < etudiantWithNotes.length; index++) { + allEtudiantWithNotes.push(query2.all(etudiantWithNotes[index].etudiant_id)) + } + + return allEtudiantWithNotes + } catch (error) { + return error + } +} + +/** + * function used when updating note + * @param {Object} formData - The form data containing subject names and values + * @param {string} niveau - The student level + * @returns {Promise} - Promise resolving to the database response or an error + */ +async function updateNote(formData, niveau, id, mention_id, annee_scolaire) { + // Extract keys and values dynamically + const matiere_id = Object.keys(formData) + const values = Object.values(formData) + + const query = database.prepare( + 'UPDATE notes SET note= ? WHERE etudiant_id = ? AND etudiant_niveau = ? AND matiere_id = ?' + ) + + const clearFromRepech = database.prepare( + 'DELETE FROM notesrepech WHERE etudiant_id = ? AND etudiant_niveau = ? AND matiere_id = ?' + ) + const insertRepechQuery = database.prepare( + `INSERT INTO notesrepech (etudiant_id, matiere_id, etudiant_niveau, mention_id, note, annee_scolaire) VALUES (?, ?, ?, ?, ?, ?)` + ) + + const checkRepechQuery = database.prepare( + 'SELECT * FROM notesrepech WHERE etudiant_id = ? AND matiere_id = ? AND etudiant_niveau = ?' + ) + + try { + let response + + for (let index = 0; index < matiere_id.length; index++) { + let data = values[index] + if (typeof data === 'string') { + data = parseFloat(data.replace(',', '.')) + } else { + data = parseFloat(String(data).replace(',', '.')) + } + let check = await checkRepechQuery.get(id, matiere_id[index], niveau) + if (data < 10) { + if (!check) { + insertRepechQuery.run(id, matiere_id[index], niveau, mention_id, 0, annee_scolaire) + } + response = await query.run(data, id, niveau, matiere_id[index]) + } else { + clearFromRepech.run(id, niveau, matiere_id[index]) + response = await query.run(data, id, niveau, matiere_id[index]) + } + } + + return response + } catch (error) { + return error + } +} + +async function blockShowMoyene() { + const query = database.prepare( + 'SELECT DISTINCT etudiant_niveau, annee_scolaire FROM notes ORDER BY annee_scolaire DESC' + ) + + const queryMention = database.prepare('SELECT * FROM mentions') + + try { + let response = await query.all() + let mention = await queryMention.all() + let niveau = response.map((item) => item.etudiant_niveau) + let annee_scolaire = response.map((item) => item.annee_scolaire) + const query2 = database.prepare( + `SELECT notes.*, etudiants.id AS etudiantsId, etudiants.mention_id AS mentionId, etudiants.niveau, matieres.* FROM notes INNER JOIN etudiants ON (notes.etudiant_id = etudiants.id) INNER JOIN matieres ON (notes.matiere_id = matieres.id) WHERE notes.etudiant_niveau = ? AND notes.annee_scolaire = ?` + ) + + let allData = [] + + for (let index = 0; index < niveau.length; index++) { + allData.push(await query2.all(niveau[index], annee_scolaire[index])) + } + + return { response, allData, mention } + } catch (error) { + return error + } +} + +/** + * get all note with matiere for single student + * @param {*} id + * @param {*} niveau + * @param {*} annee_scolaire + * @returns promise + */ +async function getMatiereAndNote(id, niveau, annee_scolaire) { + const query = database.prepare( + 'SELECT * FROM notes INNER JOIN matieres ON (notes.matiere_id = matieres.id) WHERE notes.etudiant_id = ? AND notes.etudiant_niveau = ? AND notes.annee_scolaire = ?' + ) + + try { + let response = await query.all(id, niveau, annee_scolaire) + + return response + } catch (error) { + return error + } +} + +async function getNotesWithRepechToDisplay(id, anneescolaire, niveau) { + const queryNoteNormal = database.prepare( + 'SELECT * FROM notes INNER JOIN matieres ON (notes.matiere_id = matieres.id) WHERE notes.etudiant_id = ? AND notes.annee_scolaire = ? AND notes.etudiant_niveau = ?' + ) + let noteNormal = await queryNoteNormal.all(id, anneescolaire, niveau) + + const queryNoteRepech = database.prepare( + 'SELECT * FROM notesrepech INNER JOIN matieres ON (notesrepech.matiere_id = matieres.id) WHERE notesrepech.etudiant_id = ? AND notesrepech.annee_scolaire = ? AND notesrepech.etudiant_niveau = ?' + ) + let noteRepech = await queryNoteRepech.all(id, anneescolaire, niveau) + + const semestreQuery = database.prepare( + 'SELECT * FROM semestres INNER JOIN matiere_semestre ON(semestres.id = matiere_semestre.semestre_id)' + ) + let semestre = await semestreQuery.all() + + return { noteNormal, noteRepech, semestre } +} + +module.exports = { + insertNote, + getNote, + showMoyen, + getNoteOnline, + verifyEtudiantIfHeHasNotes, + updateNote, + blockShowMoyene, + getMatiereAndNote, + getNotesWithRepechToDisplay +} diff --git a/database/Models/Notes.js b/database/Models/Notes.js index 1e58983..93e998e 100644 --- a/database/Models/Notes.js +++ b/database/Models/Notes.js @@ -1,5 +1,4 @@ -const { database } = require('../database.backup') -const { getNiveau } = require('./Niveau') +const { pool } = require('../database') const { matiereSysteme } = require('../function/System') /** @@ -10,58 +9,62 @@ const { matiereSysteme } = require('../function/System') * @returns {Promise} - Promise resolving to the database response or an error */ async function insertNote(etudiant_id, etudiant_niveau, mention_id, formData, annee_scolaire) { - // Extract keys and values dynamically const matiere_id = Object.keys(formData) const values = Object.values(formData) - const query = database.prepare( - `INSERT INTO notes (etudiant_id, matiere_id, etudiant_niveau, mention_id, note, annee_scolaire) VALUES (?, ?, ?, ?, ?, ?)` - ) + const insertNoteSQL = ` + INSERT INTO notes (etudiant_id, matiere_id, etudiant_niveau, mention_id, note, annee_scolaire) + VALUES (?, ?, ?, ?, ?, ?) + ` - const insertRepechQuery = database.prepare( - `INSERT INTO notesrepech (etudiant_id, matiere_id, etudiant_niveau, mention_id, note, annee_scolaire) VALUES (?, ?, ?, ?, ?, ?)` - ) + const insertRepechSQL = ` + INSERT INTO notesrepech (etudiant_id, matiere_id, etudiant_niveau, mention_id, note, annee_scolaire) + VALUES (?, ?, ?, ?, ?, ?) + ` - console.log(annee_scolaire) - try { - let response - let newMatiereId = [] + const connection = await pool.getConnection() + let newMatiereId = [] - // run the session normale - database.transaction(() => { - for (let j = 0; j < matiere_id.length; j++) { - if (values[j] < 10) { - newMatiereId.push(matiere_id[j]) - } + try { + await connection.beginTransaction() - response = query.run( - etudiant_id, - matiere_id[j], - etudiant_niveau, - mention_id, - parseFloat(values[j].replace(',', '.')) || 0, - annee_scolaire - ) - } - })() - - // run the second session and set it to be 0 to display it from screen - database.transaction(() => { - for (let j = 0; j < newMatiereId.length; j++) { - response = insertRepechQuery.run( - etudiant_id, - newMatiereId[j], - etudiant_niveau, - mention_id, - 0, - annee_scolaire - ) + // Insert into notes table + for (let j = 0; j < matiere_id.length; j++) { + const noteValue = parseFloat(values[j].replace(',', '.')) || 0 + if (noteValue < 10) { + newMatiereId.push(matiere_id[j]) } - })() - return response + await connection.execute(insertNoteSQL, [ + etudiant_id, + matiere_id[j], + etudiant_niveau, + mention_id, + noteValue, + annee_scolaire + ]) + } + + // Insert into notesrepech with note = 0 + for (let j = 0; j < newMatiereId.length; j++) { + await connection.execute(insertRepechSQL, [ + etudiant_id, + newMatiereId[j], + etudiant_niveau, + mention_id, + 0, + annee_scolaire + ]) + } + + await connection.commit() + return { success: true } } catch (error) { - return error + await connection.rollback() + console.error('Error inserting notes:', error) + return { error: error.message } + } finally { + connection.release() } } @@ -70,12 +73,12 @@ async function insertNote(etudiant_id, etudiant_niveau, mention_id, formData, an * @returns promise */ async function getNoteOnline() { - const query = database.prepare('SELECT notes.* FROM notes ') + const sql = 'SELECT notes.* FROM notes ' try { - let response = await query.all() + let [rows] = await pool.query(sql) - return response + return rows } catch (error) { return error } @@ -85,51 +88,42 @@ async function getNoteOnline() { * * @returns promise */ -async function getNote(id, niveau, mention_id) { - let semestre = await matiereSysteme(niveau) - - const query = database.prepare( - 'SELECT notes.*, matieres.* FROM notes JOIN matieres ON (notes.matiere_id = matieres.id) WHERE notes.etudiant_id = ? AND notes.etudiant_niveau = ?' - ) - const matiereQuery = database.prepare(` - SELECT DISTINCT m.* - FROM matieres m - JOIN matiere_semestre ms ON m.id = ms.matiere_id - JOIN semestres s ON ms.semestre_id = s.id - WHERE (s.nom LIKE ? OR s.nom LIKE ?) - AND ms.mention_id = ? - `) - - let res = await matiereQuery.all(`%${semestre[0]}%`, `%${semestre[1]}%`, mention_id) - - let response = await query.all(id, niveau) - const infoEtudiants = database.prepare('SELECT * FROM etudiants WHERE id = ?') - let etudiant = await infoEtudiants.get(id) - - let arrayResponseIdMatiere = [] - for (let index = 0; index < response.length; index++) { - arrayResponseIdMatiere.push(response[index].matiere_id) - } - - const filteredIds = res - .filter((matiere) => !arrayResponseIdMatiere.includes(matiere.id)) - .map((matiere) => matiere.id) - - const json = filteredIds.reduce((acc, id) => { - acc[id] = '0' - return acc - }, {}) +async function getNote(id, niveau) { + let connection + try { + connection = await pool.getConnection() + + // 1. Get all notes joined with matieres + const [response] = await connection.execute( + ` + SELECT notes.*, matieres.* + FROM notes + JOIN matieres ON notes.matiere_id = matieres.id + WHERE notes.etudiant_id = ? AND notes.etudiant_niveau = ? + `, + [id, niveau] + ) - const query2 = database.prepare( - 'SELECT notes.*, matieres.* FROM notes JOIN matieres ON (notes.matiere_id = matieres.id) WHERE notes.etudiant_id = ? AND notes.etudiant_niveau = ?' - ) + // 2. Optional: Build list of matiere_id (not used here but kept from original) + const arrayResponseIdMatiere = response.map((note) => note.matiere_id) + + // 3. Same query again (as in your original) — this is redundant unless changed + const [response2] = await connection.execute( + ` + SELECT notes.*, matieres.* + FROM notes + JOIN matieres ON notes.matiere_id = matieres.id + WHERE notes.etudiant_id = ? AND notes.etudiant_niveau = ? + `, + [id, niveau] + ) - try { - let response2 = query2.all(id, niveau) return response2 } catch (error) { - console.error('Error in query2:', error) - return error + console.error('Error in getNote:', error) + return { error: error.message } + } finally { + if (connection) connection.release() } } @@ -140,13 +134,13 @@ async function getNote(id, niveau, mention_id) { async function verifyEtudiantIfHeHasNotes() { try { // Prepare the query to filter by etudiant_id and etudiant_niveau - const query = database.prepare('SELECT DISTINCT etudiant_id, etudiant_niveau FROM notes') + const sql = 'SELECT DISTINCT etudiant_id, etudiant_niveau FROM notes' // Execute the query with the provided parameters - const response = query.all() + const [rows] = await pool.query(sql) // Return the response - return response + return rows } catch (error) { console.error('Error verifying student notes:', error) throw error @@ -159,29 +153,37 @@ async function verifyEtudiantIfHeHasNotes() { * @returns promise */ async function showMoyen(niveau, scolaire) { - const query = database.prepare( - `SELECT DISTINCT etudiant_id FROM notes WHERE etudiant_niveau = ? AND annee_scolaire = ?` - ) - - let etudiantWithNotes = await query.all(niveau, scolaire) + try { + // 1. Get distinct student IDs + const [etudiantWithNotes] = await pool.query( + `SELECT DISTINCT etudiant_id FROM notes WHERE etudiant_niveau = ? AND annee_scolaire = ?`, + [niveau, scolaire] + ) - let allEtudiantWithNotes = [] + let allEtudiantWithNotes = [] - const query2 = database.prepare( - 'SELECT notes.*, etudiants.*, matieres.id, matieres.nom AS nomMat, matieres.credit FROM notes INNER JOIN etudiants ON (notes.etudiant_id = etudiants.id) INNER JOIN matieres ON (notes.matiere_id = matieres.id) WHERE notes.etudiant_id = ?' - ) + // 2. Prepare the second query + const query2 = ` + SELECT notes.*, etudiants.*, matieres.id AS matiere_id, matieres.nom AS nomMat, matieres.credit + FROM notes + INNER JOIN etudiants ON notes.etudiant_id = etudiants.id + INNER JOIN matieres ON notes.matiere_id = matieres.id + WHERE notes.etudiant_id = ? + ` - try { + // 3. Loop over each student and fetch their notes for (let index = 0; index < etudiantWithNotes.length; index++) { - allEtudiantWithNotes.push(query2.all(etudiantWithNotes[index].etudiant_id)) + const etudiantId = etudiantWithNotes[index].etudiant_id + const [rows] = await pool.query(query2, [etudiantId]) + allEtudiantWithNotes.push(rows) // push just the rows, not [rows, fields] } return allEtudiantWithNotes } catch (error) { - return error + console.error('Error in showMoyen:', error) + return { error: error.message } } } - /** * function used when updating note * @param {Object} formData - The form data containing subject names and values @@ -189,81 +191,102 @@ async function showMoyen(niveau, scolaire) { * @returns {Promise} - Promise resolving to the database response or an error */ async function updateNote(formData, niveau, id, mention_id, annee_scolaire) { - // Extract keys and values dynamically const matiere_id = Object.keys(formData) const values = Object.values(formData) - const query = database.prepare( - 'UPDATE notes SET note= ? WHERE etudiant_id = ? AND etudiant_niveau = ? AND matiere_id = ?' - ) - - const clearFromRepech = database.prepare( - 'DELETE FROM notesrepech WHERE etudiant_id = ? AND etudiant_niveau = ? AND matiere_id = ?' - ) - const insertRepechQuery = database.prepare( - `INSERT INTO notesrepech (etudiant_id, matiere_id, etudiant_niveau, mention_id, note, annee_scolaire) VALUES (?, ?, ?, ?, ?, ?)` - ) - - const checkRepechQuery = database.prepare( - 'SELECT * FROM notesrepech WHERE etudiant_id = ? AND matiere_id = ? AND etudiant_niveau = ?' - ) - try { let response for (let index = 0; index < matiere_id.length; index++) { let data = values[index] + + // Convert string to float safely if (typeof data === 'string') { data = parseFloat(data.replace(',', '.')) } else { data = parseFloat(String(data).replace(',', '.')) } - let check = await checkRepechQuery.get(id, matiere_id[index], niveau) + + // 1. Check if already in notesrepech + const [check] = await pool.query( + 'SELECT * FROM notesrepech WHERE etudiant_id = ? AND matiere_id = ? AND etudiant_niveau = ?', + [id, matiere_id[index], niveau] + ) + if (data < 10) { - if (!check) { - insertRepechQuery.run(id, matiere_id[index], niveau, mention_id, 0, annee_scolaire) + // 2. If not already present, insert into notesrepech + if (check.length === 0) { + await pool.query( + `INSERT INTO notesrepech (etudiant_id, matiere_id, etudiant_niveau, mention_id, note, annee_scolaire) + VALUES (?, ?, ?, ?, ?, ?)`, + [id, matiere_id[index], niveau, mention_id, 0, annee_scolaire] + ) } - response = await query.run(data, id, niveau, matiere_id[index]) + + // 3. Update main note anyway + ;[response] = await pool.query( + 'UPDATE notes SET note = ? WHERE etudiant_id = ? AND etudiant_niveau = ? AND matiere_id = ?', + [data, id, niveau, matiere_id[index]] + ) } else { - clearFromRepech.run(id, niveau, matiere_id[index]) - response = await query.run(data, id, niveau, matiere_id[index]) + // 4. Remove from notesrepech if note >= 10 + await pool.query( + 'DELETE FROM notesrepech WHERE etudiant_id = ? AND etudiant_niveau = ? AND matiere_id = ?', + [id, niveau, matiere_id[index]] + ) + + // 5. Update main note + ;[response] = await pool.query( + 'UPDATE notes SET note = ? WHERE etudiant_id = ? AND etudiant_niveau = ? AND matiere_id = ?', + [data, id, niveau, matiere_id[index]] + ) } } return response } catch (error) { + console.error('Error updating note:', error) return error } } async function blockShowMoyene() { - const query = database.prepare( + const query = 'SELECT DISTINCT etudiant_niveau, annee_scolaire FROM notes ORDER BY annee_scolaire DESC' - ) - - const queryMention = database.prepare('SELECT * FROM mentions') + const queryMention = 'SELECT * FROM mentions' + const query2 = ` + SELECT + notes.*, + etudiants.id AS etudiantsId, + etudiants.mention_id AS mentionId, + etudiants.niveau, + matieres.* + FROM notes + INNER JOIN etudiants ON notes.etudiant_id = etudiants.id + INNER JOIN matieres ON notes.matiere_id = matieres.id + WHERE notes.etudiant_niveau = ? AND notes.annee_scolaire = ? + ` try { - let response = await query.all() - let mention = await queryMention.all() - let niveau = response.map((item) => item.etudiant_niveau) - let annee_scolaire = response.map((item) => item.annee_scolaire) - const query2 = database.prepare( - `SELECT notes.*, etudiants.id AS etudiantsId, etudiants.mention_id AS mentionId, etudiants.niveau, matieres.* FROM notes INNER JOIN etudiants ON (notes.etudiant_id = etudiants.id) INNER JOIN matieres ON (notes.matiere_id = matieres.id) WHERE notes.etudiant_niveau = ? AND notes.annee_scolaire = ?` - ) + const [response] = await pool.query(query) + const [mention] = await pool.query(queryMention) + + const niveau = response.map((item) => item.etudiant_niveau) + const annee_scolaire = response.map((item) => item.annee_scolaire) let allData = [] - for (let index = 0; index < niveau.length; index++) { - allData.push(await query2.all(niveau[index], annee_scolaire[index])) + for (let i = 0; i < niveau.length; i++) { + const [rows] = await pool.query(query2, [niveau[i], annee_scolaire[i]]) + allData.push(rows) } return { response, allData, mention } } catch (error) { + console.error(error) return error } } - /** * get all note with matiere for single student * @param {*} id @@ -272,36 +295,58 @@ async function blockShowMoyene() { * @returns promise */ async function getMatiereAndNote(id, niveau, annee_scolaire) { - const query = database.prepare( - 'SELECT * FROM notes INNER JOIN matieres ON (notes.matiere_id = matieres.id) WHERE notes.etudiant_id = ? AND notes.etudiant_niveau = ? AND notes.annee_scolaire = ?' - ) + const query = ` + SELECT * + FROM notes + INNER JOIN matieres ON notes.matiere_id = matieres.id + WHERE notes.etudiant_id = ? + AND notes.etudiant_niveau = ? + AND notes.annee_scolaire = ? + ` try { - let response = await query.all(id, niveau, annee_scolaire) - - return response + const [rows] = await pool.query(query, [id, niveau, annee_scolaire]) + return rows } catch (error) { return error } } async function getNotesWithRepechToDisplay(id, anneescolaire, niveau) { - const queryNoteNormal = database.prepare( - 'SELECT * FROM notes INNER JOIN matieres ON (notes.matiere_id = matieres.id) WHERE notes.etudiant_id = ? AND notes.annee_scolaire = ? AND notes.etudiant_niveau = ?' - ) - let noteNormal = await queryNoteNormal.all(id, anneescolaire, niveau) - - const queryNoteRepech = database.prepare( - 'SELECT * FROM notesrepech INNER JOIN matieres ON (notesrepech.matiere_id = matieres.id) WHERE notesrepech.etudiant_id = ? AND notesrepech.annee_scolaire = ? AND notesrepech.etudiant_niveau = ?' - ) - let noteRepech = await queryNoteRepech.all(id, anneescolaire, niveau) - - const semestreQuery = database.prepare( - 'SELECT * FROM semestres INNER JOIN matiere_semestre ON(semestres.id = matiere_semestre.semestre_id)' - ) - let semestre = await semestreQuery.all() - - return { noteNormal, noteRepech, semestre } + try { + // Query for normal notes + const [noteNormal] = await pool.query( + `SELECT * + FROM notes + INNER JOIN matieres ON notes.matiere_id = matieres.id + WHERE notes.etudiant_id = ? + AND notes.annee_scolaire = ? + AND notes.etudiant_niveau = ?`, + [id, anneescolaire, niveau] + ) + + // Query for repechage notes + const [noteRepech] = await pool.query( + `SELECT * + FROM notesrepech + INNER JOIN matieres ON notesrepech.matiere_id = matieres.id + WHERE notesrepech.etudiant_id = ? + AND notesrepech.annee_scolaire = ? + AND notesrepech.etudiant_niveau = ?`, + [id, anneescolaire, niveau] + ) + + // Query for semesters and matiere-semestre mapping + const [semestre] = await pool.query( + `SELECT * + FROM semestres + INNER JOIN matiere_semestre ON semestres.id = matiere_semestre.semestre_id` + ) + + return { noteNormal, noteRepech, semestre } + } catch (error) { + return error + } } module.exports = { diff --git a/database/Models/Status.js b/database/Models/Status.js index d08dc3e..5bd3b0e 100644 --- a/database/Models/Status.js +++ b/database/Models/Status.js @@ -1,16 +1,16 @@ -const { database } = require('../database.backup') +const { pool } = require('../database') /** * function to return all status * @returns promise */ async function getStatus() { - const query = database.prepare('SELECT * FROM status') + const sql = 'SELECT * FROM status' try { - let response = await query.all() + let [rows] = await pool.query(sql) - return response + return rows } catch (error) { return error } diff --git a/database/database.js b/database/database.js index d04a8ae..1634e1b 100644 --- a/database/database.js +++ b/database/database.js @@ -72,11 +72,11 @@ async function createTables() { num_inscription TEXT UNIQUE NOT NULL, sexe VARCHAR(20) DEFAULT NULL, cin VARCHAR(250) DEFAULT NULL, - date_delivrance DATE DEFAULT NULL, - nationalite DATE DEFAULT NULL, - annee_bacc DATE DEFAULT NULL, + date_delivrance TEXT DEFAULT NULL, + nationalite VARCHAR(250) DEFAULT NULL, + annee_bacc TEXT DEFAULT NULL, serie VARCHAR(20) DEFAULT NULL, - boursier TINYINT(1) DEFAULT 0, + boursier VARCHAR(20) DEFAULT NULL, domaine VARCHAR(250) DEFAULT NULL, contact VARCHAR(20) DEFAULT NULL, parcours VARCHAR(250) DEFAULT NULL, diff --git a/database/function/Helper.js b/database/function/Helper.js index 57a1460..dc7ed7f 100644 --- a/database/function/Helper.js +++ b/database/function/Helper.js @@ -1,9 +1,10 @@ -const { database } = require('../database') +const { pool } = require('../database') -const getStatusMention = (menstionText) => { - const query = database.prepare('SELECT * FROM status') +const getStatusMention = async (menstionText) => { + const query = 'SELECT * FROM status' - let response = query.all() + let [rows] = await pool.query(query) + let response = rows let statutCode for (let index = 0; index < response.length; index++) { let nom = response[index].nom diff --git a/database/function/System.js b/database/function/System.js index 99b03d4..6d371b2 100644 --- a/database/function/System.js +++ b/database/function/System.js @@ -43,219 +43,187 @@ async function updateCurrentYears() { } } -// async function updateStudents() { -// const getInfinishedYears = database -// .prepare('SELECT * FROM traitmentsystem WHERE is_finished = 0 ORDER BY id ASC') -// .get() - -// const allEtudiants = database -// .prepare('SELECT * FROM etudiants WHERE annee_scolaire = ?') -// .all(getInfinishedYears.code) - -// function checkNull(params) { -// if (params == null || params == undefined) { -// return null -// } -// return params -// } - -// function compareSessionNotes(session1, session2) { -// let notes -// if (session2) { -// if (session1 < session2.note) { -// notes = session2.note -// } else { -// notes = session1 -// } -// } else { -// notes = session1 -// } -// return notes -// } - -// database.transaction(() => { -// // get all note of student -// const queryNotes = database.prepare( -// `SELECT DISTINCT etudiant_id FROM notes WHERE etudiant_niveau = ? AND annee_scolaire = ?` -// ) -// let allEtudiantWithNotes = [] -// let etudiantWithNotes = [] -// let dataToMap = [] -// let allEtudiantWithNotesRepech = [] -// let etudiantWithNotesRepech = [] - -// for (const etudiant of allEtudiants) { -// const results = queryNotes.all(etudiant.niveau, etudiant.annee_scolaire) -// etudiantWithNotes.push(...results) // Avoid nested arrays -// } - -// const uniqueId = etudiantWithNotes.filter( -// (item, index, self) => index === self.findIndex((t) => t.etudiant_id === item.etudiant_id) -// ) - -// const query2 = database.prepare( -// 'SELECT notes.*, etudiants.*, matieres.id, matieres.nom AS nomMat, matieres.credit FROM notes LEFT JOIN etudiants ON (notes.etudiant_id = etudiants.id) LEFT JOIN matieres ON (notes.matiere_id = matieres.id) WHERE notes.etudiant_id = ?' -// ) - -// for (let j = 0; j < uniqueId.length; j++) { -// allEtudiantWithNotes.push(query2.all(uniqueId[j].etudiant_id)) -// } - -// const query = database.prepare( -// `SELECT DISTINCT etudiant_id FROM notesrepech WHERE etudiant_niveau = ? AND annee_scolaire = ?` -// ) - -// for (const etudiant of allEtudiants) { -// const results = query.all(etudiant.niveau, etudiant.annee_scolaire) -// etudiantWithNotesRepech.push(...results) // Avoid nested arrays -// } - -// const uniqueIdRepech = etudiantWithNotes.filter( -// (item, index, self) => index === self.findIndex((t) => t.etudiant_id === item.etudiant_id) -// ) - -// const query2Repech = database.prepare( -// 'SELECT notesrepech.*, etudiants.*, matieres.id, matieres.nom AS nomMat, matieres.credit FROM notesrepech INNER JOIN etudiants ON (notesrepech.etudiant_id = etudiants.id) INNER JOIN matieres ON (notesrepech.matiere_id = matieres.id) WHERE notesrepech.etudiant_id = ?' -// ) - -// for (let j = 0; j < uniqueIdRepech.length; j++) { -// allEtudiantWithNotesRepech.push(query2Repech.all(uniqueIdRepech[j].etudiant_id)) -// } - -// for (let index = 0; index < allEtudiantWithNotes.length; index++) { -// let total = 0 -// let note = 0 -// let totalCredit = 0 - -// // Create a new object for each student -// let modelJson = { -// id: '', -// nom: '', -// prenom: '', -// photos: '', -// moyenne: '', -// mention: '', -// niveau: '', -// annee_scolaire: '' -// } - -// for (let j = 0; j < allEtudiantWithNotes[index].length; j++) { -// modelJson.id = allEtudiantWithNotes[index][j].etudiant_id -// modelJson.nom = allEtudiantWithNotes[index][j].nom -// modelJson.prenom = allEtudiantWithNotes[index][j].prenom -// modelJson.photos = allEtudiantWithNotes[index][j].photos -// modelJson.mention = allEtudiantWithNotes[index][j].mention_id -// modelJson.niveau = allEtudiantWithNotes[index][j].niveau -// modelJson.annee_scolaire = allEtudiantWithNotes[index][j].annee_scolaire - -// // console.log(checkNull(session[index][j])); -// if (allEtudiantWithNotesRepech[index]) { -// note += -// compareSessionNotes( -// allEtudiantWithNotes[index][j].note, -// checkNull(allEtudiantWithNotesRepech[index][j]) -// ) * allEtudiantWithNotes[index][j].credit -// } else { -// note += allEtudiantWithNotes[index][j].note * allEtudiantWithNotes[index][j].credit -// } -// totalCredit += allEtudiantWithNotes[index][j].credit -// } - -// total = note / totalCredit -// modelJson.moyenne = total.toFixed(2) - -// // Add the new object to the array -// dataToMap.push(modelJson) -// } - -// // update all etudiant -// let updated = false -// if (dataToMap.length != 0) { -// let noteSystem = database.prepare('SELECT * FROM notesystems').get() -// for (let index = 0; index < dataToMap.length; index++) { -// if (dataToMap[index].moyenne >= noteSystem.admis) { -// let updateQuery = database.prepare( -// 'UPDATE etudiants SET niveau = ?, annee_scolaire = ?, status = ? WHERE id = ?' -// ) -// updateQuery.run( -// nextLevel(dataToMap[index].niveau), -// updateSchoolYear(dataToMap[index].annee_scolaire), -// 2, -// dataToMap[index].id -// ) -// updated = true -// } else if ( -// dataToMap[index].moyenne < noteSystem.admis && -// dataToMap[index].moyenne >= noteSystem.redouble -// ) { -// let updateQuery = database.prepare( -// 'UPDATE etudiants SET niveau = ?, annee_scolaire = ? status = ? WHERE id = ?' -// ) -// updateQuery.run( -// dataToMap[index].niveau, -// updateSchoolYear(dataToMap[index].annee_scolaire), -// 3, -// dataToMap[index].id -// ) -// updated = true -// } else { -// let updateQuery = database.prepare( -// 'UPDATE etudiants SET niveau = ?, annee_scolaire = ? status = ? WHERE id = ?' -// ) -// updateQuery.run( -// dataToMap[index].niveau, -// dataToMap[index].annee_scolaire, -// 4, -// dataToMap[index].id -// ) -// updated = true -// } -// } -// } - -// if (updated) { -// const updateInfinishedYears = database.prepare( -// 'UPDATE traitmentsystem SET is_finished = 1 WHERE id = ?' -// ) - -// updateInfinishedYears.run(getInfinishedYears.id) -// } -// })() -// } - -// function nextLevel(niveau) { -// if (niveau == 'L1') { -// return 'L2' -// } else if (niveau == 'L2') { -// return 'L3' -// } else if (niveau == 'L3') { -// return 'M1' -// } else if (niveau == 'M1') { -// return 'M2' -// } else if (niveau == 'M2') { -// return 'D1' -// } else if (niveau == 'D1') { -// return 'D2' -// } else if (niveau == 'D2') { -// return 'D3' -// } else if (niveau == 'D3') { -// return 'PHD' -// } -// } - -// function updateSchoolYear(year) { -// // Split the year into two parts -// const [startYear, endYear] = year.split('-').map(Number) - -// // Increment both the start and end year by 1 -// const newStartYear = startYear + 1 -// const newEndYear = endYear + 1 - -// // Join the new years with a hyphen -// const newYear = `${newStartYear}-${newEndYear}` - -// return newYear -// } +// Helper functions (unchanged) +function checkNull(params) { + if (params === null || params === undefined) return null + return params +} +function compareSessionNotes(session1, session2) { + if (session2) { + return session1 < session2.note ? session2.note : session1 + } + return session1 +} +function nextLevel(niveau) { + const levels = ['L1', 'L2', 'L3', 'M1', 'M2', 'D1', 'D2', 'D3', 'PHD'] + const idx = levels.indexOf(niveau) + return idx === -1 || idx === levels.length - 1 ? niveau : levels[idx + 1] +} +function updateSchoolYear(year) { + const [startYear, endYear] = year.split('-').map(Number) + return `${startYear + 1}-${endYear + 1}` +} + +async function updateStudents() { + const connection = await pool.getConnection() + try { + await connection.beginTransaction() + + // Get unfinished years (only one record assumed) + const [unfinishedYearsRows] = await connection.query( + 'SELECT * FROM traitmentsystem WHERE is_finished = 0 ORDER BY id ASC LIMIT 1' + ) + if (unfinishedYearsRows.length === 0) { + await connection.release() + return { message: 'No unfinished years found.' } + } + const unfinishedYear = unfinishedYearsRows[0] + + // Get all students of that unfinished year + const [allEtudiants] = await connection.query( + 'SELECT * FROM etudiants WHERE annee_scolaire = ?', + [unfinishedYear.code] + ) + + // Get distinct student IDs with notes + let etudiantWithNotes = [] + for (const etudiant of allEtudiants) { + const [results] = await connection.query( + 'SELECT DISTINCT etudiant_id FROM notes WHERE etudiant_niveau = ? AND annee_scolaire = ?', + [etudiant.niveau, etudiant.annee_scolaire] + ) + etudiantWithNotes.push(...results) + } + // Unique IDs + const uniqueId = [ + ...new Map(etudiantWithNotes.map((item) => [item.etudiant_id, item])).values() + ] + + // Get notes details per student + let allEtudiantWithNotes = [] + for (const student of uniqueId) { + const [rows] = await connection.query( + `SELECT notes.*, etudiants.*, matieres.id, matieres.nom AS nomMat, matieres.credit + FROM notes + LEFT JOIN etudiants ON notes.etudiant_id = etudiants.id + LEFT JOIN matieres ON notes.matiere_id = matieres.id + WHERE notes.etudiant_id = ?`, + [student.etudiant_id] + ) + allEtudiantWithNotes.push(rows) + } + + // Get distinct student IDs with notesrepech + let etudiantWithNotesRepech = [] + for (const etudiant of allEtudiants) { + const [results] = await connection.query( + 'SELECT DISTINCT etudiant_id FROM notesrepech WHERE etudiant_niveau = ? AND annee_scolaire = ?', + [etudiant.niveau, etudiant.annee_scolaire] + ) + etudiantWithNotesRepech.push(...results) + } + // Unique IDs for repech + const uniqueIdRepech = [ + ...new Map(etudiantWithNotesRepech.map((item) => [item.etudiant_id, item])).values() + ] + + // Get notesrepech details per student + let allEtudiantWithNotesRepech = [] + for (const student of uniqueIdRepech) { + const [rows] = await connection.query( + `SELECT notesrepech.*, etudiants.*, matieres.id, matieres.nom AS nomMat, matieres.credit + FROM notesrepech + INNER JOIN etudiants ON notesrepech.etudiant_id = etudiants.id + INNER JOIN matieres ON notesrepech.matiere_id = matieres.id + WHERE notesrepech.etudiant_id = ?`, + [student.etudiant_id] + ) + allEtudiantWithNotesRepech.push(rows) + } + + // Compute averages and prepare data + let dataToMap = [] + for (let i = 0; i < allEtudiantWithNotes.length; i++) { + const notesNormal = allEtudiantWithNotes[i] + const notesRepech = allEtudiantWithNotesRepech[i] || [] + + let total = 0 + let totalCredit = 0 + let modelJson = { + id: '', + nom: '', + prenom: '', + photos: '', + moyenne: '', + mention: '', + niveau: '', + annee_scolaire: '' + } + + for (let j = 0; j < notesNormal.length; j++) { + const normalNote = notesNormal[j] + modelJson.id = normalNote.etudiant_id + modelJson.nom = normalNote.nom + modelJson.prenom = normalNote.prenom + modelJson.photos = normalNote.photos + modelJson.mention = normalNote.mention_id + modelJson.niveau = normalNote.niveau + modelJson.annee_scolaire = normalNote.annee_scolaire + + // Find repech note for same matiere if exists + const repechNoteObj = notesRepech.find((r) => r.matiere_id === normalNote.matiere_id) + const noteToUse = compareSessionNotes(normalNote.note, checkNull(repechNoteObj)) + + total += (noteToUse ?? 0) * normalNote.credit + totalCredit += normalNote.credit + } + + modelJson.moyenne = (totalCredit > 0 ? total / totalCredit : 0).toFixed(2) + dataToMap.push(modelJson) + } + + // Get note system thresholds + const [noteSystemRows] = await connection.query('SELECT * FROM notesystems LIMIT 1') + const noteSystem = noteSystemRows[0] + + // Update etudiants based on moyenne + for (const student of dataToMap) { + let status, newNiveau, newAnnee + newAnnee = updateSchoolYear(student.annee_scolaire) + + if (student.moyenne >= noteSystem.admis) { + newNiveau = nextLevel(student.niveau) + status = 2 // Passed + } else if (student.moyenne >= noteSystem.redouble) { + newNiveau = student.niveau + status = 3 // Repeat + } else { + newNiveau = student.niveau + status = 4 // Fail + } + + await connection.query( + 'UPDATE etudiants SET niveau = ?, annee_scolaire = ?, status = ? WHERE id = ?', + [newNiveau, newAnnee, status, student.id] + ) + } + + // Mark unfinished year as finished + await connection.query('UPDATE traitmentsystem SET is_finished = 1 WHERE id = ?', [ + unfinishedYear.id + ]) + + await connection.commit() + connection.release() + + return { success: true, message: 'Students updated successfully' } + } catch (error) { + await connection.rollback() + connection.release() + console.error(error) + throw error + } +} async function matiereSysteme(etudiant_niveau) { let systeme @@ -300,33 +268,43 @@ async function matiereSystemReverse(semestre) { } } -// async function getNessesarytable() { -// try { -// const query = await database.prepare('SELECT * FROM nessesaryTable').get() - -// return query -// } catch (error) { -// return error -// } -// } - -// async function updateNessesaryTable(id, multiplicateur) { -// const query = database.prepare('UPDATE nessesaryTable SET uniter_heure = ? WHERE id = ?') - -// try { -// let update = query.run(multiplicateur, id) +async function getNessesarytable() { + try { + const sql = 'SELECT * FROM nessesaryTable' + const [rows] = await pool.query(sql) + return rows + } catch (error) { + return error + } +} -// return update -// } catch (error) { -// return error -// } -// } +async function updateNessesaryTable(id, multiplicateur) { + const sql = 'UPDATE nessesaryTable SET uniter_heure = ? WHERE id = ?' + + try { + const [result] = await pool.query(sql, [multiplicateur, id]) + + if (result.affectedRows === 0) { + return { + success: false, + message: 'Année universitaire non trouvé.' + } + } + + return { + success: true, + message: 'Année universitaire supprimé avec succès.' + } + } catch (error) { + return error + } +} module.exports = { matiereSysteme, updateCurrentYears, - // updateStudents, - // getNessesarytable, - // updateNessesaryTable, + updateStudents, + getNessesarytable, + updateNessesaryTable, matiereSystemReverse } diff --git a/database/import/Etudiants.js b/database/import/Etudiants.js index e19317c..7dfbca1 100644 --- a/database/import/Etudiants.js +++ b/database/import/Etudiants.js @@ -3,12 +3,11 @@ const path = require('path') const XLSX = require('xlsx') const { getCompressedDefaultImage } = require('../function/GetImageDefaault') const { parse } = require('csv-parse/sync') -const { insertEtudiant } = require('../Models/Etudiants') -const { database } = require('../database') -const { getMentions } = require('../Models/Mentions') +const { pool } = require('../database') const dayjs = require('dayjs') -const { getStatusMention } = require('../function/Helper') +// const { getStatusMention } = require('../function/Helper') const customParseFormat = require('dayjs/plugin/customParseFormat') +// const { log } = require('console') // const customParseFormatt = require('dayjs/plu') dayjs.extend(customParseFormat) @@ -50,12 +49,50 @@ function convertToISODate(input) { return jsDate } -async function MentionList() { - let response = await getMentions() - return response -} +async function insertMultipleEtudiants(etudiants) { + const sql = ` + INSERT INTO etudiants ( + nom, prenom, photos, date_de_naissances, niveau, annee_scolaire, status, + mention_id, num_inscription, sexe, cin, date_delivrance, nationalite, + annee_bacc, serie, boursier, domaine, contact, parcours + ) + VALUES ? + ` + + // Prepare values as array of arrays + const values = etudiants.map((row) => [ + row.nom, + row.prenom, + getCompressedDefaultImage(), // photos (you can adjust this if needed) + convertToISODate(row.date_naissance), + row.niveau, + row.annee_scolaire, + row.code_redoublement, + row.mention, + row.num_inscription, + row.sexe, + row.cin, + convertToISODate(row.date_de_delivrance), + row.nationaliter, + row.annee_baccalaureat, + row.serie, + row.boursier, + row.domaine, + row.contact, + null // parcours + ]) -let ListMention + try { + const [result] = await pool.query(sql, [values]) + return { + success: true, + affectedRows: result.affectedRows, + insertId: result.insertId + } + } catch (error) { + return { success: false, error: error.message } + } +} /** * Function to import data from XLSX or CSV file into SQLite database @@ -84,16 +121,15 @@ async function importFileToDatabase(filePath) { } // ✅ Count number of data rows - const numberOfLines = records.length; - console.log(`Number of data rows: ${numberOfLines}`); + const numberOfLines = records.length + console.log(`Number of data rows: ${numberOfLines}`) try { let error = true let message = '' // Vérifier les données en une seule boucle - let ar = []; - let oldNum = ''; + let oldNum = '' for (const row of records) { if ( !row.nom || @@ -160,76 +196,62 @@ async function importFileToDatabase(filePath) { } } - async function fetchMentions() { - try { - // Fetch the mentions - ListMention = await MentionList() - - // Assuming 'ListMention' is an array of objects like the ones you mentioned - // Si aucune erreur, insérer les données en batch - if (error !== false) { - // Utiliser transaction pour éviter une latence si l'insertion dépasse 100 - database.transaction(() => { - for (const row of records) { - // Convert row.mention to uppercase and compare with ListMention.nom and ListMention.uniter (also converted to uppercase) - const matchedMention = ListMention.find( - (mention) => - mention.nom.toUpperCase() === row.mention.toUpperCase() || - mention.uniter.toUpperCase() === row.mention.toUpperCase() - ) - - // If a match is found, update row.mention with ListMention.id - if (matchedMention) { - row.mention = matchedMention.id - } - row.num_inscription = row.num_inscription.toString() - - ar.push(row) - console.log(ar.length, 'create'); - try { - let compare = row.num_inscription; - if (compare == oldNum) { - row.num_inscription = Number(row.num_inscription + 1); - } - console.log( - insertEtudiant( - row.nom, - row.prenom, - getCompressedDefaultImage(), - convertToISODate(row.date_naissance), - row.niveau, - row.annee_scolaire, - getStatusMention(row.code_redoublement), - row.num_inscription, - row.mention, - row.sexe, - row.nationaliter, - row.cin, - row.date_de_delivrance, - row.annee_baccalaureat, - row.serie, - row.boursier, - row.domaine, - row.contact, - null - ) - ); - oldNum = compare - - } catch (error) { - console.log(error); - - } - } - })() + const query = 'SELECT * FROM mentions' + const [rows] = await pool.query(query) + const MentionList = rows + console.log(MentionList) + + if (error !== false) { + let newReccord = [] + // Utiliser transaction pour éviter une latence si l'insertion dépasse 100 + for (const row of records) { + // Convert row.mention to uppercase and compare with ListMention.nom and ListMention.uniter (also converted to uppercase) + const matchedMention = MentionList.find( + (mention) => + mention.nom.toUpperCase() === row.mention.toUpperCase() || + mention.uniter.toUpperCase() === row.mention.toUpperCase() + ) + + // If a match is found, update row.mention with ListMention.id + if (matchedMention) { + row.mention = matchedMention.id + } + + const query = 'SELECT * FROM status' + + let [rows] = await pool.query(query) + let response = rows + let statutCode + for (let index = 0; index < response.length; index++) { + let nom = response[index].nom + let nomLower = nom.toLowerCase() // Correct method + let find1 = row.code_redoublement.slice(0, 1) + let find2 = row.code_redoublement.slice(0, 3) + + if (nomLower.slice(0, 1) == find1.toLowerCase()) { + statutCode = response[index].id + } else if (nomLower.slice(0, 3) == find2.toLowerCase()) { + statutCode = response[index].id + } + } + + row.code_redoublement = statutCode + row.num_inscription = row.num_inscription.toString() + try { + let compare = row.num_inscription + if (compare == oldNum) { + row.num_inscription = String(row.num_inscription) + } + console.log(row.code_redoublement) + newReccord.push(row) + oldNum = compare + } catch (error) { + console.log(error) } - } catch (error) { - console.error('Error:', error) // Handle any errors } + console.log(insertMultipleEtudiants(newReccord)) } - fetchMentions() - return { error, message } } catch (error) { console.error('Error inserting record:', error) diff --git a/database/import/Matieres.js b/database/import/Matieres.js index 994dec3..2cdecb9 100644 --- a/database/import/Matieres.js +++ b/database/import/Matieres.js @@ -2,8 +2,39 @@ const fs = require('fs') const path = require('path') const XLSX = require('xlsx') const { parse } = require('csv-parse/sync') -const { createMatiere } = require('../Models/Matieres') -const { database } = require('../database.backup') +const { pool } = require('../database') + +async function createMatieresBatch(records) { + try { + // Step 1: Get uniter_heure once + const uniterHeureSql = 'SELECT uniter_heure FROM nessesaryTable LIMIT 1' + const [rows] = await pool.query(uniterHeureSql) + const uniterHeureValue = rows[0]?.uniter_heure ?? 1 // fallback 1 if not found + + // Step 2: Prepare bulk insert values + // Each row: [nom, uniter, credit, heure, ue] + const values = records.map(({ nom, credit, uniter, ue }) => { + const heure = credit * uniterHeureValue + return [nom, uniter, credit, heure, ue] + }) + + // Step 3: Bulk insert query + const insertSql = ` + INSERT INTO matieres (nom, unite_enseignement, credit, heure, ue) + VALUES ? + ` + + const [result] = await pool.query(insertSql, [values]) + + return { + success: true, + insertedCount: result.affectedRows, + insertId: result.insertId + } + } catch (error) { + return { success: false, error: 'Erreur veuillez réessayer: ' + error.message } + } +} /** * Function to import data from the first column of an XLSX or CSV file into SQLite database @@ -51,11 +82,7 @@ async function importFileToDatabaseMatiere(filePath) { } if (error !== false) { - database.transaction(() => { - for (const row of records) { - createMatiere(row.nom, row.credit, row.uniter, row.ue) - } - })() + createMatieresBatch(records) } return { error, message } diff --git a/src/renderer/src/components/AddNotes.jsx b/src/renderer/src/components/AddNotes.jsx index 9424dd0..f000a56 100644 --- a/src/renderer/src/components/AddNotes.jsx +++ b/src/renderer/src/components/AddNotes.jsx @@ -93,7 +93,7 @@ const AddNotes = () => { annee_scolaire }) console.log(response) - if (response.changes) { + if (response.success) { setOpen(true) setStatut(200) setDisabled(true) diff --git a/src/renderer/src/components/AddStudent.jsx b/src/renderer/src/components/AddStudent.jsx index c6b30f0..2ff0136 100644 --- a/src/renderer/src/components/AddStudent.jsx +++ b/src/renderer/src/components/AddStudent.jsx @@ -185,12 +185,12 @@ const AddStudent = () => { const response = await window.etudiants.insertEtudiant(formData) console.log(response) - if (response.code) { + if (!response.success) { setCode(422) setOpen(true) } - if (response.changes) { + if (response.success) { imageVisual.current.style.display = 'none' imageVisual.current.src = '' setCode(200) diff --git a/src/renderer/src/components/AjoutTranche.jsx b/src/renderer/src/components/AjoutTranche.jsx index 91519b2..5f66207 100644 --- a/src/renderer/src/components/AjoutTranche.jsx +++ b/src/renderer/src/components/AjoutTranche.jsx @@ -29,7 +29,7 @@ const AjoutTranche = ({ open, onClose, onSubmitSuccess, id }) => { e.preventDefault() let response = await window.etudiants.createTranche(formData) - if (response.changes) { + if (response.success) { onClose() onSubmitSuccess(true) setFormData({ diff --git a/src/renderer/src/components/DeleteTranche.jsx b/src/renderer/src/components/DeleteTranche.jsx index 62cc80c..f6e949b 100644 --- a/src/renderer/src/components/DeleteTranche.jsx +++ b/src/renderer/src/components/DeleteTranche.jsx @@ -22,7 +22,7 @@ const DeleteTranche = ({ open, onClose, id, onSubmitSuccess }) => { if (idDelete !== null) { const id = idDelete let response = await window.etudiants.deleteTranche({ id }) - if (response.changes) { + if (response.success) { onSubmitSuccess(true) onClose() } diff --git a/src/renderer/src/components/ModalFormMultiplicateur.jsx b/src/renderer/src/components/ModalFormMultiplicateur.jsx index 40b26ba..d3bdd92 100644 --- a/src/renderer/src/components/ModalFormMultiplicateur.jsx +++ b/src/renderer/src/components/ModalFormMultiplicateur.jsx @@ -42,7 +42,7 @@ const ModalFormMultiplicateur = ({ open, onClose }) => { console.log(formData) let response = await window.matieres.updateNessesary(formData) - if (response.changes) { + if (response.success) { onClose() // Close the modal after submission } } diff --git a/src/renderer/src/components/Noteclasse.jsx b/src/renderer/src/components/Noteclasse.jsx index f250ec7..3a6d73f 100644 --- a/src/renderer/src/components/Noteclasse.jsx +++ b/src/renderer/src/components/Noteclasse.jsx @@ -210,8 +210,10 @@ const Noteclasse = () => { const [selectedId, setSelectedId] = useState(null) // Store id dynamically const sendData = (id) => { - setOpenCart(true) setSelectedId(id) + // if (selectedId !== null) { + setOpenCart(true) + // } } useEffect(() => { diff --git a/src/renderer/src/components/ReleverNotes.jsx b/src/renderer/src/components/ReleverNotes.jsx index c41c357..a09d4b1 100644 --- a/src/renderer/src/components/ReleverNotes.jsx +++ b/src/renderer/src/components/ReleverNotes.jsx @@ -55,6 +55,11 @@ const ReleverNotes = ({ id, anneescolaire, niveau, refs }) => { } useEffect(() => { + if (!id) { + // id doesn't exist, you might want to retry, or do nothing + // For example, refetch later or show an error + return + } window.etudiants.getSingle({ id }).then((response) => { setEtudiant(response) }) diff --git a/src/renderer/src/components/SingleEtudiant.jsx b/src/renderer/src/components/SingleEtudiant.jsx index f08e0b2..6536e00 100644 --- a/src/renderer/src/components/SingleEtudiant.jsx +++ b/src/renderer/src/components/SingleEtudiant.jsx @@ -25,6 +25,7 @@ import { FaRegTimesCircle } from 'react-icons/fa' import MenuItem from '@mui/material/MenuItem' import { MdGrade, MdRule } from 'react-icons/md' import { FaLeftLong, FaRightLong } from 'react-icons/fa6' +import dayjs from 'dayjs' const SingleEtudiant = () => { const { id } = useParams() @@ -85,7 +86,6 @@ const SingleEtudiant = () => { }) }, [id]) - console.log(scolaire) function comparestatut(statutID) { let statusText @@ -115,7 +115,7 @@ const SingleEtudiant = () => { nom: etudiant.nom || '', prenom: etudiant.prenom || '', photos: etudiant.photos || null, - date_de_naissances: etudiant.date_de_naissances || '', + date_de_naissances: dayjs(etudiant.date_de_naissances).format('YYYY-MM-DD') || '', niveau: etudiant.niveau || '', annee_scolaire: etudiant.annee_scolaire || '', status: etudiant.status || '', @@ -125,8 +125,8 @@ const SingleEtudiant = () => { sexe: etudiant.sexe, nationalite: etudiant.nationalite, cin: etudiant.cin, - date_delivrance: etudiant.date_delivrance, - annee_bacc: etudiant.annee_bacc, + date_delivrance: dayjs(etudiant.date_delivrance).format('YYYY-MM-DD'), + annee_bacc: dayjs(etudiant.annee_bacc).format('YYYY-MM-DD'), serie: etudiant.serie, boursier: etudiant.boursier, domaine: etudiant.domaine, @@ -192,7 +192,7 @@ const SingleEtudiant = () => { // If validation passes, proceed with the submission try { let response = await window.etudiants.updateEtudiants(formData) - if (response.changes) { + if (response.success) { setEtudiant(formData) } @@ -267,7 +267,9 @@ const SingleEtudiant = () => { let imgAvatar = avatar.querySelector('img') window.etudiants.updateEtudiantsPDP({ pdp, id }).then((responses) => { - if (responses.changes) { + console.log(responses); + + if (responses.success) { if (imgAvatar === null) { let image = document.createElement('img') image.setAttribute('src', pdp) @@ -507,7 +509,7 @@ const SingleEtudiant = () => { name="date_de_naissances" color="warning" type="date" - defaultValue={etudiant.date_de_naissances} // Controlled component value + defaultValue={dayjs(etudiant.date_de_naissances).format('YYYY-MM-DD')} // Controlled component value onChange={handleChange} InputLabelProps={{ shrink: true @@ -721,7 +723,7 @@ const SingleEtudiant = () => { name="date_delivrance" color="warning" type="date" - defaultValue={etudiant.date_delivrance} // Controlled component value + defaultValue={dayjs(etudiant.date_delivrance).format('YYYY-MM-DD')} // Controlled component value onChange={handleChange} InputProps={{ startAdornment: ( @@ -899,8 +901,8 @@ const SingleEtudiant = () => { } }} > - Oui - Non + Oui + Non @@ -1101,7 +1103,7 @@ const SingleEtudiant = () => { variant="h6" style={{ display: 'flex', justifyContent: 'space-between' }} > - Date de Naissance: {etudiant.date_de_naissances} + Date de Naissance: {dayjs(etudiant.date_de_naissances).format('YYYY-MM-DD')} diff --git a/src/renderer/src/components/Student.jsx b/src/renderer/src/components/Student.jsx index 28e8a6c..ad42d3d 100644 --- a/src/renderer/src/components/Student.jsx +++ b/src/renderer/src/components/Student.jsx @@ -218,7 +218,7 @@ const Student = () => { display: 'flex', flexDirection: 'column', gap: '10px', - marginTop:"15px" + marginTop: "15px" }} place="left-end" clickable @@ -309,7 +309,19 @@ const Student = () => { } } - const paginationModel = { page: 0, pageSize: 5 } + // const paginationModel = { page: 0, pageSize: 20 } + const [pageSize, setPageSize] = useState(20) + const [pageSizeOptions, setPageSizeOptions] = useState([20, 40, 60]) + + const handlePageSizeChange = (newPageSize) => { + setPageSize(newPageSize) + + // If the user picked the largest value, add next +20 + const maxOption = Math.max(...pageSizeOptions) + if (newPageSize === maxOption) { + setPageSizeOptions((prev) => [...prev, maxOption + 20]) + } + } // Ensure that the array is flat (not wrapped in another array) const dataRow = etudiants.map((etudiant) => ({ @@ -325,7 +337,7 @@ const Student = () => { photos: etudiant.photos, sexe: etudiant.sexe, cin: etudiant.cin, - date_deli: etudiant.date_delivrance, + date_deli: dayjs(etudiant.date_delivrance).format('DD-MM-YYYY'), nation: etudiant.nationalite, annee_bacc: etudiant.annee_bacc, serie: etudiant.serie, @@ -529,8 +541,11 @@ const Student = () => { handlePageSizeChange(model.pageSize)} sx={{ border: 0, width: 'auto', // Ensures the DataGrid takes full width diff --git a/src/renderer/src/components/SystemeNote.jsx b/src/renderer/src/components/SystemeNote.jsx index 12904de..e3029f6 100644 --- a/src/renderer/src/components/SystemeNote.jsx +++ b/src/renderer/src/components/SystemeNote.jsx @@ -53,13 +53,16 @@ const SystemeNote = () => { } }, [noteSy]) + console.log(noteSy) + const formSubmit = async (e) => { e.preventDefault() let valid = validateNOteSystem(admisRef.current, redoubleRef.current, renvoyerRef.current) if (valid) { let response = await window.notesysteme.updateNoteSysteme(formData) - if (response.changes) { + console.log(response) + if (response.success) { setStatus(200) setOpen(true) }