import terminer
This commit is contained in:
parent
0cf0a72814
commit
124d0eeead
@ -261,7 +261,7 @@ async function createTranche(etudiant_id, tranchename, montant) {
|
|||||||
const sql = 'INSERT INTO trancheecolage (etudiant_id, tranchename, montant) VALUES (?, ?, ?)'
|
const sql = 'INSERT INTO trancheecolage (etudiant_id, tranchename, montant) VALUES (?, ?, ?)'
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let [result] = pool.query(sql, [etudiant_id, tranchename, montant])
|
let [result] = await pool.query(sql, [etudiant_id, tranchename, montant])
|
||||||
|
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
@ -273,46 +273,66 @@ async function createTranche(etudiant_id, tranchename, montant) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function getTranche(id) {
|
async function getTranche(id) {
|
||||||
const query = database.prepare('SELECT * FROM trancheecolage WHERE etudiant_id = ?')
|
const sql = 'SELECT * FROM trancheecolage WHERE etudiant_id = ?'
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response = query.all(id)
|
let [rows] = await pool.query(sql, [id])
|
||||||
|
|
||||||
return response
|
return rows
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateTranche(id, tranchename, montant) {
|
async function updateTranche(id, tranchename, montant) {
|
||||||
const query = database.prepare(
|
const sql = 'UPDATE trancheecolage SET tranchename = ?, montant = ? WHERE id = ?'
|
||||||
'UPDATE trancheecolage SET tranchename = ?, montant = ? WHERE id = ?'
|
|
||||||
)
|
|
||||||
|
|
||||||
try {
|
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) {
|
} catch (error) {
|
||||||
return error
|
return error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteTranche(id) {
|
async function deleteTranche(id) {
|
||||||
const query = database.prepare('DELETE FROM trancheecolage WHERE id = ?')
|
const sql = 'DELETE FROM trancheecolage WHERE id = ?'
|
||||||
|
|
||||||
try {
|
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) {
|
} catch (error) {
|
||||||
return error
|
return error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getSingleTranche(id) {
|
async function getSingleTranche(id) {
|
||||||
|
const sql = 'SELECT * FROM trancheecolage WHERE id = ?'
|
||||||
try {
|
try {
|
||||||
return await database.prepare('SELECT * FROM trancheecolage WHERE id = ?').get(id)
|
const [rows] = await pool.query(sql, [id])
|
||||||
|
return rows[0]
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return error
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,4 @@
|
|||||||
const { database } = require('../database.backup')
|
const { pool } = require('../database')
|
||||||
const { getNiveau } = require('./Niveau')
|
|
||||||
const { matiereSysteme } = require('../function/System')
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to insert notes into the database
|
* Function to insert notes into the database
|
||||||
@ -16,28 +14,32 @@ async function insertNoteRepech(
|
|||||||
formData,
|
formData,
|
||||||
annee_scolaire
|
annee_scolaire
|
||||||
) {
|
) {
|
||||||
// Extract keys and values dynamically
|
const matiere_ids = Object.keys(formData)
|
||||||
const matiere_id = Object.keys(formData)
|
|
||||||
const values = Object.values(formData)
|
const values = Object.values(formData)
|
||||||
|
|
||||||
const query = database.prepare(
|
const query = `
|
||||||
`INSERT INTO notesrepech (etudiant_id, matiere_id, etudiant_niveau, mention_id, note, annee_scolaire) VALUES (?, ?, ?, ?, ?, ?)`
|
INSERT INTO notesrepech
|
||||||
)
|
(etudiant_id, matiere_id, etudiant_niveau, mention_id, note, annee_scolaire)
|
||||||
console.log(annee_scolaire)
|
VALUES (?, ?, ?, ?, ?, ?)
|
||||||
|
`
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response
|
let response
|
||||||
for (let j = 0; j < matiere_id.length; j++) {
|
for (let j = 0; j < matiere_ids.length; j++) {
|
||||||
response = await query.run(
|
const note = parseFloat(values[j].replace(',', '.')) || 0
|
||||||
|
const [result] = await pool.query(query, [
|
||||||
etudiant_id,
|
etudiant_id,
|
||||||
matiere_id[j],
|
matiere_ids[j],
|
||||||
etudiant_niveau,
|
etudiant_niveau,
|
||||||
mention_id,
|
mention_id,
|
||||||
parseFloat(values[j].replace(',', '.')) || 0,
|
note,
|
||||||
annee_scolaire
|
annee_scolaire
|
||||||
)
|
])
|
||||||
|
response = result
|
||||||
}
|
}
|
||||||
return response
|
return response
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error('Insert error:', error)
|
||||||
return error
|
return error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -47,12 +49,12 @@ async function insertNoteRepech(
|
|||||||
* @returns promise
|
* @returns promise
|
||||||
*/
|
*/
|
||||||
async function getNoteOnline() {
|
async function getNoteOnline() {
|
||||||
const query = database.prepare('SELECT notes.* FROM notes ')
|
const sql = 'SELECT notes.* FROM notes '
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response = await query.all()
|
let [rows] = await pool.query(sql)
|
||||||
|
|
||||||
return response
|
return rows
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return error
|
||||||
}
|
}
|
||||||
@ -63,17 +65,19 @@ async function getNoteOnline() {
|
|||||||
* @returns promise
|
* @returns promise
|
||||||
*/
|
*/
|
||||||
async function getNoteRepech(id, niveau) {
|
async function getNoteRepech(id, niveau) {
|
||||||
let semestre = await matiereSysteme(niveau)
|
const query = `
|
||||||
|
SELECT notesrepech.*, matieres.*
|
||||||
const query2 = database.prepare(
|
FROM notesrepech
|
||||||
'SELECT notesrepech.*, matieres.* FROM notesrepech JOIN matieres ON (notesrepech.matiere_id = matieres.id) WHERE notesrepech.etudiant_id = ? AND notesrepech.etudiant_niveau = ?'
|
JOIN matieres ON notesrepech.matiere_id = matieres.id
|
||||||
)
|
WHERE notesrepech.etudiant_id = ?
|
||||||
|
AND notesrepech.etudiant_niveau = ?
|
||||||
|
`
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response2 = query2.all(id, niveau)
|
const [rows] = await pool.query(query, [id, niveau])
|
||||||
return response2
|
return rows
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error in query2:', error)
|
console.error('Error in getNoteRepech:', error)
|
||||||
return error
|
return error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -83,15 +87,11 @@ async function getNoteRepech(id, niveau) {
|
|||||||
* @returns {Promise<Array>} - Promise resolving to an array of notes or an empty array
|
* @returns {Promise<Array>} - Promise resolving to an array of notes or an empty array
|
||||||
*/
|
*/
|
||||||
async function verifyEtudiantIfHeHasNotesRepech() {
|
async function verifyEtudiantIfHeHasNotesRepech() {
|
||||||
|
const query = `SELECT DISTINCT etudiant_id, etudiant_niveau FROM notesrepech`
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Prepare the query to filter by etudiant_id and etudiant_niveau
|
const [rows] = await pool.query(query)
|
||||||
const query = database.prepare('SELECT DISTINCT etudiant_id, etudiant_niveau FROM notesrepech')
|
return rows
|
||||||
|
|
||||||
// Execute the query with the provided parameters
|
|
||||||
const response = query.all()
|
|
||||||
|
|
||||||
// Return the response
|
|
||||||
return response
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error verifying student notes:', error)
|
console.error('Error verifying student notes:', error)
|
||||||
throw error
|
throw error
|
||||||
@ -104,25 +104,32 @@ async function verifyEtudiantIfHeHasNotesRepech() {
|
|||||||
* @returns promise
|
* @returns promise
|
||||||
*/
|
*/
|
||||||
async function showMoyenRepech(niveau, scolaire) {
|
async function showMoyenRepech(niveau, scolaire) {
|
||||||
const query = database.prepare(
|
try {
|
||||||
`SELECT DISTINCT etudiant_id FROM notesrepech WHERE etudiant_niveau = ? AND annee_scolaire = ?`
|
// 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 etudiantWithNotes = await query.all(niveau, scolaire)
|
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 = ?
|
||||||
|
`
|
||||||
|
|
||||||
let allEtudiantWithNotes = []
|
let allEtudiantWithNotes = []
|
||||||
|
|
||||||
const query2 = database.prepare(
|
// 2. Loop over each student and get their notes repech
|
||||||
'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 (const etudiant of etudiantWithNotes) {
|
||||||
)
|
const [rows] = await pool.query(query2, [etudiant.etudiant_id])
|
||||||
|
allEtudiantWithNotes.push(rows)
|
||||||
try {
|
|
||||||
for (let index = 0; index < etudiantWithNotes.length; index++) {
|
|
||||||
allEtudiantWithNotes.push(query2.all(etudiantWithNotes[index].etudiant_id))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return allEtudiantWithNotes
|
return allEtudiantWithNotes
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error('Error in showMoyenRepech:', error)
|
||||||
return error
|
return error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -134,57 +141,80 @@ async function showMoyenRepech(niveau, scolaire) {
|
|||||||
* @returns {Promise} - Promise resolving to the database response or an error
|
* @returns {Promise} - Promise resolving to the database response or an error
|
||||||
*/
|
*/
|
||||||
async function updateNoteRepech(formData, niveau, id) {
|
async function updateNoteRepech(formData, niveau, id) {
|
||||||
// Extract keys and values dynamically
|
const matiere_ids = Object.keys(formData)
|
||||||
const matiere_id = Object.keys(formData)
|
|
||||||
const values = Object.values(formData)
|
const values = Object.values(formData)
|
||||||
|
|
||||||
const query = database.prepare(
|
const query = `
|
||||||
'UPDATE notesrepech SET note= ? WHERE etudiant_id = ? AND etudiant_niveau = ? AND matiere_id = ?'
|
UPDATE notesrepech
|
||||||
)
|
SET note = ?
|
||||||
|
WHERE etudiant_id = ? AND etudiant_niveau = ? AND matiere_id = ?
|
||||||
|
`
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response
|
let response
|
||||||
|
|
||||||
for (let index = 0; index < matiere_id.length; index++) {
|
for (let index = 0; index < matiere_ids.length; index++) {
|
||||||
let data = values[index]
|
let data = values[index]
|
||||||
|
|
||||||
|
// Convert string number with comma to float, e.g. "12,5" => 12.5
|
||||||
if (typeof data === 'string') {
|
if (typeof data === 'string') {
|
||||||
console.log(parseFloat(data.replace(',', '.')))
|
data = parseFloat(data.replace(',', '.'))
|
||||||
} else {
|
} 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
|
return response
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error('Error updating notes repech:', error)
|
||||||
return error
|
return error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function blockShowMoyeneRepech() {
|
async function blockShowMoyeneRepech() {
|
||||||
const query = database.prepare(
|
const query = `
|
||||||
'SELECT DISTINCT etudiant_niveau, annee_scolaire FROM notesrepech ORDER BY annee_scolaire DESC'
|
SELECT DISTINCT etudiant_niveau, annee_scolaire
|
||||||
)
|
FROM notesrepech
|
||||||
|
ORDER BY annee_scolaire DESC
|
||||||
|
`
|
||||||
|
|
||||||
const queryMention = database.prepare('SELECT * FROM mentions')
|
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 {
|
try {
|
||||||
let response = await query.all()
|
const [response] = await pool.query(query)
|
||||||
let mention = await queryMention.all()
|
const [mention] = await pool.query(queryMention)
|
||||||
let niveau = response.map((item) => item.etudiant_niveau)
|
|
||||||
let annee_scolaire = response.map((item) => item.annee_scolaire)
|
const niveau = response.map((item) => item.etudiant_niveau)
|
||||||
const query2 = database.prepare(
|
const annee_scolaire = response.map((item) => item.annee_scolaire)
|
||||||
`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 = ?`
|
|
||||||
)
|
|
||||||
|
|
||||||
let allData = []
|
let allData = []
|
||||||
|
|
||||||
for (let index = 0; index < niveau.length; index++) {
|
for (let i = 0; i < niveau.length; i++) {
|
||||||
allData.push(await query2.all(niveau[index], annee_scolaire[index]))
|
const [rows] = await pool.query(query2, [niveau[i], annee_scolaire[i]])
|
||||||
|
allData.push(rows)
|
||||||
}
|
}
|
||||||
|
|
||||||
return { response, allData, mention }
|
return { response, allData, mention }
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error('Error in blockShowMoyeneRepech:', error)
|
||||||
return error
|
return error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -197,15 +227,20 @@ async function blockShowMoyeneRepech() {
|
|||||||
* @returns promise
|
* @returns promise
|
||||||
*/
|
*/
|
||||||
async function getMatiereAndNoteRepech(id, niveau, annee_scolaire) {
|
async function getMatiereAndNoteRepech(id, niveau, annee_scolaire) {
|
||||||
const query = database.prepare(
|
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 = ?'
|
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 {
|
try {
|
||||||
let response = await query.all(id, niveau, annee_scolaire)
|
const [rows] = await pool.query(query, [id, niveau, annee_scolaire])
|
||||||
|
return rows
|
||||||
return response
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error('Error in getMatiereAndNoteRepech:', error)
|
||||||
return error
|
return error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,16 +1,16 @@
|
|||||||
const { database } = require('../database.backup')
|
const { pool } = require('../database')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* function to get all Systeme note
|
* function to get all Systeme note
|
||||||
* @returns promise
|
* @returns promise
|
||||||
*/
|
*/
|
||||||
async function getSysteme() {
|
async function getSysteme() {
|
||||||
const query = database.prepare('SELECT * FROM notesystems')
|
const sql = 'SELECT * FROM notesystems'
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response = await query.get()
|
let [rows] = await pool.query(sql)
|
||||||
|
|
||||||
return response
|
return rows[0]
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return error
|
||||||
}
|
}
|
||||||
@ -25,14 +25,22 @@ async function getSysteme() {
|
|||||||
* @returns promise
|
* @returns promise
|
||||||
*/
|
*/
|
||||||
async function updateSysteme(id, admis, redouble, renvoyer) {
|
async function updateSysteme(id, admis, redouble, renvoyer) {
|
||||||
const query = database.prepare(
|
const sql = 'UPDATE notesystems SET admis = ?, redouble = ?, renvoyer = ? WHERE id = ?'
|
||||||
'UPDATE notesystems SET admis = ?, redouble = ?, renvoyer = ? WHERE id = ?'
|
|
||||||
)
|
|
||||||
|
|
||||||
try {
|
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) {
|
} catch (error) {
|
||||||
return error
|
return error
|
||||||
}
|
}
|
||||||
|
|||||||
320
database/Models/Notes copy.js
Normal file
320
database/Models/Notes copy.js
Normal file
@ -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<Array>} - 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
|
||||||
|
}
|
||||||
@ -1,5 +1,4 @@
|
|||||||
const { database } = require('../database.backup')
|
const { pool } = require('../database')
|
||||||
const { getNiveau } = require('./Niveau')
|
|
||||||
const { matiereSysteme } = require('../function/System')
|
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
|
* @returns {Promise} - Promise resolving to the database response or an error
|
||||||
*/
|
*/
|
||||||
async function insertNote(etudiant_id, etudiant_niveau, mention_id, formData, annee_scolaire) {
|
async function insertNote(etudiant_id, etudiant_niveau, mention_id, formData, annee_scolaire) {
|
||||||
// Extract keys and values dynamically
|
|
||||||
const matiere_id = Object.keys(formData)
|
const matiere_id = Object.keys(formData)
|
||||||
const values = Object.values(formData)
|
const values = Object.values(formData)
|
||||||
|
|
||||||
const query = database.prepare(
|
const insertNoteSQL = `
|
||||||
`INSERT INTO notes (etudiant_id, matiere_id, etudiant_niveau, mention_id, note, annee_scolaire) VALUES (?, ?, ?, ?, ?, ?)`
|
INSERT INTO notes (etudiant_id, matiere_id, etudiant_niveau, mention_id, note, annee_scolaire)
|
||||||
)
|
VALUES (?, ?, ?, ?, ?, ?)
|
||||||
|
`
|
||||||
|
|
||||||
const insertRepechQuery = database.prepare(
|
const insertRepechSQL = `
|
||||||
`INSERT INTO notesrepech (etudiant_id, matiere_id, etudiant_niveau, mention_id, note, annee_scolaire) VALUES (?, ?, ?, ?, ?, ?)`
|
INSERT INTO notesrepech (etudiant_id, matiere_id, etudiant_niveau, mention_id, note, annee_scolaire)
|
||||||
)
|
VALUES (?, ?, ?, ?, ?, ?)
|
||||||
|
`
|
||||||
|
|
||||||
console.log(annee_scolaire)
|
const connection = await pool.getConnection()
|
||||||
try {
|
|
||||||
let response
|
|
||||||
let newMatiereId = []
|
let newMatiereId = []
|
||||||
|
|
||||||
// run the session normale
|
try {
|
||||||
database.transaction(() => {
|
await connection.beginTransaction()
|
||||||
|
|
||||||
|
// Insert into notes table
|
||||||
for (let j = 0; j < matiere_id.length; j++) {
|
for (let j = 0; j < matiere_id.length; j++) {
|
||||||
if (values[j] < 10) {
|
const noteValue = parseFloat(values[j].replace(',', '.')) || 0
|
||||||
|
if (noteValue < 10) {
|
||||||
newMatiereId.push(matiere_id[j])
|
newMatiereId.push(matiere_id[j])
|
||||||
}
|
}
|
||||||
|
|
||||||
response = query.run(
|
await connection.execute(insertNoteSQL, [
|
||||||
etudiant_id,
|
etudiant_id,
|
||||||
matiere_id[j],
|
matiere_id[j],
|
||||||
etudiant_niveau,
|
etudiant_niveau,
|
||||||
mention_id,
|
mention_id,
|
||||||
parseFloat(values[j].replace(',', '.')) || 0,
|
noteValue,
|
||||||
annee_scolaire
|
annee_scolaire
|
||||||
)
|
])
|
||||||
}
|
}
|
||||||
})()
|
|
||||||
|
|
||||||
// run the second session and set it to be 0 to display it from screen
|
// Insert into notesrepech with note = 0
|
||||||
database.transaction(() => {
|
|
||||||
for (let j = 0; j < newMatiereId.length; j++) {
|
for (let j = 0; j < newMatiereId.length; j++) {
|
||||||
response = insertRepechQuery.run(
|
await connection.execute(insertRepechSQL, [
|
||||||
etudiant_id,
|
etudiant_id,
|
||||||
newMatiereId[j],
|
newMatiereId[j],
|
||||||
etudiant_niveau,
|
etudiant_niveau,
|
||||||
mention_id,
|
mention_id,
|
||||||
0,
|
0,
|
||||||
annee_scolaire
|
annee_scolaire
|
||||||
)
|
])
|
||||||
}
|
}
|
||||||
})()
|
|
||||||
|
|
||||||
return response
|
await connection.commit()
|
||||||
|
return { success: true }
|
||||||
} catch (error) {
|
} 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
|
* @returns promise
|
||||||
*/
|
*/
|
||||||
async function getNoteOnline() {
|
async function getNoteOnline() {
|
||||||
const query = database.prepare('SELECT notes.* FROM notes ')
|
const sql = 'SELECT notes.* FROM notes '
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response = await query.all()
|
let [rows] = await pool.query(sql)
|
||||||
|
|
||||||
return response
|
return rows
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return error
|
||||||
}
|
}
|
||||||
@ -85,51 +88,42 @@ async function getNoteOnline() {
|
|||||||
*
|
*
|
||||||
* @returns promise
|
* @returns promise
|
||||||
*/
|
*/
|
||||||
async function getNote(id, niveau, mention_id) {
|
async function getNote(id, niveau) {
|
||||||
let semestre = await matiereSysteme(niveau)
|
let connection
|
||||||
|
|
||||||
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 {
|
try {
|
||||||
let response2 = query2.all(id, niveau)
|
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]
|
||||||
|
)
|
||||||
|
|
||||||
|
// 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]
|
||||||
|
)
|
||||||
|
|
||||||
return response2
|
return response2
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error in query2:', error)
|
console.error('Error in getNote:', error)
|
||||||
return error
|
return { error: error.message }
|
||||||
|
} finally {
|
||||||
|
if (connection) connection.release()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,13 +134,13 @@ async function getNote(id, niveau, mention_id) {
|
|||||||
async function verifyEtudiantIfHeHasNotes() {
|
async function verifyEtudiantIfHeHasNotes() {
|
||||||
try {
|
try {
|
||||||
// Prepare the query to filter by etudiant_id and etudiant_niveau
|
// 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
|
// Execute the query with the provided parameters
|
||||||
const response = query.all()
|
const [rows] = await pool.query(sql)
|
||||||
|
|
||||||
// Return the response
|
// Return the response
|
||||||
return response
|
return rows
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error verifying student notes:', error)
|
console.error('Error verifying student notes:', error)
|
||||||
throw error
|
throw error
|
||||||
@ -159,29 +153,37 @@ async function verifyEtudiantIfHeHasNotes() {
|
|||||||
* @returns promise
|
* @returns promise
|
||||||
*/
|
*/
|
||||||
async function showMoyen(niveau, scolaire) {
|
async function showMoyen(niveau, scolaire) {
|
||||||
const query = database.prepare(
|
try {
|
||||||
`SELECT DISTINCT etudiant_id FROM notes WHERE etudiant_niveau = ? AND annee_scolaire = ?`
|
// 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 etudiantWithNotes = await query.all(niveau, scolaire)
|
|
||||||
|
|
||||||
let allEtudiantWithNotes = []
|
let allEtudiantWithNotes = []
|
||||||
|
|
||||||
const query2 = database.prepare(
|
// 2. Prepare the second query
|
||||||
'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 = ?'
|
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++) {
|
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
|
return allEtudiantWithNotes
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
console.error('Error in showMoyen:', error)
|
||||||
|
return { error: error.message }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* function used when updating note
|
* function used when updating note
|
||||||
* @param {Object} formData - The form data containing subject names and values
|
* @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
|
* @returns {Promise} - Promise resolving to the database response or an error
|
||||||
*/
|
*/
|
||||||
async function updateNote(formData, niveau, id, mention_id, annee_scolaire) {
|
async function updateNote(formData, niveau, id, mention_id, annee_scolaire) {
|
||||||
// Extract keys and values dynamically
|
|
||||||
const matiere_id = Object.keys(formData)
|
const matiere_id = Object.keys(formData)
|
||||||
const values = Object.values(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 {
|
try {
|
||||||
let response
|
let response
|
||||||
|
|
||||||
for (let index = 0; index < matiere_id.length; index++) {
|
for (let index = 0; index < matiere_id.length; index++) {
|
||||||
let data = values[index]
|
let data = values[index]
|
||||||
|
|
||||||
|
// Convert string to float safely
|
||||||
if (typeof data === 'string') {
|
if (typeof data === 'string') {
|
||||||
data = parseFloat(data.replace(',', '.'))
|
data = parseFloat(data.replace(',', '.'))
|
||||||
} else {
|
} else {
|
||||||
data = parseFloat(String(data).replace(',', '.'))
|
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 (data < 10) {
|
||||||
if (!check) {
|
// 2. If not already present, insert into notesrepech
|
||||||
insertRepechQuery.run(id, matiere_id[index], niveau, mention_id, 0, annee_scolaire)
|
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 {
|
} else {
|
||||||
clearFromRepech.run(id, niveau, matiere_id[index])
|
// 4. Remove from notesrepech if note >= 10
|
||||||
response = await query.run(data, id, niveau, matiere_id[index])
|
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
|
return response
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error('Error updating note:', error)
|
||||||
return error
|
return error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function blockShowMoyene() {
|
async function blockShowMoyene() {
|
||||||
const query = database.prepare(
|
const query =
|
||||||
'SELECT DISTINCT etudiant_niveau, annee_scolaire FROM notes ORDER BY annee_scolaire DESC'
|
'SELECT DISTINCT etudiant_niveau, annee_scolaire FROM notes ORDER BY annee_scolaire DESC'
|
||||||
)
|
const queryMention = 'SELECT * FROM mentions'
|
||||||
|
const query2 = `
|
||||||
const queryMention = database.prepare('SELECT * FROM mentions')
|
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 {
|
try {
|
||||||
let response = await query.all()
|
const [response] = await pool.query(query)
|
||||||
let mention = await queryMention.all()
|
const [mention] = await pool.query(queryMention)
|
||||||
let niveau = response.map((item) => item.etudiant_niveau)
|
|
||||||
let annee_scolaire = response.map((item) => item.annee_scolaire)
|
const niveau = response.map((item) => item.etudiant_niveau)
|
||||||
const query2 = database.prepare(
|
const annee_scolaire = response.map((item) => item.annee_scolaire)
|
||||||
`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 = []
|
let allData = []
|
||||||
|
|
||||||
for (let index = 0; index < niveau.length; index++) {
|
for (let i = 0; i < niveau.length; i++) {
|
||||||
allData.push(await query2.all(niveau[index], annee_scolaire[index]))
|
const [rows] = await pool.query(query2, [niveau[i], annee_scolaire[i]])
|
||||||
|
allData.push(rows)
|
||||||
}
|
}
|
||||||
|
|
||||||
return { response, allData, mention }
|
return { response, allData, mention }
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
return error
|
return error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get all note with matiere for single student
|
* get all note with matiere for single student
|
||||||
* @param {*} id
|
* @param {*} id
|
||||||
@ -272,36 +295,58 @@ async function blockShowMoyene() {
|
|||||||
* @returns promise
|
* @returns promise
|
||||||
*/
|
*/
|
||||||
async function getMatiereAndNote(id, niveau, annee_scolaire) {
|
async function getMatiereAndNote(id, niveau, annee_scolaire) {
|
||||||
const query = database.prepare(
|
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 = ?'
|
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 {
|
try {
|
||||||
let response = await query.all(id, niveau, annee_scolaire)
|
const [rows] = await pool.query(query, [id, niveau, annee_scolaire])
|
||||||
|
return rows
|
||||||
return response
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getNotesWithRepechToDisplay(id, anneescolaire, niveau) {
|
async function getNotesWithRepechToDisplay(id, anneescolaire, niveau) {
|
||||||
const queryNoteNormal = database.prepare(
|
try {
|
||||||
'SELECT * FROM notes INNER JOIN matieres ON (notes.matiere_id = matieres.id) WHERE notes.etudiant_id = ? AND notes.annee_scolaire = ? AND notes.etudiant_niveau = ?'
|
// 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]
|
||||||
)
|
)
|
||||||
let noteNormal = await queryNoteNormal.all(id, anneescolaire, niveau)
|
|
||||||
|
|
||||||
const queryNoteRepech = database.prepare(
|
// Query for repechage notes
|
||||||
'SELECT * FROM notesrepech INNER JOIN matieres ON (notesrepech.matiere_id = matieres.id) WHERE notesrepech.etudiant_id = ? AND notesrepech.annee_scolaire = ? AND notesrepech.etudiant_niveau = ?'
|
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]
|
||||||
)
|
)
|
||||||
let noteRepech = await queryNoteRepech.all(id, anneescolaire, niveau)
|
|
||||||
|
|
||||||
const semestreQuery = database.prepare(
|
// Query for semesters and matiere-semestre mapping
|
||||||
'SELECT * FROM semestres INNER JOIN matiere_semestre ON(semestres.id = matiere_semestre.semestre_id)'
|
const [semestre] = await pool.query(
|
||||||
|
`SELECT *
|
||||||
|
FROM semestres
|
||||||
|
INNER JOIN matiere_semestre ON semestres.id = matiere_semestre.semestre_id`
|
||||||
)
|
)
|
||||||
let semestre = await semestreQuery.all()
|
|
||||||
|
|
||||||
return { noteNormal, noteRepech, semestre }
|
return { noteNormal, noteRepech, semestre }
|
||||||
|
} catch (error) {
|
||||||
|
return error
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|||||||
@ -1,16 +1,16 @@
|
|||||||
const { database } = require('../database.backup')
|
const { pool } = require('../database')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* function to return all status
|
* function to return all status
|
||||||
* @returns promise
|
* @returns promise
|
||||||
*/
|
*/
|
||||||
async function getStatus() {
|
async function getStatus() {
|
||||||
const query = database.prepare('SELECT * FROM status')
|
const sql = 'SELECT * FROM status'
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response = await query.all()
|
let [rows] = await pool.query(sql)
|
||||||
|
|
||||||
return response
|
return rows
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return error
|
||||||
}
|
}
|
||||||
|
|||||||
@ -72,11 +72,11 @@ async function createTables() {
|
|||||||
num_inscription TEXT UNIQUE NOT NULL,
|
num_inscription TEXT UNIQUE NOT NULL,
|
||||||
sexe VARCHAR(20) DEFAULT NULL,
|
sexe VARCHAR(20) DEFAULT NULL,
|
||||||
cin VARCHAR(250) DEFAULT NULL,
|
cin VARCHAR(250) DEFAULT NULL,
|
||||||
date_delivrance DATE DEFAULT NULL,
|
date_delivrance TEXT DEFAULT NULL,
|
||||||
nationalite DATE DEFAULT NULL,
|
nationalite VARCHAR(250) DEFAULT NULL,
|
||||||
annee_bacc DATE DEFAULT NULL,
|
annee_bacc TEXT DEFAULT NULL,
|
||||||
serie VARCHAR(20) DEFAULT NULL,
|
serie VARCHAR(20) DEFAULT NULL,
|
||||||
boursier TINYINT(1) DEFAULT 0,
|
boursier VARCHAR(20) DEFAULT NULL,
|
||||||
domaine VARCHAR(250) DEFAULT NULL,
|
domaine VARCHAR(250) DEFAULT NULL,
|
||||||
contact VARCHAR(20) DEFAULT NULL,
|
contact VARCHAR(20) DEFAULT NULL,
|
||||||
parcours VARCHAR(250) DEFAULT NULL,
|
parcours VARCHAR(250) DEFAULT NULL,
|
||||||
|
|||||||
@ -1,9 +1,10 @@
|
|||||||
const { database } = require('../database')
|
const { pool } = require('../database')
|
||||||
|
|
||||||
const getStatusMention = (menstionText) => {
|
const getStatusMention = async (menstionText) => {
|
||||||
const query = database.prepare('SELECT * FROM status')
|
const query = 'SELECT * FROM status'
|
||||||
|
|
||||||
let response = query.all()
|
let [rows] = await pool.query(query)
|
||||||
|
let response = rows
|
||||||
let statutCode
|
let statutCode
|
||||||
for (let index = 0; index < response.length; index++) {
|
for (let index = 0; index < response.length; index++) {
|
||||||
let nom = response[index].nom
|
let nom = response[index].nom
|
||||||
|
|||||||
@ -43,219 +43,187 @@ async function updateCurrentYears() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// async function updateStudents() {
|
// Helper functions (unchanged)
|
||||||
// const getInfinishedYears = database
|
function checkNull(params) {
|
||||||
// .prepare('SELECT * FROM traitmentsystem WHERE is_finished = 0 ORDER BY id ASC')
|
if (params === null || params === undefined) return null
|
||||||
// .get()
|
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}`
|
||||||
|
}
|
||||||
|
|
||||||
// const allEtudiants = database
|
async function updateStudents() {
|
||||||
// .prepare('SELECT * FROM etudiants WHERE annee_scolaire = ?')
|
const connection = await pool.getConnection()
|
||||||
// .all(getInfinishedYears.code)
|
try {
|
||||||
|
await connection.beginTransaction()
|
||||||
|
|
||||||
// function checkNull(params) {
|
// Get unfinished years (only one record assumed)
|
||||||
// if (params == null || params == undefined) {
|
const [unfinishedYearsRows] = await connection.query(
|
||||||
// return null
|
'SELECT * FROM traitmentsystem WHERE is_finished = 0 ORDER BY id ASC LIMIT 1'
|
||||||
// }
|
)
|
||||||
// return params
|
if (unfinishedYearsRows.length === 0) {
|
||||||
// }
|
await connection.release()
|
||||||
|
return { message: 'No unfinished years found.' }
|
||||||
|
}
|
||||||
|
const unfinishedYear = unfinishedYearsRows[0]
|
||||||
|
|
||||||
// function compareSessionNotes(session1, session2) {
|
// Get all students of that unfinished year
|
||||||
// let notes
|
const [allEtudiants] = await connection.query(
|
||||||
// if (session2) {
|
'SELECT * FROM etudiants WHERE annee_scolaire = ?',
|
||||||
// if (session1 < session2.note) {
|
[unfinishedYear.code]
|
||||||
// notes = session2.note
|
)
|
||||||
// } else {
|
|
||||||
// notes = session1
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// notes = session1
|
|
||||||
// }
|
|
||||||
// return notes
|
|
||||||
// }
|
|
||||||
|
|
||||||
// database.transaction(() => {
|
// Get distinct student IDs with notes
|
||||||
// // get all note of student
|
let etudiantWithNotes = []
|
||||||
// const queryNotes = database.prepare(
|
for (const etudiant of allEtudiants) {
|
||||||
// `SELECT DISTINCT etudiant_id FROM notes WHERE etudiant_niveau = ? AND annee_scolaire = ?`
|
const [results] = await connection.query(
|
||||||
// )
|
'SELECT DISTINCT etudiant_id FROM notes WHERE etudiant_niveau = ? AND annee_scolaire = ?',
|
||||||
// let allEtudiantWithNotes = []
|
[etudiant.niveau, etudiant.annee_scolaire]
|
||||||
// let etudiantWithNotes = []
|
)
|
||||||
// let dataToMap = []
|
etudiantWithNotes.push(...results)
|
||||||
// let allEtudiantWithNotesRepech = []
|
}
|
||||||
// let etudiantWithNotesRepech = []
|
// Unique IDs
|
||||||
|
const uniqueId = [
|
||||||
|
...new Map(etudiantWithNotes.map((item) => [item.etudiant_id, item])).values()
|
||||||
|
]
|
||||||
|
|
||||||
// for (const etudiant of allEtudiants) {
|
// Get notes details per student
|
||||||
// const results = queryNotes.all(etudiant.niveau, etudiant.annee_scolaire)
|
let allEtudiantWithNotes = []
|
||||||
// etudiantWithNotes.push(...results) // Avoid nested arrays
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
// const uniqueId = etudiantWithNotes.filter(
|
// Get distinct student IDs with notesrepech
|
||||||
// (item, index, self) => index === self.findIndex((t) => t.etudiant_id === item.etudiant_id)
|
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()
|
||||||
|
]
|
||||||
|
|
||||||
// const query2 = database.prepare(
|
// Get notesrepech details per student
|
||||||
// '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 = ?'
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
// for (let j = 0; j < uniqueId.length; j++) {
|
// Compute averages and prepare data
|
||||||
// allEtudiantWithNotes.push(query2.all(uniqueId[j].etudiant_id))
|
let dataToMap = []
|
||||||
// }
|
for (let i = 0; i < allEtudiantWithNotes.length; i++) {
|
||||||
|
const notesNormal = allEtudiantWithNotes[i]
|
||||||
|
const notesRepech = allEtudiantWithNotesRepech[i] || []
|
||||||
|
|
||||||
// const query = database.prepare(
|
let total = 0
|
||||||
// `SELECT DISTINCT etudiant_id FROM notesrepech WHERE etudiant_niveau = ? AND annee_scolaire = ?`
|
let totalCredit = 0
|
||||||
// )
|
let modelJson = {
|
||||||
|
id: '',
|
||||||
|
nom: '',
|
||||||
|
prenom: '',
|
||||||
|
photos: '',
|
||||||
|
moyenne: '',
|
||||||
|
mention: '',
|
||||||
|
niveau: '',
|
||||||
|
annee_scolaire: ''
|
||||||
|
}
|
||||||
|
|
||||||
// for (const etudiant of allEtudiants) {
|
for (let j = 0; j < notesNormal.length; j++) {
|
||||||
// const results = query.all(etudiant.niveau, etudiant.annee_scolaire)
|
const normalNote = notesNormal[j]
|
||||||
// etudiantWithNotesRepech.push(...results) // Avoid nested arrays
|
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
|
||||||
|
|
||||||
// const uniqueIdRepech = etudiantWithNotes.filter(
|
// Find repech note for same matiere if exists
|
||||||
// (item, index, self) => index === self.findIndex((t) => t.etudiant_id === item.etudiant_id)
|
const repechNoteObj = notesRepech.find((r) => r.matiere_id === normalNote.matiere_id)
|
||||||
// )
|
const noteToUse = compareSessionNotes(normalNote.note, checkNull(repechNoteObj))
|
||||||
|
|
||||||
// const query2Repech = database.prepare(
|
total += (noteToUse ?? 0) * normalNote.credit
|
||||||
// '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 = ?'
|
totalCredit += normalNote.credit
|
||||||
// )
|
}
|
||||||
|
|
||||||
// for (let j = 0; j < uniqueIdRepech.length; j++) {
|
modelJson.moyenne = (totalCredit > 0 ? total / totalCredit : 0).toFixed(2)
|
||||||
// allEtudiantWithNotesRepech.push(query2Repech.all(uniqueIdRepech[j].etudiant_id))
|
dataToMap.push(modelJson)
|
||||||
// }
|
}
|
||||||
|
|
||||||
// for (let index = 0; index < allEtudiantWithNotes.length; index++) {
|
// Get note system thresholds
|
||||||
// let total = 0
|
const [noteSystemRows] = await connection.query('SELECT * FROM notesystems LIMIT 1')
|
||||||
// let note = 0
|
const noteSystem = noteSystemRows[0]
|
||||||
// let totalCredit = 0
|
|
||||||
|
|
||||||
// // Create a new object for each student
|
// Update etudiants based on moyenne
|
||||||
// let modelJson = {
|
for (const student of dataToMap) {
|
||||||
// id: '',
|
let status, newNiveau, newAnnee
|
||||||
// nom: '',
|
newAnnee = updateSchoolYear(student.annee_scolaire)
|
||||||
// prenom: '',
|
|
||||||
// photos: '',
|
|
||||||
// moyenne: '',
|
|
||||||
// mention: '',
|
|
||||||
// niveau: '',
|
|
||||||
// annee_scolaire: ''
|
|
||||||
// }
|
|
||||||
|
|
||||||
// for (let j = 0; j < allEtudiantWithNotes[index].length; j++) {
|
if (student.moyenne >= noteSystem.admis) {
|
||||||
// modelJson.id = allEtudiantWithNotes[index][j].etudiant_id
|
newNiveau = nextLevel(student.niveau)
|
||||||
// modelJson.nom = allEtudiantWithNotes[index][j].nom
|
status = 2 // Passed
|
||||||
// modelJson.prenom = allEtudiantWithNotes[index][j].prenom
|
} else if (student.moyenne >= noteSystem.redouble) {
|
||||||
// modelJson.photos = allEtudiantWithNotes[index][j].photos
|
newNiveau = student.niveau
|
||||||
// modelJson.mention = allEtudiantWithNotes[index][j].mention_id
|
status = 3 // Repeat
|
||||||
// modelJson.niveau = allEtudiantWithNotes[index][j].niveau
|
} else {
|
||||||
// modelJson.annee_scolaire = allEtudiantWithNotes[index][j].annee_scolaire
|
newNiveau = student.niveau
|
||||||
|
status = 4 // Fail
|
||||||
|
}
|
||||||
|
|
||||||
// // console.log(checkNull(session[index][j]));
|
await connection.query(
|
||||||
// if (allEtudiantWithNotesRepech[index]) {
|
'UPDATE etudiants SET niveau = ?, annee_scolaire = ?, status = ? WHERE id = ?',
|
||||||
// note +=
|
[newNiveau, newAnnee, status, student.id]
|
||||||
// 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
|
// Mark unfinished year as finished
|
||||||
// modelJson.moyenne = total.toFixed(2)
|
await connection.query('UPDATE traitmentsystem SET is_finished = 1 WHERE id = ?', [
|
||||||
|
unfinishedYear.id
|
||||||
|
])
|
||||||
|
|
||||||
// // Add the new object to the array
|
await connection.commit()
|
||||||
// dataToMap.push(modelJson)
|
connection.release()
|
||||||
// }
|
|
||||||
|
|
||||||
// // update all etudiant
|
return { success: true, message: 'Students updated successfully' }
|
||||||
// let updated = false
|
} catch (error) {
|
||||||
// if (dataToMap.length != 0) {
|
await connection.rollback()
|
||||||
// let noteSystem = database.prepare('SELECT * FROM notesystems').get()
|
connection.release()
|
||||||
// for (let index = 0; index < dataToMap.length; index++) {
|
console.error(error)
|
||||||
// if (dataToMap[index].moyenne >= noteSystem.admis) {
|
throw error
|
||||||
// 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
|
|
||||||
// }
|
|
||||||
|
|
||||||
async function matiereSysteme(etudiant_niveau) {
|
async function matiereSysteme(etudiant_niveau) {
|
||||||
let systeme
|
let systeme
|
||||||
@ -300,33 +268,43 @@ async function matiereSystemReverse(semestre) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// async function getNessesarytable() {
|
async function getNessesarytable() {
|
||||||
// try {
|
try {
|
||||||
// const query = await database.prepare('SELECT * FROM nessesaryTable').get()
|
const sql = 'SELECT * FROM nessesaryTable'
|
||||||
|
const [rows] = await pool.query(sql)
|
||||||
|
return rows
|
||||||
|
} catch (error) {
|
||||||
|
return error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// return query
|
async function updateNessesaryTable(id, multiplicateur) {
|
||||||
// } catch (error) {
|
const sql = 'UPDATE nessesaryTable SET uniter_heure = ? WHERE id = ?'
|
||||||
// return error
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// async function updateNessesaryTable(id, multiplicateur) {
|
try {
|
||||||
// const query = database.prepare('UPDATE nessesaryTable SET uniter_heure = ? WHERE id = ?')
|
const [result] = await pool.query(sql, [multiplicateur, id])
|
||||||
|
|
||||||
// try {
|
if (result.affectedRows === 0) {
|
||||||
// let update = query.run(multiplicateur, id)
|
return {
|
||||||
|
success: false,
|
||||||
|
message: 'Année universitaire non trouvé.'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// return update
|
return {
|
||||||
// } catch (error) {
|
success: true,
|
||||||
// return error
|
message: 'Année universitaire supprimé avec succès.'
|
||||||
// }
|
}
|
||||||
// }
|
} catch (error) {
|
||||||
|
return error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
matiereSysteme,
|
matiereSysteme,
|
||||||
updateCurrentYears,
|
updateCurrentYears,
|
||||||
// updateStudents,
|
updateStudents,
|
||||||
// getNessesarytable,
|
getNessesarytable,
|
||||||
// updateNessesaryTable,
|
updateNessesaryTable,
|
||||||
matiereSystemReverse
|
matiereSystemReverse
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,12 +3,11 @@ const path = require('path')
|
|||||||
const XLSX = require('xlsx')
|
const XLSX = require('xlsx')
|
||||||
const { getCompressedDefaultImage } = require('../function/GetImageDefaault')
|
const { getCompressedDefaultImage } = require('../function/GetImageDefaault')
|
||||||
const { parse } = require('csv-parse/sync')
|
const { parse } = require('csv-parse/sync')
|
||||||
const { insertEtudiant } = require('../Models/Etudiants')
|
const { pool } = require('../database')
|
||||||
const { database } = require('../database')
|
|
||||||
const { getMentions } = require('../Models/Mentions')
|
|
||||||
const dayjs = require('dayjs')
|
const dayjs = require('dayjs')
|
||||||
const { getStatusMention } = require('../function/Helper')
|
// const { getStatusMention } = require('../function/Helper')
|
||||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||||
|
// const { log } = require('console')
|
||||||
// const customParseFormatt = require('dayjs/plu')
|
// const customParseFormatt = require('dayjs/plu')
|
||||||
dayjs.extend(customParseFormat)
|
dayjs.extend(customParseFormat)
|
||||||
|
|
||||||
@ -50,12 +49,50 @@ function convertToISODate(input) {
|
|||||||
return jsDate
|
return jsDate
|
||||||
}
|
}
|
||||||
|
|
||||||
async function MentionList() {
|
async function insertMultipleEtudiants(etudiants) {
|
||||||
let response = await getMentions()
|
const sql = `
|
||||||
return response
|
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 ?
|
||||||
|
`
|
||||||
|
|
||||||
let ListMention
|
// 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
|
||||||
|
])
|
||||||
|
|
||||||
|
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
|
* 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
|
// ✅ Count number of data rows
|
||||||
const numberOfLines = records.length;
|
const numberOfLines = records.length
|
||||||
console.log(`Number of data rows: ${numberOfLines}`);
|
console.log(`Number of data rows: ${numberOfLines}`)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let error = true
|
let error = true
|
||||||
let message = ''
|
let message = ''
|
||||||
|
|
||||||
// Vérifier les données en une seule boucle
|
// Vérifier les données en une seule boucle
|
||||||
let ar = [];
|
let oldNum = ''
|
||||||
let oldNum = '';
|
|
||||||
for (const row of records) {
|
for (const row of records) {
|
||||||
if (
|
if (
|
||||||
!row.nom ||
|
!row.nom ||
|
||||||
@ -160,19 +196,17 @@ async function importFileToDatabase(filePath) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchMentions() {
|
const query = 'SELECT * FROM mentions'
|
||||||
try {
|
const [rows] = await pool.query(query)
|
||||||
// Fetch the mentions
|
const MentionList = rows
|
||||||
ListMention = await MentionList()
|
console.log(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) {
|
if (error !== false) {
|
||||||
|
let newReccord = []
|
||||||
// Utiliser transaction pour éviter une latence si l'insertion dépasse 100
|
// Utiliser transaction pour éviter une latence si l'insertion dépasse 100
|
||||||
database.transaction(() => {
|
|
||||||
for (const row of records) {
|
for (const row of records) {
|
||||||
// Convert row.mention to uppercase and compare with ListMention.nom and ListMention.uniter (also converted to uppercase)
|
// Convert row.mention to uppercase and compare with ListMention.nom and ListMention.uniter (also converted to uppercase)
|
||||||
const matchedMention = ListMention.find(
|
const matchedMention = MentionList.find(
|
||||||
(mention) =>
|
(mention) =>
|
||||||
mention.nom.toUpperCase() === row.mention.toUpperCase() ||
|
mention.nom.toUpperCase() === row.mention.toUpperCase() ||
|
||||||
mention.uniter.toUpperCase() === row.mention.toUpperCase()
|
mention.uniter.toUpperCase() === row.mention.toUpperCase()
|
||||||
@ -182,53 +216,41 @@ async function importFileToDatabase(filePath) {
|
|||||||
if (matchedMention) {
|
if (matchedMention) {
|
||||||
row.mention = matchedMention.id
|
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()
|
row.num_inscription = row.num_inscription.toString()
|
||||||
|
|
||||||
ar.push(row)
|
|
||||||
console.log(ar.length, 'create');
|
|
||||||
try {
|
try {
|
||||||
let compare = row.num_inscription;
|
let compare = row.num_inscription
|
||||||
if (compare == oldNum) {
|
if (compare == oldNum) {
|
||||||
row.num_inscription = Number(row.num_inscription + 1);
|
row.num_inscription = String(row.num_inscription)
|
||||||
}
|
}
|
||||||
console.log(
|
console.log(row.code_redoublement)
|
||||||
insertEtudiant(
|
newReccord.push(row)
|
||||||
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
|
oldNum = compare
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})()
|
console.log(insertMultipleEtudiants(newReccord))
|
||||||
}
|
}
|
||||||
} catch (error) {
|
|
||||||
console.error('Error:', error) // Handle any errors
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fetchMentions()
|
|
||||||
|
|
||||||
return { error, message }
|
return { error, message }
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@ -2,8 +2,39 @@ const fs = require('fs')
|
|||||||
const path = require('path')
|
const path = require('path')
|
||||||
const XLSX = require('xlsx')
|
const XLSX = require('xlsx')
|
||||||
const { parse } = require('csv-parse/sync')
|
const { parse } = require('csv-parse/sync')
|
||||||
const { createMatiere } = require('../Models/Matieres')
|
const { pool } = require('../database')
|
||||||
const { database } = require('../database.backup')
|
|
||||||
|
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
|
* 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) {
|
if (error !== false) {
|
||||||
database.transaction(() => {
|
createMatieresBatch(records)
|
||||||
for (const row of records) {
|
|
||||||
createMatiere(row.nom, row.credit, row.uniter, row.ue)
|
|
||||||
}
|
|
||||||
})()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return { error, message }
|
return { error, message }
|
||||||
|
|||||||
@ -93,7 +93,7 @@ const AddNotes = () => {
|
|||||||
annee_scolaire
|
annee_scolaire
|
||||||
})
|
})
|
||||||
console.log(response)
|
console.log(response)
|
||||||
if (response.changes) {
|
if (response.success) {
|
||||||
setOpen(true)
|
setOpen(true)
|
||||||
setStatut(200)
|
setStatut(200)
|
||||||
setDisabled(true)
|
setDisabled(true)
|
||||||
|
|||||||
@ -185,12 +185,12 @@ const AddStudent = () => {
|
|||||||
const response = await window.etudiants.insertEtudiant(formData)
|
const response = await window.etudiants.insertEtudiant(formData)
|
||||||
|
|
||||||
console.log(response)
|
console.log(response)
|
||||||
if (response.code) {
|
if (!response.success) {
|
||||||
setCode(422)
|
setCode(422)
|
||||||
setOpen(true)
|
setOpen(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.changes) {
|
if (response.success) {
|
||||||
imageVisual.current.style.display = 'none'
|
imageVisual.current.style.display = 'none'
|
||||||
imageVisual.current.src = ''
|
imageVisual.current.src = ''
|
||||||
setCode(200)
|
setCode(200)
|
||||||
|
|||||||
@ -29,7 +29,7 @@ const AjoutTranche = ({ open, onClose, onSubmitSuccess, id }) => {
|
|||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
let response = await window.etudiants.createTranche(formData)
|
let response = await window.etudiants.createTranche(formData)
|
||||||
|
|
||||||
if (response.changes) {
|
if (response.success) {
|
||||||
onClose()
|
onClose()
|
||||||
onSubmitSuccess(true)
|
onSubmitSuccess(true)
|
||||||
setFormData({
|
setFormData({
|
||||||
|
|||||||
@ -22,7 +22,7 @@ const DeleteTranche = ({ open, onClose, id, onSubmitSuccess }) => {
|
|||||||
if (idDelete !== null) {
|
if (idDelete !== null) {
|
||||||
const id = idDelete
|
const id = idDelete
|
||||||
let response = await window.etudiants.deleteTranche({ id })
|
let response = await window.etudiants.deleteTranche({ id })
|
||||||
if (response.changes) {
|
if (response.success) {
|
||||||
onSubmitSuccess(true)
|
onSubmitSuccess(true)
|
||||||
onClose()
|
onClose()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,7 +42,7 @@ const ModalFormMultiplicateur = ({ open, onClose }) => {
|
|||||||
console.log(formData)
|
console.log(formData)
|
||||||
let response = await window.matieres.updateNessesary(formData)
|
let response = await window.matieres.updateNessesary(formData)
|
||||||
|
|
||||||
if (response.changes) {
|
if (response.success) {
|
||||||
onClose() // Close the modal after submission
|
onClose() // Close the modal after submission
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -210,8 +210,10 @@ const Noteclasse = () => {
|
|||||||
const [selectedId, setSelectedId] = useState(null) // Store id dynamically
|
const [selectedId, setSelectedId] = useState(null) // Store id dynamically
|
||||||
|
|
||||||
const sendData = (id) => {
|
const sendData = (id) => {
|
||||||
setOpenCart(true)
|
|
||||||
setSelectedId(id)
|
setSelectedId(id)
|
||||||
|
// if (selectedId !== null) {
|
||||||
|
setOpenCart(true)
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@ -55,6 +55,11 @@ const ReleverNotes = ({ id, anneescolaire, niveau, refs }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
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) => {
|
window.etudiants.getSingle({ id }).then((response) => {
|
||||||
setEtudiant(response)
|
setEtudiant(response)
|
||||||
})
|
})
|
||||||
|
|||||||
@ -25,6 +25,7 @@ import { FaRegTimesCircle } from 'react-icons/fa'
|
|||||||
import MenuItem from '@mui/material/MenuItem'
|
import MenuItem from '@mui/material/MenuItem'
|
||||||
import { MdGrade, MdRule } from 'react-icons/md'
|
import { MdGrade, MdRule } from 'react-icons/md'
|
||||||
import { FaLeftLong, FaRightLong } from 'react-icons/fa6'
|
import { FaLeftLong, FaRightLong } from 'react-icons/fa6'
|
||||||
|
import dayjs from 'dayjs'
|
||||||
|
|
||||||
const SingleEtudiant = () => {
|
const SingleEtudiant = () => {
|
||||||
const { id } = useParams()
|
const { id } = useParams()
|
||||||
@ -85,7 +86,6 @@ const SingleEtudiant = () => {
|
|||||||
})
|
})
|
||||||
}, [id])
|
}, [id])
|
||||||
|
|
||||||
console.log(scolaire)
|
|
||||||
function comparestatut(statutID) {
|
function comparestatut(statutID) {
|
||||||
let statusText
|
let statusText
|
||||||
|
|
||||||
@ -115,7 +115,7 @@ const SingleEtudiant = () => {
|
|||||||
nom: etudiant.nom || '',
|
nom: etudiant.nom || '',
|
||||||
prenom: etudiant.prenom || '',
|
prenom: etudiant.prenom || '',
|
||||||
photos: etudiant.photos || null,
|
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 || '',
|
niveau: etudiant.niveau || '',
|
||||||
annee_scolaire: etudiant.annee_scolaire || '',
|
annee_scolaire: etudiant.annee_scolaire || '',
|
||||||
status: etudiant.status || '',
|
status: etudiant.status || '',
|
||||||
@ -125,8 +125,8 @@ const SingleEtudiant = () => {
|
|||||||
sexe: etudiant.sexe,
|
sexe: etudiant.sexe,
|
||||||
nationalite: etudiant.nationalite,
|
nationalite: etudiant.nationalite,
|
||||||
cin: etudiant.cin,
|
cin: etudiant.cin,
|
||||||
date_delivrance: etudiant.date_delivrance,
|
date_delivrance: dayjs(etudiant.date_delivrance).format('YYYY-MM-DD'),
|
||||||
annee_bacc: etudiant.annee_bacc,
|
annee_bacc: dayjs(etudiant.annee_bacc).format('YYYY-MM-DD'),
|
||||||
serie: etudiant.serie,
|
serie: etudiant.serie,
|
||||||
boursier: etudiant.boursier,
|
boursier: etudiant.boursier,
|
||||||
domaine: etudiant.domaine,
|
domaine: etudiant.domaine,
|
||||||
@ -192,7 +192,7 @@ const SingleEtudiant = () => {
|
|||||||
// If validation passes, proceed with the submission
|
// If validation passes, proceed with the submission
|
||||||
try {
|
try {
|
||||||
let response = await window.etudiants.updateEtudiants(formData)
|
let response = await window.etudiants.updateEtudiants(formData)
|
||||||
if (response.changes) {
|
if (response.success) {
|
||||||
setEtudiant(formData)
|
setEtudiant(formData)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -267,7 +267,9 @@ const SingleEtudiant = () => {
|
|||||||
let imgAvatar = avatar.querySelector('img')
|
let imgAvatar = avatar.querySelector('img')
|
||||||
|
|
||||||
window.etudiants.updateEtudiantsPDP({ pdp, id }).then((responses) => {
|
window.etudiants.updateEtudiantsPDP({ pdp, id }).then((responses) => {
|
||||||
if (responses.changes) {
|
console.log(responses);
|
||||||
|
|
||||||
|
if (responses.success) {
|
||||||
if (imgAvatar === null) {
|
if (imgAvatar === null) {
|
||||||
let image = document.createElement('img')
|
let image = document.createElement('img')
|
||||||
image.setAttribute('src', pdp)
|
image.setAttribute('src', pdp)
|
||||||
@ -507,7 +509,7 @@ const SingleEtudiant = () => {
|
|||||||
name="date_de_naissances"
|
name="date_de_naissances"
|
||||||
color="warning"
|
color="warning"
|
||||||
type="date"
|
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}
|
onChange={handleChange}
|
||||||
InputLabelProps={{
|
InputLabelProps={{
|
||||||
shrink: true
|
shrink: true
|
||||||
@ -721,7 +723,7 @@ const SingleEtudiant = () => {
|
|||||||
name="date_delivrance"
|
name="date_delivrance"
|
||||||
color="warning"
|
color="warning"
|
||||||
type="date"
|
type="date"
|
||||||
defaultValue={etudiant.date_delivrance} // Controlled component value
|
defaultValue={dayjs(etudiant.date_delivrance).format('YYYY-MM-DD')} // Controlled component value
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
InputProps={{
|
InputProps={{
|
||||||
startAdornment: (
|
startAdornment: (
|
||||||
@ -899,8 +901,8 @@ const SingleEtudiant = () => {
|
|||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<MenuItem value={'OUI'}>Oui</MenuItem>
|
<MenuItem value={'oui'}>Oui</MenuItem>
|
||||||
<MenuItem value={'NON'}>Non</MenuItem>
|
<MenuItem value={'non'}>Non</MenuItem>
|
||||||
</TextField>
|
</TextField>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item xs={6}>
|
<Grid item xs={6}>
|
||||||
@ -1101,7 +1103,7 @@ const SingleEtudiant = () => {
|
|||||||
variant="h6"
|
variant="h6"
|
||||||
style={{ display: 'flex', justifyContent: 'space-between' }}
|
style={{ display: 'flex', justifyContent: 'space-between' }}
|
||||||
>
|
>
|
||||||
<span>Date de Naissance:</span> {etudiant.date_de_naissances}
|
<span>Date de Naissance:</span> {dayjs(etudiant.date_de_naissances).format('YYYY-MM-DD')}
|
||||||
</Typography>
|
</Typography>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item xs={12}>
|
<Grid item xs={12}>
|
||||||
|
|||||||
@ -218,7 +218,7 @@ const Student = () => {
|
|||||||
display: 'flex',
|
display: 'flex',
|
||||||
flexDirection: 'column',
|
flexDirection: 'column',
|
||||||
gap: '10px',
|
gap: '10px',
|
||||||
marginTop:"15px"
|
marginTop: "15px"
|
||||||
}}
|
}}
|
||||||
place="left-end"
|
place="left-end"
|
||||||
clickable
|
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)
|
// Ensure that the array is flat (not wrapped in another array)
|
||||||
const dataRow = etudiants.map((etudiant) => ({
|
const dataRow = etudiants.map((etudiant) => ({
|
||||||
@ -325,7 +337,7 @@ const Student = () => {
|
|||||||
photos: etudiant.photos,
|
photos: etudiant.photos,
|
||||||
sexe: etudiant.sexe,
|
sexe: etudiant.sexe,
|
||||||
cin: etudiant.cin,
|
cin: etudiant.cin,
|
||||||
date_deli: etudiant.date_delivrance,
|
date_deli: dayjs(etudiant.date_delivrance).format('DD-MM-YYYY'),
|
||||||
nation: etudiant.nationalite,
|
nation: etudiant.nationalite,
|
||||||
annee_bacc: etudiant.annee_bacc,
|
annee_bacc: etudiant.annee_bacc,
|
||||||
serie: etudiant.serie,
|
serie: etudiant.serie,
|
||||||
@ -529,8 +541,11 @@ const Student = () => {
|
|||||||
<DataGrid
|
<DataGrid
|
||||||
rows={dataRow}
|
rows={dataRow}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
initialState={{ pagination: { paginationModel } }}
|
// initialState={{ pagination: { paginationModel } }}
|
||||||
pageSizeOptions={[5, 10]}
|
// pageSizeOptions={[20, 40, 60]}
|
||||||
|
pageSizeOptions={pageSizeOptions}
|
||||||
|
paginationModel={{ pageSize, page: 0 }}
|
||||||
|
onPaginationModelChange={(model) => handlePageSizeChange(model.pageSize)}
|
||||||
sx={{
|
sx={{
|
||||||
border: 0,
|
border: 0,
|
||||||
width: 'auto', // Ensures the DataGrid takes full width
|
width: 'auto', // Ensures the DataGrid takes full width
|
||||||
|
|||||||
@ -53,13 +53,16 @@ const SystemeNote = () => {
|
|||||||
}
|
}
|
||||||
}, [noteSy])
|
}, [noteSy])
|
||||||
|
|
||||||
|
console.log(noteSy)
|
||||||
|
|
||||||
const formSubmit = async (e) => {
|
const formSubmit = async (e) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
let valid = validateNOteSystem(admisRef.current, redoubleRef.current, renvoyerRef.current)
|
let valid = validateNOteSystem(admisRef.current, redoubleRef.current, renvoyerRef.current)
|
||||||
|
|
||||||
if (valid) {
|
if (valid) {
|
||||||
let response = await window.notesysteme.updateNoteSysteme(formData)
|
let response = await window.notesysteme.updateNoteSysteme(formData)
|
||||||
if (response.changes) {
|
console.log(response)
|
||||||
|
if (response.success) {
|
||||||
setStatus(200)
|
setStatus(200)
|
||||||
setOpen(true)
|
setOpen(true)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user