Compare commits
2 Commits
82b5e6a68e
...
0cf0a72814
| Author | SHA1 | Date |
|---|---|---|
|
|
0cf0a72814 | 7 months ago |
|
|
290f5747fb | 7 months ago |
47 changed files with 3914 additions and 1330 deletions
@ -0,0 +1,305 @@ |
|||||
|
const { database } = require('../database.backup') |
||||
|
|
||||
|
/** |
||||
|
* function to insert etudiant into databases |
||||
|
*/ |
||||
|
async function insertEtudiant( |
||||
|
nom, |
||||
|
prenom, |
||||
|
photos, |
||||
|
date_de_naissances, |
||||
|
niveau, |
||||
|
annee_scolaire, |
||||
|
status, |
||||
|
num_inscription, |
||||
|
mention_id, |
||||
|
sexe, |
||||
|
nationaliter, |
||||
|
cin, |
||||
|
date_delivrence, |
||||
|
annee_bacc, |
||||
|
serie, |
||||
|
boursier, |
||||
|
domaine, |
||||
|
contact, |
||||
|
parcours |
||||
|
) { |
||||
|
const query = database.prepare( |
||||
|
'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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' |
||||
|
) |
||||
|
|
||||
|
try { |
||||
|
let response = await query.run( |
||||
|
nom, |
||||
|
prenom, |
||||
|
photos, |
||||
|
date_de_naissances, |
||||
|
niveau, |
||||
|
annee_scolaire, |
||||
|
status, |
||||
|
mention_id, |
||||
|
num_inscription, |
||||
|
sexe, |
||||
|
cin, |
||||
|
date_delivrence, |
||||
|
nationaliter, |
||||
|
annee_bacc, |
||||
|
serie, |
||||
|
boursier, |
||||
|
domaine, |
||||
|
contact, |
||||
|
parcours |
||||
|
) |
||||
|
return response |
||||
|
} catch (error) { |
||||
|
return error |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* function to get all etudiants |
||||
|
* |
||||
|
* @returns JSON |
||||
|
*/ |
||||
|
async function getAllEtudiants() { |
||||
|
const query = database.prepare('SELECT * FROM etudiants ORDER BY annee_scolaire DESC') |
||||
|
try { |
||||
|
let response = await query.all() |
||||
|
|
||||
|
return response |
||||
|
} catch (error) { |
||||
|
return error |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* function to return a single etudiant |
||||
|
* and display it on the screen |
||||
|
* |
||||
|
* @param {int} id |
||||
|
* @returns Promise |
||||
|
*/ |
||||
|
async function getSingleEtudiant(id) { |
||||
|
const query = database.prepare('SELECT * FROM etudiants WHERE id = ?') |
||||
|
|
||||
|
try { |
||||
|
const etudiants = await query.get(id) |
||||
|
|
||||
|
if (etudiants) { |
||||
|
return etudiants |
||||
|
} else { |
||||
|
return { message: 'etudiants pas trouver' } |
||||
|
} |
||||
|
} catch (error) { |
||||
|
return error |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* function to get all etudiants M2 |
||||
|
* |
||||
|
* @returns JSON |
||||
|
*/ |
||||
|
async function FilterDataByNiveau(niveau) { |
||||
|
const query = database.prepare( |
||||
|
'SELECT * FROM etudiants WHERE niveau = ? ORDER BY annee_scolaire DESC' |
||||
|
) |
||||
|
try { |
||||
|
let response = await query.all(niveau) |
||||
|
|
||||
|
return response |
||||
|
} catch (error) { |
||||
|
return error |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* function to update etudiants |
||||
|
* |
||||
|
* @param {*} nom |
||||
|
* @param {*} prenom |
||||
|
* @param {*} photos |
||||
|
* @param {*} date_de_naissances |
||||
|
* @param {*} niveau |
||||
|
* @param {*} annee_scolaire |
||||
|
* @param {*} status |
||||
|
* @param {*} num_inscription |
||||
|
* @param {*} id |
||||
|
* @returns promise |
||||
|
*/ |
||||
|
async function updateEtudiant( |
||||
|
nom, |
||||
|
prenom, |
||||
|
photos, |
||||
|
date_de_naissances, |
||||
|
niveau, |
||||
|
annee_scolaire, |
||||
|
status, |
||||
|
mention_id, |
||||
|
num_inscription, |
||||
|
id, |
||||
|
sexe, |
||||
|
nationalite, |
||||
|
cin, |
||||
|
date_delivrence, |
||||
|
annee_bacc, |
||||
|
serie, |
||||
|
boursier, |
||||
|
domaine, |
||||
|
contact, |
||||
|
parcours |
||||
|
) { |
||||
|
const query = database.prepare( |
||||
|
'UPDATE etudiants SET 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 = ? WHERE id = ?' |
||||
|
) |
||||
|
|
||||
|
try { |
||||
|
let response = await query.run( |
||||
|
nom, |
||||
|
prenom, |
||||
|
photos, |
||||
|
date_de_naissances, |
||||
|
niveau, |
||||
|
annee_scolaire, |
||||
|
status, |
||||
|
mention_id, |
||||
|
num_inscription, |
||||
|
sexe, |
||||
|
cin, |
||||
|
date_delivrence, |
||||
|
nationalite, |
||||
|
annee_bacc, |
||||
|
serie, |
||||
|
boursier, |
||||
|
domaine, |
||||
|
contact, |
||||
|
parcours, |
||||
|
id |
||||
|
) |
||||
|
|
||||
|
return response |
||||
|
} catch (error) { |
||||
|
return error |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* function to return the needed data in dashboard |
||||
|
* |
||||
|
* @returns promise |
||||
|
*/ |
||||
|
async function getDataToDashboard() { |
||||
|
const query = database.prepare('SELECT * FROM niveaus') |
||||
|
const query2 = database.prepare('SELECT * FROM etudiants') |
||||
|
const query3 = database.prepare('SELECT DISTINCT annee_scolaire FROM etudiants') // get all année scolaire sans doublan
|
||||
|
|
||||
|
try { |
||||
|
let niveau = query.all() |
||||
|
let etudiants = query2.all() |
||||
|
let anne_scolaire = query3.all() |
||||
|
|
||||
|
return { niveau, etudiants, anne_scolaire } |
||||
|
} catch (error) { |
||||
|
return error |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
async function changePDP(photos, id) { |
||||
|
const query = database.prepare('UPDATE etudiants SET photos = ? WHERE id = ?') |
||||
|
|
||||
|
try { |
||||
|
let response = await query.run(photos, id) |
||||
|
|
||||
|
return response |
||||
|
} catch (error) { |
||||
|
return error |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
async function updateParcours(parcours, id) { |
||||
|
const query = database.prepare('UPDATE etudiants SET parcours = ? WHERE id = ?') |
||||
|
|
||||
|
try { |
||||
|
let response = await query.run(parcours, id) |
||||
|
|
||||
|
return response |
||||
|
} catch (error) { |
||||
|
return error |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
async function createTranche(etudiant_id, tranchename, montant) { |
||||
|
const query = database.prepare( |
||||
|
'INSERT INTO trancheecolage (etudiant_id, tranchename, montant) VALUES (?, ?, ?)' |
||||
|
) |
||||
|
|
||||
|
try { |
||||
|
let response = query.run(etudiant_id, tranchename, montant) |
||||
|
|
||||
|
return response |
||||
|
} catch (error) { |
||||
|
return error |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
async function getTranche(id) { |
||||
|
const query = database.prepare('SELECT * FROM trancheecolage WHERE etudiant_id = ?') |
||||
|
|
||||
|
try { |
||||
|
let response = query.all(id) |
||||
|
|
||||
|
return response |
||||
|
} catch (error) { |
||||
|
return error |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
async function updateTranche(id, tranchename, montant) { |
||||
|
const query = database.prepare( |
||||
|
'UPDATE trancheecolage SET tranchename = ?, montant = ? WHERE id = ?' |
||||
|
) |
||||
|
|
||||
|
try { |
||||
|
let response = query.run(tranchename, montant, id) |
||||
|
|
||||
|
return response |
||||
|
} catch (error) { |
||||
|
return error |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
async function deleteTranche(id) { |
||||
|
const query = database.prepare('DELETE FROM trancheecolage WHERE id = ?') |
||||
|
|
||||
|
try { |
||||
|
let response = query.run(id) |
||||
|
|
||||
|
return response |
||||
|
} catch (error) { |
||||
|
return error |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
async function getSingleTranche(id) { |
||||
|
try { |
||||
|
return await database.prepare('SELECT * FROM trancheecolage WHERE id = ?').get(id) |
||||
|
} catch (error) { |
||||
|
return error |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
module.exports = { |
||||
|
insertEtudiant, |
||||
|
getAllEtudiants, |
||||
|
FilterDataByNiveau, |
||||
|
getSingleEtudiant, |
||||
|
updateEtudiant, |
||||
|
getDataToDashboard, |
||||
|
changePDP, |
||||
|
updateParcours, |
||||
|
createTranche, |
||||
|
getTranche, |
||||
|
updateTranche, |
||||
|
deleteTranche, |
||||
|
getSingleTranche |
||||
|
} |
||||
@ -0,0 +1,354 @@ |
|||||
|
const { database } = require('../database.backup') |
||||
|
const { matiereSysteme } = require('../function/System') |
||||
|
const { convertArrayAndString } = require('../function/StringArrayConvertion') |
||||
|
|
||||
|
/** |
||||
|
* function uset to create matiere |
||||
|
* @param {*} nom |
||||
|
* @returns Promise |
||||
|
*/ |
||||
|
async function createMatiere(nom, credit, uniter, ue) { |
||||
|
const query = database.prepare( |
||||
|
'INSERT INTO matieres (nom, unite_enseignement, credit, heure, ue) VALUES (?, ?, ?, ?, ?)' |
||||
|
) |
||||
|
|
||||
|
const uniterHeure = database.prepare('SELECT uniter_heure FROM nessesaryTable').get() |
||||
|
const heure = credit * uniterHeure.uniter_heure |
||||
|
|
||||
|
try { |
||||
|
response = await query.run(nom, uniter, credit, heure, ue) |
||||
|
|
||||
|
return response |
||||
|
} catch (error) { |
||||
|
return error |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* function to get all matieres |
||||
|
* @returns Promise |
||||
|
*/ |
||||
|
async function getMatiere() { |
||||
|
const query = database.prepare('SELECT * FROM matieres ORDER BY id DESC') |
||||
|
|
||||
|
try { |
||||
|
let response = await query.all() |
||||
|
|
||||
|
return response |
||||
|
} catch (error) { |
||||
|
return error |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
async function displayMatiereFromForm(niveau, mention_id, parcours) { |
||||
|
// Fetch the semestre array
|
||||
|
let semestre = await matiereSysteme(niveau) // Ensure this returns an array with at least 2 items
|
||||
|
|
||||
|
if (niveau !== 'L1') { |
||||
|
if (semestre.length < 2) { |
||||
|
console.error('Error: Semestre array does not contain enough elements.') |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
// Prepare the query
|
||||
|
let 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 |
||||
|
JOIN parcoursmatiere pm ON m.id = pm.matiere_id |
||||
|
JOIN parcours p ON pm.parcour_id = p.id |
||||
|
WHERE (s.nom LIKE ? OR s.nom LIKE ?) |
||||
|
AND ms.mention_id = ? |
||||
|
AND p.nom = ? |
||||
|
`)
|
||||
|
|
||||
|
try { |
||||
|
// Execute the query with parameters
|
||||
|
let response = matiereQuery.all(`%${semestre[0]}%`, `%${semestre[1]}%`, mention_id, parcours) |
||||
|
|
||||
|
console.log(response) |
||||
|
// Log the response
|
||||
|
return response |
||||
|
} catch (error) { |
||||
|
return error |
||||
|
} |
||||
|
} else { |
||||
|
if (semestre.length < 2) { |
||||
|
console.error('Error: Semestre array does not contain enough elements.') |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
// Prepare the query
|
||||
|
let 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 = ? |
||||
|
`)
|
||||
|
|
||||
|
try { |
||||
|
// Execute the query with parameters
|
||||
|
let response = matiereQuery.all(`%${semestre[0]}%`, `%${semestre[1]}%`, mention_id) |
||||
|
console.log(response) |
||||
|
// Log the response
|
||||
|
return response |
||||
|
} catch (error) { |
||||
|
return error |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* function to get single matiere |
||||
|
* @param {*} id |
||||
|
* @returns promise |
||||
|
*/ |
||||
|
async function getSingleMatiere(id) { |
||||
|
const query = await database.prepare('SELECT * FROM matieres WHERE id = ?') |
||||
|
|
||||
|
try { |
||||
|
let response = query.get(id) |
||||
|
|
||||
|
return response |
||||
|
} catch (error) { |
||||
|
return error |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* function used when updating matiere |
||||
|
* @param {*} nom |
||||
|
* @param {*} id |
||||
|
* @returns promise |
||||
|
*/ |
||||
|
async function updateMatiere(nom, id, credit, uniter, ue) { |
||||
|
const query = database.prepare( |
||||
|
'UPDATE matieres SET nom = ?, credit = ?, unite_enseignement = ?, heure = ?, ue = ? WHERE id = ?' |
||||
|
) |
||||
|
|
||||
|
const uniterHeure = await database.prepare('SELECT uniter_heure FROM nessesaryTable').get() |
||||
|
const heure = credit * uniterHeure.uniter_heure |
||||
|
|
||||
|
try { |
||||
|
response = await query.run(nom, credit, uniter, heure, ue, id) |
||||
|
|
||||
|
return response |
||||
|
} catch (error) { |
||||
|
return error |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
async function deleteMatiere(id) { |
||||
|
const query = database.prepare('DELETE FROM matieres WHERE id = ?') |
||||
|
|
||||
|
try { |
||||
|
let response = query.run(id) |
||||
|
|
||||
|
return response |
||||
|
} catch (error) { |
||||
|
return error |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
async function asygnationToMention(formData, id) { |
||||
|
const clearQuery = database.prepare('DELETE FROM matiere_mention WHERE matiere_id = ?') |
||||
|
const query = database.prepare( |
||||
|
'INSERT INTO matiere_mention (matiere_id, mention_id) VALUES (?,?)' |
||||
|
) |
||||
|
const selectedKeys = Object.keys(formData).filter((key) => formData[key]) |
||||
|
const placeholders = selectedKeys.map(() => '?').join(',') |
||||
|
// Prepare the query with placeholders
|
||||
|
const clearSemestreMentionQuery = database.prepare( |
||||
|
`DELETE FROM matiere_semestre WHERE matiere_id = ? AND mention_id NOT IN (${placeholders})` |
||||
|
) |
||||
|
|
||||
|
const clearNoreQuery = database.prepare( |
||||
|
`DELETE FROM notes WHERE matiere_id = ? AND mention_id NOT IN (${placeholders})` |
||||
|
) |
||||
|
|
||||
|
try { |
||||
|
let response |
||||
|
await clearQuery.run(id) |
||||
|
await clearNoreQuery.run(id, ...selectedKeys) |
||||
|
clearSemestreMentionQuery.run(id, ...selectedKeys) |
||||
|
// use transaction for speed execution
|
||||
|
database.transaction(() => { |
||||
|
for (let index = 0; index < selectedKeys.length; index++) { |
||||
|
response = query.run(id, selectedKeys[index]) |
||||
|
} |
||||
|
})() |
||||
|
|
||||
|
return response |
||||
|
} catch (error) { |
||||
|
return error |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
async function getMentionMatiere(id) { |
||||
|
const query = database.prepare('SELECT * FROM matiere_mention WHERE matiere_id = ?') |
||||
|
|
||||
|
try { |
||||
|
let response = await query.all(id) |
||||
|
|
||||
|
return response |
||||
|
} catch (error) { |
||||
|
return error |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
async function getMentionMatiereChecked(matiere_id) { |
||||
|
const getMentionMatiere = database.prepare('SELECT * FROM matiere_mention WHERE matiere_id = ?') |
||||
|
let MentionArray = await getMentionMatiere.all(matiere_id) |
||||
|
let arrayID = [] |
||||
|
|
||||
|
for (let index = 0; index < MentionArray.length; index++) { |
||||
|
arrayID.push(MentionArray[index].mention_id) |
||||
|
} |
||||
|
|
||||
|
const mentionQuery = database.prepare( |
||||
|
`SELECT * FROM mentions WHERE id IN (${arrayID.map(() => '?').join(', ')})` |
||||
|
) |
||||
|
|
||||
|
try { |
||||
|
const results = await mentionQuery.all(...arrayID) |
||||
|
|
||||
|
return results |
||||
|
} catch (error) { |
||||
|
return error |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
async function getSemestreMatiere(id) { |
||||
|
const query = database.prepare('SELECT * FROM matiere_semestre WHERE matiere_id = ?') |
||||
|
|
||||
|
try { |
||||
|
let response = await query.all(id) |
||||
|
|
||||
|
return response |
||||
|
} catch (error) { |
||||
|
return error |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
async function getSemestre() { |
||||
|
const query = database.prepare('SELECT * FROM semestres') |
||||
|
|
||||
|
try { |
||||
|
let response = await query.all() |
||||
|
|
||||
|
return response |
||||
|
} catch (error) { |
||||
|
return error |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
async function insertUpdateMentionSemestre(matiere_id, formData) { |
||||
|
const clearQuery = database.prepare('DELETE FROM matiere_semestre WHERE matiere_id = ?') |
||||
|
clearQuery.run(matiere_id) |
||||
|
|
||||
|
const query = database.prepare( |
||||
|
'INSERT INTO matiere_semestre (matiere_id, semestre_id, mention_id) VALUES (?, ?, ?)' |
||||
|
) |
||||
|
let response |
||||
|
database.transaction(() => { |
||||
|
for (const key in formData) { |
||||
|
if (formData.hasOwnProperty(key)) { |
||||
|
for (let jindex = 0; jindex < formData[key].length; jindex++) { |
||||
|
response = query.run(matiere_id, formData[key][jindex], key) |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
})() |
||||
|
return response |
||||
|
} |
||||
|
|
||||
|
async function getEnseignants() { |
||||
|
const getIdQuery = database.prepare( |
||||
|
'SELECT id FROM matiereEnseignants GROUP BY matiere_id ORDER BY MAX(date) DESC' |
||||
|
) |
||||
|
|
||||
|
const query = database.prepare( |
||||
|
'SELECT * FROM matiereEnseignants WHERE id IN (' + |
||||
|
new Array(getIdQuery.all().length).fill('?').join(',') + |
||||
|
')' |
||||
|
) |
||||
|
|
||||
|
try { |
||||
|
// Get the latest `id` for each `matiere_id`
|
||||
|
const latestIds = getIdQuery.all().map((row) => row.id) |
||||
|
|
||||
|
// If no ids exist, return an empty array
|
||||
|
if (latestIds.length === 0) { |
||||
|
return [] |
||||
|
} |
||||
|
|
||||
|
// Fetch the full details using the filtered IDs
|
||||
|
let response = query.all(...latestIds) |
||||
|
|
||||
|
return response |
||||
|
} catch (error) { |
||||
|
return error |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
async function insertNewProf(matiere_id, nom, prenom, contact, date) { |
||||
|
const query = database.prepare( |
||||
|
'INSERT INTO matiereEnseignants (matiere_id, nom_enseignant, prenom_enseignant, contact, date) VALUES (?, ?, ?, ?, ?)' |
||||
|
) |
||||
|
|
||||
|
try { |
||||
|
let response = query.run(matiere_id, nom, prenom, contact, date) |
||||
|
|
||||
|
return response |
||||
|
} catch (error) { |
||||
|
return error |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
async function getSIngleProf(id) { |
||||
|
try { |
||||
|
const prof = await database |
||||
|
.prepare('SELECT * FROM matiereEnseignants WHERE matiere_id = ?') |
||||
|
.get(id) |
||||
|
|
||||
|
return prof |
||||
|
} catch (error) { |
||||
|
return error |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
async function updateProf(matiere_id, nom, prenom, contact, date) { |
||||
|
const query = database.prepare( |
||||
|
'UPDATE matiereEnseignants SET nom_enseignant = ?, prenom_enseignant = ?, contact = ?, date = ? WHERE matiere_id = ?' |
||||
|
) |
||||
|
|
||||
|
try { |
||||
|
let response = query.run(nom, prenom, contact, date, matiere_id) |
||||
|
|
||||
|
return response |
||||
|
} catch (error) { |
||||
|
return error |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
module.exports = { |
||||
|
createMatiere, |
||||
|
getSIngleProf, |
||||
|
getMatiere, |
||||
|
getSingleMatiere, |
||||
|
updateMatiere, |
||||
|
displayMatiereFromForm, |
||||
|
deleteMatiere, |
||||
|
asygnationToMention, |
||||
|
getMentionMatiere, |
||||
|
getMentionMatiereChecked, |
||||
|
getSemestreMatiere, |
||||
|
getSemestre, |
||||
|
insertUpdateMentionSemestre, |
||||
|
getEnseignants, |
||||
|
insertNewProf, |
||||
|
updateProf |
||||
|
} |
||||
@ -0,0 +1,149 @@ |
|||||
|
const { database } = require('../database') |
||||
|
const bcrypt = require('bcryptjs') |
||||
|
|
||||
|
// Function to insert a user into the database
|
||||
|
async function insertUser(username, email, password, roles) { |
||||
|
const saltRounds = 10 |
||||
|
|
||||
|
try { |
||||
|
// Await the bcrypt hashing to complete before proceeding
|
||||
|
const hashedPassword = await bcrypt.hash(password, saltRounds) |
||||
|
|
||||
|
// Prepare and run the insert query using the hashed password
|
||||
|
const insertUserQuery = database.prepare( |
||||
|
'INSERT INTO users (username, email, password, roles) VALUES (?, ?, ?, ?)' |
||||
|
) |
||||
|
const insertedUser = await insertUserQuery.run(username, email, hashedPassword, roles) |
||||
|
|
||||
|
return insertedUser |
||||
|
} catch (err) { |
||||
|
return err |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// Function to fetch all users from the database
|
||||
|
async function getAllUsers() { |
||||
|
const getUsersQuery = database.prepare('SELECT * FROM users') |
||||
|
let response = await getUsersQuery.all() |
||||
|
|
||||
|
return response |
||||
|
} |
||||
|
|
||||
|
// Function to login a user
|
||||
|
async function loginUser(username, password) { |
||||
|
// Prepare the query to get the user by username
|
||||
|
const loginUserQuery = database.prepare('SELECT * FROM users WHERE LOWER(username) = ?') |
||||
|
|
||||
|
try { |
||||
|
// Execute the query and get the user from the database
|
||||
|
const user = await loginUserQuery.get(username.toLowerCase()) |
||||
|
|
||||
|
if (user) { |
||||
|
// Use bcrypt to compare the provided password with the stored hashed password
|
||||
|
const isPasswordValid = await bcrypt.compare(password, user.password) |
||||
|
|
||||
|
if (isPasswordValid) { |
||||
|
// If password matches, return the user
|
||||
|
return user |
||||
|
} else { |
||||
|
// If password does not match
|
||||
|
console.log('Invalid password') |
||||
|
} |
||||
|
} else { |
||||
|
// If no user is found with the provided username
|
||||
|
console.log('User not found') |
||||
|
} |
||||
|
} catch (err) { |
||||
|
console.error('Error during login:', err) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* function to use in forgit password |
||||
|
* |
||||
|
* @param {*} email |
||||
|
* @param {*} password |
||||
|
* @param {*} passwordConfirmation |
||||
|
* @returns |
||||
|
*/ |
||||
|
async function forgotPassword(email, password, passwordConfirmation) { |
||||
|
const saltRounds = 10 |
||||
|
const forgotPasswordQuery = database.prepare('SELECT * FROM users WHERE email = ?') |
||||
|
|
||||
|
if (password == passwordConfirmation) { |
||||
|
const user = await forgotPasswordQuery.get(email) |
||||
|
|
||||
|
if (user) { |
||||
|
const updateQuery = database.prepare('UPDATE users SET password = ? WHERE email = ?') |
||||
|
const hashedPassword = await bcrypt.hash(password, saltRounds) |
||||
|
|
||||
|
try { |
||||
|
await updateQuery.run(hashedPassword, email) |
||||
|
|
||||
|
return { message: 'Mot de passe modifier avec succes', status: 200 } |
||||
|
} catch (error) { |
||||
|
console.error('Error updating password:', error) |
||||
|
} |
||||
|
} else { |
||||
|
return { message: 'Email non trouver', status: 404 } |
||||
|
} |
||||
|
} else { |
||||
|
return { message: 'Mot de passe ne correspond pas', status: 401 } |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* function to use when updatign the users |
||||
|
* |
||||
|
* @param {*} username |
||||
|
* @param {*} email |
||||
|
* @param {*} password |
||||
|
* @param {*} id |
||||
|
* @returns promise |
||||
|
*/ |
||||
|
async function updateUser(username, email, password, id) { |
||||
|
const saltRounds = 10 |
||||
|
|
||||
|
try { |
||||
|
let query |
||||
|
let response |
||||
|
|
||||
|
if (password === '') { |
||||
|
// Update without changing the password
|
||||
|
if (username === '' && email !== '') { |
||||
|
query = database.prepare('UPDATE users SET email = ? WHERE id = ?') |
||||
|
response = await query.run(email, id) |
||||
|
} else if (email === '' && username !== '') { |
||||
|
query = database.prepare('UPDATE users SET username = ? WHERE id = ?') |
||||
|
response = await query.run(username, id) |
||||
|
} else if (username !== '' && email !== '') { |
||||
|
query = database.prepare('UPDATE users SET username = ?, email = ? WHERE id = ?') |
||||
|
response = await query.run(username, email, id) |
||||
|
} |
||||
|
} else { |
||||
|
// Update with a new hashed password
|
||||
|
const hashedPassword = await bcrypt.hash(password, saltRounds) |
||||
|
query = database.prepare( |
||||
|
'UPDATE users SET username = ?, email = ?, password = ? WHERE id = ?' |
||||
|
) |
||||
|
response = await query.run(username, email, hashedPassword, id) |
||||
|
} |
||||
|
|
||||
|
// Fetch the updated user after the update
|
||||
|
const getUserQuery = database.prepare('SELECT * FROM users WHERE id = ?') |
||||
|
const updatedUser = await getUserQuery.get(id) |
||||
|
|
||||
|
return updatedUser // Return the updated user
|
||||
|
} catch (error) { |
||||
|
console.error('Error updating user:', error) |
||||
|
throw error // Throw error to handle it in calling function if needed
|
||||
|
} |
||||
|
} |
||||
|
|
||||
|
module.exports = { |
||||
|
getAllUsers, |
||||
|
insertUser, |
||||
|
loginUser, |
||||
|
forgotPassword, |
||||
|
updateUser |
||||
|
} |
||||
@ -1,149 +1,177 @@ |
|||||
const { database } = require('../database') |
const { pool } = require('../database') |
||||
const bcrypt = require('bcryptjs') |
const bcrypt = require('bcryptjs') |
||||
|
|
||||
// Function to insert a user into the database
|
/** |
||||
|
* function to insert new user |
||||
|
* @param {String} username |
||||
|
* @param {String} email |
||||
|
* @param {String} password |
||||
|
* @param {String} roles |
||||
|
* @returns {Object} |
||||
|
*/ |
||||
async function insertUser(username, email, password, roles) { |
async function insertUser(username, email, password, roles) { |
||||
const saltRounds = 10 |
const saltRound = 10 |
||||
|
|
||||
try { |
try { |
||||
// Await the bcrypt hashing to complete before proceeding
|
const hashedPassword = await bcrypt.hash(password, saltRound) |
||||
const hashedPassword = await bcrypt.hash(password, saltRounds) |
|
||||
|
|
||||
// Prepare and run the insert query using the hashed password
|
const sql = ` |
||||
const insertUserQuery = database.prepare( |
INSERT INTO users (username, email, password, roles) VALUES (?, ?, ?, ?) |
||||
'INSERT INTO users (username, email, password, roles) VALUES (?, ?, ?, ?)' |
` |
||||
) |
const [result] = await pool.query(sql, [username, email, hashedPassword, roles]) |
||||
const insertedUser = await insertUserQuery.run(username, email, hashedPassword, roles) |
|
||||
|
|
||||
return insertedUser |
// result.insertId contains the new user ID
|
||||
} catch (err) { |
return { |
||||
return err |
success: true, |
||||
|
id: result.insertId |
||||
|
} |
||||
|
} catch (error) { |
||||
|
return { success: false, error: error } |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
// Function to fetch all users from the database
|
/** |
||||
|
* function to get all users |
||||
|
* @returns {Array} |
||||
|
*/ |
||||
async function getAllUsers() { |
async function getAllUsers() { |
||||
const getUsersQuery = database.prepare('SELECT * FROM users') |
const sql = `SELECT * FROM users` |
||||
let response = await getUsersQuery.all() |
|
||||
|
try { |
||||
|
const [rows] = await pool.query(sql) |
||||
|
|
||||
|
return rows |
||||
|
} catch (error) { |
||||
|
return 'failled to get users' |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* function to get one users |
||||
|
* @param {Number} id |
||||
|
* @returns {Object} |
||||
|
*/ |
||||
|
async function getUserById(id) { |
||||
|
const sql = `SELECT * FROM users WHERE id = ?` |
||||
|
const [rows] = await pool.query(sql, [id]) |
||||
|
|
||||
return response |
if (rows.length > 0) { |
||||
|
return rows[0] |
||||
|
} else { |
||||
|
return null |
||||
|
} |
||||
} |
} |
||||
|
|
||||
// Function to login a user
|
/** |
||||
async function loginUser(username, password) { |
* function used when users try to log in |
||||
// Prepare the query to get the user by username
|
* @param {String} username |
||||
const loginUserQuery = database.prepare('SELECT * FROM users WHERE LOWER(username) = ?') |
* @param {String} password |
||||
|
* @returns {Object} |
||||
|
*/ |
||||
|
async function loginUsers(username, password) { |
||||
|
const sql = `SELECT * FROM users WHERE LOWER(username) = ?` |
||||
|
|
||||
try { |
try { |
||||
// Execute the query and get the user from the database
|
const [rows] = await pool.query(sql, [username.toLowerCase()]) |
||||
const user = await loginUserQuery.get(username.toLowerCase()) |
|
||||
|
|
||||
if (user) { |
|
||||
// Use bcrypt to compare the provided password with the stored hashed password
|
|
||||
const isPasswordValid = await bcrypt.compare(password, user.password) |
|
||||
|
|
||||
if (isPasswordValid) { |
if (rows.length === 0) { |
||||
// If password matches, return the user
|
return { success: false, error: 'Utilisateur inexistant' } |
||||
return user |
|
||||
} else { |
|
||||
// If password does not match
|
|
||||
console.log('Invalid password') |
|
||||
} |
} |
||||
} else { |
|
||||
// If no user is found with the provided username
|
const user = rows[0] |
||||
console.log('User not found') |
|
||||
|
// compare the password
|
||||
|
const passwordMatch = await bcrypt.compare(password, user.password) |
||||
|
|
||||
|
if (!passwordMatch) { |
||||
|
return { success: false, error: 'Mot de passe incorrect' } |
||||
} |
} |
||||
} catch (err) { |
|
||||
console.error('Error during login:', err) |
// delete the key password before return a user object
|
||||
|
delete user.password |
||||
|
|
||||
|
return { success: true, user } |
||||
|
} catch (error) { |
||||
|
return { error: 'erreur lors du login' } |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
/** |
/** |
||||
* function to use in forgit password |
* function to update users |
||||
* |
* @param {String} username |
||||
* @param {*} email |
* @param {String} email |
||||
* @param {*} password |
* @param {String} password |
||||
* @param {*} passwordConfirmation |
* @param {String} roles |
||||
* @returns |
* @param {Number} id |
||||
|
* @returns {Object} |
||||
*/ |
*/ |
||||
async function forgotPassword(email, password, passwordConfirmation) { |
async function updateUser(username, email, password, roles, id) { |
||||
const saltRounds = 10 |
let sql, params |
||||
const forgotPasswordQuery = database.prepare('SELECT * FROM users WHERE email = ?') |
|
||||
|
|
||||
if (password == passwordConfirmation) { |
if (password !== null) { |
||||
const user = await forgotPasswordQuery.get(email) |
const hashedPassword = await bcrypt.hash(password, 10) |
||||
|
sql = `UPDATE users SET username = ?, email = ?, password = ?, roles = ? WHERE id = ?` |
||||
if (user) { |
params = [username, email, hashedPassword, roles, id] |
||||
const updateQuery = database.prepare('UPDATE users SET password = ? WHERE email = ?') |
} else { |
||||
const hashedPassword = await bcrypt.hash(password, saltRounds) |
sql = `UPDATE users SET username = ?, email = ?, roles = ? WHERE id = ?` |
||||
|
params = [username, email, roles, id] |
||||
|
} |
||||
|
|
||||
try { |
try { |
||||
await updateQuery.run(hashedPassword, email) |
const [result] = await pool.query(sql, params) |
||||
|
|
||||
return { message: 'Mot de passe modifier avec succes', status: 200 } |
if (result.affectedRows === 0) { |
||||
} catch (error) { |
return { |
||||
console.error('Error updating password:', error) |
success: false, |
||||
|
message: 'Utilisateur non trouvé ou aucune modification effectuée.' |
||||
} |
} |
||||
} else { |
|
||||
return { message: 'Email non trouver', status: 404 } |
|
||||
} |
} |
||||
} else { |
|
||||
return { message: 'Mot de passe ne correspond pas', status: 401 } |
return { |
||||
|
success: true, |
||||
|
message: 'Utilisateur mis à jour avec succès.' |
||||
|
} |
||||
|
} catch (error) { |
||||
|
return { success: false, error: 'Erreur veullez réeseyer' } |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
/** |
/** |
||||
* function to use when updatign the users |
* function to delete users |
||||
* |
* @param {Number} id |
||||
* @param {*} username |
* @returns {Object} |
||||
* @param {*} email |
|
||||
* @param {*} password |
|
||||
* @param {*} id |
|
||||
* @returns promise |
|
||||
*/ |
*/ |
||||
async function updateUser(username, email, password, id) { |
async function deleteUser(id) { |
||||
const saltRounds = 10 |
const sql = `DELETE FROM users WHERE id = ?` |
||||
|
|
||||
try { |
try { |
||||
let query |
const [result] = await pool.query(sql, [id]) |
||||
let response |
|
||||
|
if (result.affectedRows === 0) { |
||||
if (password === '') { |
return { |
||||
// Update without changing the password
|
success: false, |
||||
if (username === '' && email !== '') { |
message: 'Utilisateur non trouvé.' |
||||
query = database.prepare('UPDATE users SET email = ? WHERE id = ?') |
|
||||
response = await query.run(email, id) |
|
||||
} else if (email === '' && username !== '') { |
|
||||
query = database.prepare('UPDATE users SET username = ? WHERE id = ?') |
|
||||
response = await query.run(username, id) |
|
||||
} else if (username !== '' && email !== '') { |
|
||||
query = database.prepare('UPDATE users SET username = ?, email = ? WHERE id = ?') |
|
||||
response = await query.run(username, email, id) |
|
||||
} |
} |
||||
} else { |
|
||||
// Update with a new hashed password
|
|
||||
const hashedPassword = await bcrypt.hash(password, saltRounds) |
|
||||
query = database.prepare( |
|
||||
'UPDATE users SET username = ?, email = ?, password = ? WHERE id = ?' |
|
||||
) |
|
||||
response = await query.run(username, email, hashedPassword, id) |
|
||||
} |
} |
||||
|
|
||||
// Fetch the updated user after the update
|
return { |
||||
const getUserQuery = database.prepare('SELECT * FROM users WHERE id = ?') |
success: true, |
||||
const updatedUser = await getUserQuery.get(id) |
message: 'Utilisateur supprimé avec succès.' |
||||
|
} |
||||
return updatedUser // Return the updated user
|
|
||||
} catch (error) { |
} catch (error) { |
||||
console.error('Error updating user:', error) |
console.error(error) |
||||
throw error // Throw error to handle it in calling function if needed
|
return { |
||||
|
success: false, |
||||
|
error: 'Erreur lors de la suppression, veuillez réessayer.' |
||||
|
} |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
module.exports = { |
module.exports = { |
||||
getAllUsers, |
|
||||
insertUser, |
insertUser, |
||||
loginUser, |
getAllUsers, |
||||
forgotPassword, |
getUserById, |
||||
updateUser |
loginUsers, |
||||
|
updateUser, |
||||
|
deleteUser |
||||
} |
} |
||||
|
|||||
@ -0,0 +1,444 @@ |
|||||
|
const sqlite = require('better-sqlite3') |
||||
|
const bcrypt = require('bcryptjs') |
||||
|
|
||||
|
|
||||
|
// Construct the database path using the detected IP
|
||||
|
let dbPath = `./base/data.db`; |
||||
|
|
||||
|
// Connect to SQLite database with the initial path
|
||||
|
let database = new sqlite(dbPath); |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
// Create the users table if it doesn't exist
|
||||
|
const createUserTableQuery = ` |
||||
|
CREATE TABLE IF NOT EXISTS users ( |
||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |
||||
|
username VARCHAR(200) NOT NULL, |
||||
|
email VARCHAR(250) NOT NULL UNIQUE, |
||||
|
password TEXT NOT NULL, |
||||
|
roles VARCHAR(250) NOT NULL, |
||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP |
||||
|
); |
||||
|
` |
||||
|
database.prepare(createUserTableQuery).run() |
||||
|
|
||||
|
// Insert a default admin user if not exists
|
||||
|
const insertDefaultUserQuery = ` |
||||
|
INSERT INTO users (username, email, password, roles) |
||||
|
SELECT 'admin', 'admin@example.com', ?, 'admin' |
||||
|
WHERE NOT EXISTS (SELECT 1 FROM users WHERE username = 'admin'); |
||||
|
` |
||||
|
|
||||
|
// Hash the password '1234' before storing
|
||||
|
const hashedPassword = bcrypt.hashSync('123456789', 10) |
||||
|
database.prepare(insertDefaultUserQuery).run(hashedPassword) |
||||
|
|
||||
|
// create table for note status
|
||||
|
const createStatusTableQuery = ` |
||||
|
CREATE TABLE IF NOT EXISTS status ( |
||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |
||||
|
nom VARCHAR(200) NOT NULL, |
||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP |
||||
|
); |
||||
|
` |
||||
|
database.prepare(createStatusTableQuery).run() |
||||
|
|
||||
|
// create table for mention
|
||||
|
const createMentionTableQuery = ` |
||||
|
CREATE TABLE IF NOT EXISTS mentions ( |
||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |
||||
|
nom VARCHAR(250) NOT NULL, |
||||
|
uniter VARCHAR(50) NOT NULL, -- Abréviation du nom |
||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP |
||||
|
); |
||||
|
` |
||||
|
database.prepare(createMentionTableQuery).run() |
||||
|
|
||||
|
// Create the niveau table if it doesn't exist
|
||||
|
const createNiveauTableQuery = ` |
||||
|
CREATE TABLE IF NOT EXISTS niveaus ( |
||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |
||||
|
nom VARCHAR(50) NOT NULL, -- Exemple: L1, L2, L3, etc. |
||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP |
||||
|
); |
||||
|
` |
||||
|
database.prepare(createNiveauTableQuery).run() |
||||
|
|
||||
|
// Create the etudiants table if it doesn't exist
|
||||
|
const createEtudiantsTableQuery = ` |
||||
|
CREATE TABLE IF NOT EXISTS etudiants ( |
||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |
||||
|
nom VARCHAR(250) DEFAULT NULL, |
||||
|
prenom VARCHAR(250) DEFAULT NULL, |
||||
|
photos TEXT DEFAULT NULL, |
||||
|
date_de_naissances DATE DEFAULT NULL, |
||||
|
niveau VARCHAR(250) NOT NULL, -- Clé étrangère vers niveaus |
||||
|
annee_scolaire VARCHAR(20) NOT NULL, |
||||
|
status INTEGER DEFAULT NULL, |
||||
|
mention_id INTEGER NOT NULL, -- Clé étrangère vers mentions |
||||
|
num_inscription TEXT NOT NULL, |
||||
|
sexe VARCHAR(20) DEFAULT NULL, |
||||
|
cin VARCHAR(250) DEFAULT NULL, |
||||
|
date_delivrance DEFAULT NULL, |
||||
|
nationalite DATE DEFAULT NULL, |
||||
|
annee_bacc DATE DEFAULT NULL, |
||||
|
serie VARCHAR(20) DEFAULT NULL, |
||||
|
boursier BOOLEAN DEFAULT FALSE, |
||||
|
domaine VARCHAR(250) DEFAULT NULL, |
||||
|
contact VARCHAR(20) DEFAULT NULL, |
||||
|
parcours VARCHAR(250) DEFAULT NULL, |
||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
|
FOREIGN KEY (status) REFERENCES status(id), |
||||
|
FOREIGN KEY (mention_id) REFERENCES mentions(id) |
||||
|
); |
||||
|
` |
||||
|
database.prepare(createEtudiantsTableQuery).run() |
||||
|
|
||||
|
// Create the notes table if it doesn't exist
|
||||
|
const createMatiereTableQuery = ` |
||||
|
CREATE TABLE IF NOT EXISTS matieres ( |
||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |
||||
|
nom VARCHAR(250) UNIQUE NOT NULL, |
||||
|
unite_enseignement VARCHAR(250) NOT NULL, |
||||
|
credit INTEGER NOT NULL, |
||||
|
heure INTEGER NOT NULL, |
||||
|
ue VARCHAR(10) NOT NULL, |
||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP |
||||
|
); |
||||
|
` |
||||
|
database.prepare(createMatiereTableQuery).run() |
||||
|
|
||||
|
// Create the semestre table if it doesn't exist
|
||||
|
const createSemestreTableQuery = ` |
||||
|
CREATE TABLE IF NOT EXISTS semestres ( |
||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |
||||
|
nom VARCHAR(30) NOT NULL, -- Exemple: S1, S2, S3, etc. |
||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP |
||||
|
); |
||||
|
` |
||||
|
database.prepare(createSemestreTableQuery).run() |
||||
|
|
||||
|
// Create the semestre table if it doesn't exist
|
||||
|
const createMatiere_mentionTableQuery = ` |
||||
|
CREATE TABLE IF NOT EXISTS matiere_mention ( |
||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |
||||
|
matiere_id INTEGER NOT NULL, -- Clé étrangère vers matieres |
||||
|
mention_id INTEGER NOT NULL, -- Clé étrangère vers mentions |
||||
|
FOREIGN KEY (matiere_id) REFERENCES matieres(id), |
||||
|
FOREIGN KEY (mention_id) REFERENCES mentions(id) |
||||
|
); |
||||
|
` |
||||
|
database.prepare(createMatiere_mentionTableQuery).run() |
||||
|
|
||||
|
const createMatiere_semestreTableQuery = ` |
||||
|
CREATE TABLE IF NOT EXISTS matiere_semestre ( |
||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |
||||
|
matiere_id INTEGER NOT NULL, -- Clé étrangère vers matieres |
||||
|
semestre_id INTEGER NOT NULL, -- Clé étrangère vers semestres |
||||
|
mention_id INTEGER NOT NULL, -- Clé étrangère vers niveaus |
||||
|
FOREIGN KEY (matiere_id) REFERENCES matieres(id), |
||||
|
FOREIGN KEY (semestre_id) REFERENCES semestres(id), |
||||
|
FOREIGN KEY (mention_id) REFERENCES mentions(id) |
||||
|
); |
||||
|
` |
||||
|
database.prepare(createMatiere_semestreTableQuery).run() |
||||
|
|
||||
|
// Create the notes table if it doesn't exist
|
||||
|
const createNoteTableQuery = ` |
||||
|
CREATE TABLE IF NOT EXISTS notes ( |
||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |
||||
|
etudiant_id INTEGER NOT NULL, -- Clé étrangère vers etudiants |
||||
|
matiere_id INTEGER NOT NULL, -- Clé étrangère vers matieres |
||||
|
etudiant_niveau VARCHAR(50) NOT NULL, |
||||
|
mention_id INTEGER NOT NULL, |
||||
|
note FLOAT DEFAULT NULL, |
||||
|
annee_scolaire VARCHAR(50) NOT NULL, |
||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
|
FOREIGN KEY (etudiant_id) REFERENCES etudiants(id), |
||||
|
FOREIGN KEY (matiere_id) REFERENCES matieres(id) |
||||
|
FOREIGN KEY (mention_id) REFERENCES mentions(id) |
||||
|
); |
||||
|
` |
||||
|
database.prepare(createNoteTableQuery).run() |
||||
|
|
||||
|
// Create the notes second session table if it doesn't exist
|
||||
|
const createNoteRepechTableQuery = ` |
||||
|
CREATE TABLE IF NOT EXISTS notesrepech ( |
||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |
||||
|
etudiant_id INTEGER NOT NULL, -- Clé étrangère vers etudiants |
||||
|
matiere_id INTEGER NOT NULL, -- Clé étrangère vers matieres |
||||
|
etudiant_niveau VARCHAR(50) NOT NULL, |
||||
|
mention_id INTEGER NOT NULL, |
||||
|
note FLOAT DEFAULT NULL, |
||||
|
annee_scolaire VARCHAR(50) NOT NULL, |
||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
|
FOREIGN KEY (etudiant_id) REFERENCES etudiants(id), |
||||
|
FOREIGN KEY (matiere_id) REFERENCES matieres(id) |
||||
|
FOREIGN KEY (mention_id) REFERENCES mentions(id) |
||||
|
); |
||||
|
` |
||||
|
database.prepare(createNoteRepechTableQuery).run() |
||||
|
|
||||
|
// create table for note système
|
||||
|
const createNoteSystemeTableQuery = ` |
||||
|
CREATE TABLE IF NOT EXISTS notesystems ( |
||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |
||||
|
admis FLOAT NOT NULL DEFAULT 10, |
||||
|
redouble FLOAT NOT NULL DEFAULT 9.99, |
||||
|
renvoyer FLOAT NOT NULL DEFAULT 7.99, |
||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP |
||||
|
); |
||||
|
` |
||||
|
database.prepare(createNoteSystemeTableQuery).run() |
||||
|
|
||||
|
// create table année scolaire
|
||||
|
const createAnneeScolaireTableQuery = ` |
||||
|
CREATE TABLE IF NOT EXISTS anneescolaire ( |
||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |
||||
|
code VARCHAR(30) NOT NULL, |
||||
|
debut DATE NOT NULL, |
||||
|
fin DATE NOT NULL, |
||||
|
is_current INTEGER DEFAULT 0, |
||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP |
||||
|
); |
||||
|
` |
||||
|
database.prepare(createAnneeScolaireTableQuery).run() |
||||
|
|
||||
|
// create traitement systeme
|
||||
|
const createTraitementSystemQuery = ` |
||||
|
CREATE TABLE IF NOT EXISTS traitmentsystem ( |
||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |
||||
|
code VARCHAR(30) NOT NULL, |
||||
|
debut DATE NOT NULL, |
||||
|
fin DATE NOT NULL, |
||||
|
is_finished INTEGER DEFAULT 0, |
||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP |
||||
|
); |
||||
|
` |
||||
|
database.prepare(createTraitementSystemQuery).run() |
||||
|
|
||||
|
const createNecessaryParameterTableQuery = ` |
||||
|
CREATE TABLE IF NOT EXISTS nessesaryTable ( |
||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |
||||
|
uniter_heure INTEGER NOT NULL, |
||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP |
||||
|
); |
||||
|
` |
||||
|
database.prepare(createNecessaryParameterTableQuery).run() |
||||
|
|
||||
|
const createMatiereEnseignantTableQuery = ` |
||||
|
CREATE TABLE IF NOT EXISTS matiereEnseignants ( |
||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |
||||
|
matiere_id INTEGER NOT NULL, |
||||
|
nom_enseignant VARCHAR(250) NOT NULL, |
||||
|
prenom_enseignant VARCHAR(250) NOT NULL, |
||||
|
contact VARCHAR(11) NOT NULL, |
||||
|
date DATE NOT NULL, |
||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
|
FOREIGN KEY (matiere_id) REFERENCES matieres(id) |
||||
|
); |
||||
|
` |
||||
|
database.prepare(createMatiereEnseignantTableQuery).run() |
||||
|
|
||||
|
const createParcourTableQuery = ` |
||||
|
CREATE TABLE IF NOT EXISTS parcours ( |
||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |
||||
|
nom VARCHAR(250) NOT NULL, |
||||
|
uniter VARCHAR(250) NOT NULL, |
||||
|
mention_id INTEGER DEFAULT NULL, -- Clé étrangère vers mentions |
||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP |
||||
|
); |
||||
|
` |
||||
|
database.prepare(createParcourTableQuery).run() |
||||
|
|
||||
|
const createParcourSemestreTableQuery = ` |
||||
|
CREATE TABLE IF NOT EXISTS parcoursmatiere ( |
||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |
||||
|
matiere_id INTEGER NOT NULL, |
||||
|
parcour_id INTEGER NOT NULL, |
||||
|
FOREIGN KEY (matiere_id) REFERENCES matieres(id), |
||||
|
FOREIGN KEY (parcour_id) REFERENCES parcours(id) |
||||
|
); |
||||
|
` |
||||
|
database.prepare(createParcourSemestreTableQuery).run() |
||||
|
|
||||
|
const createTableEcolageQuery = ` |
||||
|
CREATE TABLE IF NOT EXISTS trancheecolage ( |
||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |
||||
|
etudiant_id INTEGER NOT NULL, |
||||
|
tranchename VARCHAR(255) NOT NULL, |
||||
|
montant DOUBLE NOT NULL |
||||
|
); |
||||
|
` |
||||
|
database.prepare(createTableEcolageQuery).run() |
||||
|
|
||||
|
const createTableStoreIP = ` |
||||
|
CREATE TABLE IF NOT EXISTS ipconfig ( |
||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |
||||
|
ipname VARCHAR(255) NOT NULL |
||||
|
); |
||||
|
`;
|
||||
|
database.prepare(createTableStoreIP).run() |
||||
|
|
||||
|
// -------------------------------------- function pre-excuter --------------------------------------------
|
||||
|
|
||||
|
async function insertStatusesIfNotExist() { |
||||
|
// Préparation des requêtes
|
||||
|
const checkStatusQuery = database.prepare(` |
||||
|
SELECT COUNT(*) AS count FROM status WHERE nom = ?; |
||||
|
`)
|
||||
|
const insertStatusQuery = database.prepare(` |
||||
|
INSERT INTO status (nom) VALUES (?); |
||||
|
`)
|
||||
|
|
||||
|
// Tableau des statuts à vérifier/insérer
|
||||
|
const arrayStatus = ['Nouveau', 'Passant', 'Redoublant', 'Renvoyé', 'Ancien'] |
||||
|
|
||||
|
for (let index = 0; index < arrayStatus.length; index++) { |
||||
|
const statusName = arrayStatus[index] |
||||
|
|
||||
|
// Vérification si le statut existe déjà
|
||||
|
const result = checkStatusQuery.get(statusName) |
||||
|
|
||||
|
// Si le statut n'existe pas, on l'insère
|
||||
|
if (result.count === 0) { |
||||
|
insertStatusQuery.run(statusName) |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
// execute the function
|
||||
|
insertStatusesIfNotExist() |
||||
|
|
||||
|
async function insertDefaultNoteSystemIfNotExist() { |
||||
|
// Préparation de la requête pour vérifier si une entrée existe déjà
|
||||
|
const checkNoteSystemQuery = database.prepare(` |
||||
|
SELECT COUNT(*) AS count FROM notesystems; |
||||
|
`)
|
||||
|
|
||||
|
// Préparation de la requête pour insérer une entrée par défaut
|
||||
|
const insertNoteSystemQuery = database.prepare(` |
||||
|
INSERT INTO notesystems (admis, redouble, renvoyer) |
||||
|
VALUES (?, ?, ?); |
||||
|
`)
|
||||
|
|
||||
|
// Valeurs par défaut à insérer
|
||||
|
const defaultValues = { |
||||
|
admis: 10.0, |
||||
|
redouble: 9.99, |
||||
|
renvoyer: 7.99 |
||||
|
} |
||||
|
|
||||
|
// Vérification si une entrée existe déjà
|
||||
|
const result = checkNoteSystemQuery.get() |
||||
|
|
||||
|
if (result.count === 0) { |
||||
|
// Insérer les valeurs par défaut si aucune entrée n'existe
|
||||
|
insertNoteSystemQuery.run(defaultValues.admis, defaultValues.redouble, defaultValues.renvoyer) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
insertDefaultNoteSystemIfNotExist() |
||||
|
|
||||
|
async function semestreCreate() { |
||||
|
const query = database.prepare('INSERT INTO semestres (nom) VALUES (?)') |
||||
|
// Préparation de la requête pour vérifier si une entrée existe déjà
|
||||
|
const checkSemestreQuery = database.prepare(` |
||||
|
SELECT COUNT(*) AS count FROM semestres; |
||||
|
`)
|
||||
|
|
||||
|
try { |
||||
|
let arraySemestre = [ |
||||
|
'S1', |
||||
|
'S2', |
||||
|
'S3', |
||||
|
'S4', |
||||
|
'S5', |
||||
|
'S6', |
||||
|
'S7', |
||||
|
'S8', |
||||
|
'S9', |
||||
|
'S10', |
||||
|
'S11', |
||||
|
'S12', |
||||
|
'S13', |
||||
|
'S14', |
||||
|
'S14', |
||||
|
'S16' |
||||
|
] |
||||
|
// Vérification si une entrée existe déjà
|
||||
|
const result = checkSemestreQuery.get() |
||||
|
|
||||
|
if (result.count === 0) { |
||||
|
database.transaction(() => { |
||||
|
for (let index = 0; index < arraySemestre.length; index++) { |
||||
|
query.run(arraySemestre[index]) |
||||
|
} |
||||
|
})() |
||||
|
} |
||||
|
} catch (error) { |
||||
|
console.log(error) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
const createNecessaryParameterTable = () => { |
||||
|
// Check if the table is empty
|
||||
|
const rowCount = database.prepare(`SELECT COUNT(*) AS count FROM nessesaryTable`).get().count |
||||
|
|
||||
|
// If the table is empty, insert the default value
|
||||
|
if (rowCount === 0) { |
||||
|
const insertDefaultQuery = ` |
||||
|
INSERT INTO nessesaryTable (uniter_heure) VALUES (15); |
||||
|
` |
||||
|
database.prepare(insertDefaultQuery).run() |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// Call the function when the app runs
|
||||
|
createNecessaryParameterTable() |
||||
|
|
||||
|
semestreCreate() |
||||
|
|
||||
|
// Function to get the IP from the database
|
||||
|
function getIP() { |
||||
|
const data = database.prepare("SELECT * FROM ipconfig WHERE id = 1").get(); |
||||
|
|
||||
|
if (data) { |
||||
|
return data.ipname; |
||||
|
} else { |
||||
|
return null; // Explicitly return `null` if no data is found
|
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// Get the new IP from the database
|
||||
|
let newIP = getIP(); |
||||
|
|
||||
|
if (newIP) { |
||||
|
// Construct the database path using the new IP from the database
|
||||
|
dbPath = `\\\\${newIP}\\base\\data.db`; |
||||
|
|
||||
|
// Reconnect to SQLite database with the updated path
|
||||
|
database = new sqlite(dbPath); // Re-initialize database connection with new path
|
||||
|
console.log("now COnnect to the ", dbPath); |
||||
|
} |
||||
|
|
||||
|
module.exports = { |
||||
|
database |
||||
|
} |
||||
@ -1,444 +1,307 @@ |
|||||
const sqlite = require('better-sqlite3') |
const mysql = require('mysql2/promise') |
||||
const bcrypt = require('bcryptjs') |
const bcrypt = require('bcryptjs') |
||||
|
|
||||
|
const pool = mysql.createPool({ |
||||
|
host: '127.0.0.1', |
||||
|
user: 'root', |
||||
|
password: '', |
||||
|
database: 'university', |
||||
|
waitForConnections: true, |
||||
|
connectionLimit: 10, |
||||
|
queueLimit: 0 |
||||
|
}) |
||||
|
|
||||
// Construct the database path using the detected IP
|
async function createTables() { |
||||
let dbPath = `./base/data.db`; |
const connection = await pool.getConnection() |
||||
|
|
||||
// Connect to SQLite database with the initial path
|
try { |
||||
let database = new sqlite(dbPath); |
// Users table
|
||||
|
await connection.query(` |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
// Create the users table if it doesn't exist
|
|
||||
const createUserTableQuery = ` |
|
||||
CREATE TABLE IF NOT EXISTS users ( |
CREATE TABLE IF NOT EXISTS users ( |
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |
id INT AUTO_INCREMENT PRIMARY KEY, |
||||
username VARCHAR(200) NOT NULL, |
username VARCHAR(200) NOT NULL, |
||||
email VARCHAR(250) NOT NULL UNIQUE, |
email VARCHAR(250) NOT NULL UNIQUE, |
||||
password TEXT NOT NULL, |
password TEXT NOT NULL, |
||||
roles VARCHAR(250) NOT NULL, |
roles VARCHAR(250) NOT NULL, |
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP |
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP |
||||
); |
) ENGINE=InnoDB; |
||||
` |
`)
|
||||
database.prepare(createUserTableQuery).run() |
|
||||
|
|
||||
// Insert a default admin user if not exists
|
|
||||
const insertDefaultUserQuery = ` |
|
||||
INSERT INTO users (username, email, password, roles) |
|
||||
SELECT 'admin', 'admin@example.com', ?, 'admin' |
|
||||
WHERE NOT EXISTS (SELECT 1 FROM users WHERE username = 'admin'); |
|
||||
` |
|
||||
|
|
||||
// Hash the password '1234' before storing
|
|
||||
const hashedPassword = bcrypt.hashSync('123456789', 10) |
|
||||
database.prepare(insertDefaultUserQuery).run(hashedPassword) |
|
||||
|
|
||||
// create table for note status
|
// Status table
|
||||
const createStatusTableQuery = ` |
await connection.query(` |
||||
CREATE TABLE IF NOT EXISTS status ( |
CREATE TABLE IF NOT EXISTS status ( |
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |
id INT AUTO_INCREMENT PRIMARY KEY, |
||||
nom VARCHAR(200) NOT NULL, |
nom VARCHAR(200) NOT NULL, |
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP |
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP |
||||
); |
) ENGINE=InnoDB; |
||||
` |
`)
|
||||
database.prepare(createStatusTableQuery).run() |
|
||||
|
|
||||
// create table for mention
|
// Mentions table
|
||||
const createMentionTableQuery = ` |
await connection.query(` |
||||
CREATE TABLE IF NOT EXISTS mentions ( |
CREATE TABLE IF NOT EXISTS mentions ( |
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |
id INT AUTO_INCREMENT PRIMARY KEY, |
||||
nom VARCHAR(250) NOT NULL, |
nom VARCHAR(250) NOT NULL, |
||||
uniter VARCHAR(50) NOT NULL, -- Abréviation du nom |
uniter VARCHAR(50) NOT NULL, |
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP |
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP |
||||
); |
) ENGINE=InnoDB; |
||||
` |
`)
|
||||
database.prepare(createMentionTableQuery).run() |
|
||||
|
|
||||
// Create the niveau table if it doesn't exist
|
await connection.query(` |
||||
const createNiveauTableQuery = ` |
|
||||
CREATE TABLE IF NOT EXISTS niveaus ( |
CREATE TABLE IF NOT EXISTS niveaus ( |
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |
id INT AUTO_INCREMENT PRIMARY KEY, |
||||
nom VARCHAR(50) NOT NULL, -- Exemple: L1, L2, L3, etc. |
nom VARCHAR(50) UNIQUE NOT NULL, |
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP |
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP |
||||
); |
) ENGINE=InnoDB; |
||||
` |
`)
|
||||
database.prepare(createNiveauTableQuery).run() |
|
||||
|
|
||||
// Create the etudiants table if it doesn't exist
|
await connection.query(` |
||||
const createEtudiantsTableQuery = ` |
|
||||
CREATE TABLE IF NOT EXISTS etudiants ( |
CREATE TABLE IF NOT EXISTS etudiants ( |
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |
id INT AUTO_INCREMENT PRIMARY KEY, |
||||
nom VARCHAR(250) DEFAULT NULL, |
nom VARCHAR(250) DEFAULT NULL, |
||||
prenom VARCHAR(250) DEFAULT NULL, |
prenom VARCHAR(250) DEFAULT NULL, |
||||
photos TEXT DEFAULT NULL, |
photos TEXT DEFAULT NULL, |
||||
date_de_naissances DATE DEFAULT NULL, |
date_de_naissances DATE DEFAULT NULL, |
||||
niveau VARCHAR(250) NOT NULL, -- Clé étrangère vers niveaus |
niveau VARCHAR(250) NOT NULL, |
||||
annee_scolaire VARCHAR(20) NOT NULL, |
annee_scolaire VARCHAR(20) NOT NULL, |
||||
status INTEGER DEFAULT NULL, |
status INT DEFAULT NULL, |
||||
mention_id INTEGER NOT NULL, -- Clé étrangère vers mentions |
mention_id INT NOT NULL, |
||||
num_inscription TEXT 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 DEFAULT NULL, |
date_delivrance DATE DEFAULT NULL, |
||||
nationalite DATE DEFAULT NULL, |
nationalite DATE DEFAULT NULL, |
||||
annee_bacc DATE DEFAULT NULL, |
annee_bacc DATE DEFAULT NULL, |
||||
serie VARCHAR(20) DEFAULT NULL, |
serie VARCHAR(20) DEFAULT NULL, |
||||
boursier BOOLEAN DEFAULT FALSE, |
boursier TINYINT(1) DEFAULT 0, |
||||
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, |
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
||||
FOREIGN KEY (status) REFERENCES status(id), |
FOREIGN KEY (status) REFERENCES status(id), |
||||
FOREIGN KEY (mention_id) REFERENCES mentions(id) |
FOREIGN KEY (mention_id) REFERENCES mentions(id) |
||||
); |
) ENGINE=InnoDB; |
||||
` |
`)
|
||||
database.prepare(createEtudiantsTableQuery).run() |
|
||||
|
|
||||
// Create the notes table if it doesn't exist
|
await connection.query(` |
||||
const createMatiereTableQuery = ` |
|
||||
CREATE TABLE IF NOT EXISTS matieres ( |
CREATE TABLE IF NOT EXISTS matieres ( |
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |
id INT AUTO_INCREMENT PRIMARY KEY, |
||||
nom VARCHAR(250) UNIQUE NOT NULL, |
nom VARCHAR(250) UNIQUE NOT NULL, |
||||
unite_enseignement VARCHAR(250) NOT NULL, |
unite_enseignement VARCHAR(250) NOT NULL, |
||||
credit INTEGER NOT NULL, |
credit INT NOT NULL, |
||||
heure INTEGER NOT NULL, |
heure INT NOT NULL, |
||||
ue VARCHAR(10) NOT NULL, |
ue VARCHAR(10) NOT NULL, |
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP |
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP |
||||
); |
) ENGINE=InnoDB; |
||||
` |
`)
|
||||
database.prepare(createMatiereTableQuery).run() |
|
||||
|
|
||||
// Create the semestre table if it doesn't exist
|
await connection.query(` |
||||
const createSemestreTableQuery = ` |
|
||||
CREATE TABLE IF NOT EXISTS semestres ( |
CREATE TABLE IF NOT EXISTS semestres ( |
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |
id INT AUTO_INCREMENT PRIMARY KEY, |
||||
nom VARCHAR(30) NOT NULL, -- Exemple: S1, S2, S3, etc. |
nom VARCHAR(30) NOT NULL, |
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP |
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP |
||||
); |
) ENGINE=InnoDB; |
||||
` |
`)
|
||||
database.prepare(createSemestreTableQuery).run() |
|
||||
|
|
||||
// Create the semestre table if it doesn't exist
|
await connection.query(` |
||||
const createMatiere_mentionTableQuery = ` |
|
||||
CREATE TABLE IF NOT EXISTS matiere_mention ( |
CREATE TABLE IF NOT EXISTS matiere_mention ( |
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |
id INT AUTO_INCREMENT PRIMARY KEY, |
||||
matiere_id INTEGER NOT NULL, -- Clé étrangère vers matieres |
matiere_id INT NOT NULL, |
||||
mention_id INTEGER NOT NULL, -- Clé étrangère vers mentions |
mention_id INT NOT NULL, |
||||
FOREIGN KEY (matiere_id) REFERENCES matieres(id), |
FOREIGN KEY (matiere_id) REFERENCES matieres(id), |
||||
FOREIGN KEY (mention_id) REFERENCES mentions(id) |
FOREIGN KEY (mention_id) REFERENCES mentions(id) |
||||
); |
) ENGINE=InnoDB; |
||||
` |
`)
|
||||
database.prepare(createMatiere_mentionTableQuery).run() |
|
||||
|
|
||||
const createMatiere_semestreTableQuery = ` |
await connection.query(` |
||||
CREATE TABLE IF NOT EXISTS matiere_semestre ( |
CREATE TABLE IF NOT EXISTS matiere_semestre ( |
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |
id INT AUTO_INCREMENT PRIMARY KEY, |
||||
matiere_id INTEGER NOT NULL, -- Clé étrangère vers matieres |
matiere_id INT NOT NULL, |
||||
semestre_id INTEGER NOT NULL, -- Clé étrangère vers semestres |
semestre_id INT NOT NULL, |
||||
mention_id INTEGER NOT NULL, -- Clé étrangère vers niveaus |
mention_id INT NOT NULL, |
||||
FOREIGN KEY (matiere_id) REFERENCES matieres(id), |
FOREIGN KEY (matiere_id) REFERENCES matieres(id), |
||||
FOREIGN KEY (semestre_id) REFERENCES semestres(id), |
FOREIGN KEY (semestre_id) REFERENCES semestres(id), |
||||
FOREIGN KEY (mention_id) REFERENCES mentions(id) |
FOREIGN KEY (mention_id) REFERENCES mentions(id) |
||||
); |
) ENGINE=InnoDB; |
||||
` |
`)
|
||||
database.prepare(createMatiere_semestreTableQuery).run() |
|
||||
|
|
||||
// Create the notes table if it doesn't exist
|
await connection.query(` |
||||
const createNoteTableQuery = ` |
|
||||
CREATE TABLE IF NOT EXISTS notes ( |
CREATE TABLE IF NOT EXISTS notes ( |
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |
id INT AUTO_INCREMENT PRIMARY KEY, |
||||
etudiant_id INTEGER NOT NULL, -- Clé étrangère vers etudiants |
etudiant_id INT NOT NULL, |
||||
matiere_id INTEGER NOT NULL, -- Clé étrangère vers matieres |
matiere_id INT NOT NULL, |
||||
etudiant_niveau VARCHAR(50) NOT NULL, |
etudiant_niveau VARCHAR(50) NOT NULL, |
||||
mention_id INTEGER NOT NULL, |
mention_id INT NOT NULL, |
||||
note FLOAT DEFAULT NULL, |
note FLOAT DEFAULT NULL, |
||||
annee_scolaire VARCHAR(50) NOT NULL, |
annee_scolaire VARCHAR(50) NOT NULL, |
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
||||
FOREIGN KEY (etudiant_id) REFERENCES etudiants(id), |
FOREIGN KEY (etudiant_id) REFERENCES etudiants(id), |
||||
FOREIGN KEY (matiere_id) REFERENCES matieres(id) |
FOREIGN KEY (matiere_id) REFERENCES matieres(id), |
||||
FOREIGN KEY (mention_id) REFERENCES mentions(id) |
FOREIGN KEY (mention_id) REFERENCES mentions(id) |
||||
); |
) ENGINE=InnoDB; |
||||
` |
`)
|
||||
database.prepare(createNoteTableQuery).run() |
|
||||
|
|
||||
// Create the notes second session table if it doesn't exist
|
await connection.query(` |
||||
const createNoteRepechTableQuery = ` |
|
||||
CREATE TABLE IF NOT EXISTS notesrepech ( |
CREATE TABLE IF NOT EXISTS notesrepech ( |
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |
id INT AUTO_INCREMENT PRIMARY KEY, |
||||
etudiant_id INTEGER NOT NULL, -- Clé étrangère vers etudiants |
etudiant_id INT NOT NULL, |
||||
matiere_id INTEGER NOT NULL, -- Clé étrangère vers matieres |
matiere_id INT NOT NULL, |
||||
etudiant_niveau VARCHAR(50) NOT NULL, |
etudiant_niveau VARCHAR(50) NOT NULL, |
||||
mention_id INTEGER NOT NULL, |
mention_id INT NOT NULL, |
||||
note FLOAT DEFAULT NULL, |
note FLOAT DEFAULT NULL, |
||||
annee_scolaire VARCHAR(50) NOT NULL, |
annee_scolaire VARCHAR(50) NOT NULL, |
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
||||
FOREIGN KEY (etudiant_id) REFERENCES etudiants(id), |
FOREIGN KEY (etudiant_id) REFERENCES etudiants(id), |
||||
FOREIGN KEY (matiere_id) REFERENCES matieres(id) |
FOREIGN KEY (matiere_id) REFERENCES matieres(id), |
||||
FOREIGN KEY (mention_id) REFERENCES mentions(id) |
FOREIGN KEY (mention_id) REFERENCES mentions(id) |
||||
); |
) ENGINE=InnoDB; |
||||
` |
`)
|
||||
database.prepare(createNoteRepechTableQuery).run() |
|
||||
|
|
||||
// create table for note système
|
await connection.query(` |
||||
const createNoteSystemeTableQuery = ` |
|
||||
CREATE TABLE IF NOT EXISTS notesystems ( |
CREATE TABLE IF NOT EXISTS notesystems ( |
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |
id INT AUTO_INCREMENT PRIMARY KEY, |
||||
admis FLOAT NOT NULL DEFAULT 10, |
admis FLOAT NOT NULL DEFAULT 10, |
||||
redouble FLOAT NOT NULL DEFAULT 9.99, |
redouble FLOAT NOT NULL DEFAULT 9.99, |
||||
renvoyer FLOAT NOT NULL DEFAULT 7.99, |
renvoyer FLOAT NOT NULL DEFAULT 7.99, |
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP |
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP |
||||
); |
) ENGINE=InnoDB; |
||||
` |
`)
|
||||
database.prepare(createNoteSystemeTableQuery).run() |
|
||||
|
|
||||
// create table année scolaire
|
await connection.query(` |
||||
const createAnneeScolaireTableQuery = ` |
|
||||
CREATE TABLE IF NOT EXISTS anneescolaire ( |
CREATE TABLE IF NOT EXISTS anneescolaire ( |
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |
id INT AUTO_INCREMENT PRIMARY KEY, |
||||
code VARCHAR(30) NOT NULL, |
code VARCHAR(30) NOT NULL, |
||||
debut DATE NOT NULL, |
debut DATE NOT NULL, |
||||
fin DATE NOT NULL, |
fin DATE NOT NULL, |
||||
is_current INTEGER DEFAULT 0, |
is_current TINYINT(1) DEFAULT 0, |
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP |
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP |
||||
); |
) ENGINE=InnoDB; |
||||
` |
`)
|
||||
database.prepare(createAnneeScolaireTableQuery).run() |
|
||||
|
|
||||
// create traitement systeme
|
await connection.query(` |
||||
const createTraitementSystemQuery = ` |
|
||||
CREATE TABLE IF NOT EXISTS traitmentsystem ( |
CREATE TABLE IF NOT EXISTS traitmentsystem ( |
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |
id INT AUTO_INCREMENT PRIMARY KEY, |
||||
code VARCHAR(30) NOT NULL, |
code VARCHAR(30) NOT NULL, |
||||
debut DATE NOT NULL, |
debut DATE NOT NULL, |
||||
fin DATE NOT NULL, |
fin DATE NOT NULL, |
||||
is_finished INTEGER DEFAULT 0, |
is_finished TINYINT(1) DEFAULT 0, |
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP |
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP |
||||
); |
) ENGINE=InnoDB; |
||||
` |
`)
|
||||
database.prepare(createTraitementSystemQuery).run() |
|
||||
|
|
||||
const createNecessaryParameterTableQuery = ` |
await connection.query(` |
||||
CREATE TABLE IF NOT EXISTS nessesaryTable ( |
CREATE TABLE IF NOT EXISTS nessesaryTable ( |
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |
id INT AUTO_INCREMENT PRIMARY KEY, |
||||
uniter_heure INTEGER NOT NULL, |
uniter_heure INT NOT NULL, |
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP |
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP |
||||
); |
) ENGINE=InnoDB; |
||||
` |
`)
|
||||
database.prepare(createNecessaryParameterTableQuery).run() |
|
||||
|
|
||||
const createMatiereEnseignantTableQuery = ` |
await connection.query(` |
||||
CREATE TABLE IF NOT EXISTS matiereEnseignants ( |
CREATE TABLE IF NOT EXISTS matiereEnseignants ( |
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |
id INT AUTO_INCREMENT PRIMARY KEY, |
||||
matiere_id INTEGER NOT NULL, |
matiere_id INT NOT NULL, |
||||
nom_enseignant VARCHAR(250) NOT NULL, |
nom_enseignant VARCHAR(250) NOT NULL, |
||||
prenom_enseignant VARCHAR(250) NOT NULL, |
prenom_enseignant VARCHAR(250) NOT NULL, |
||||
contact VARCHAR(11) NOT NULL, |
contact VARCHAR(11) NOT NULL, |
||||
date DATE NOT NULL, |
date DATE NOT NULL, |
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
||||
FOREIGN KEY (matiere_id) REFERENCES matieres(id) |
FOREIGN KEY (matiere_id) REFERENCES matieres(id) |
||||
); |
) ENGINE=InnoDB; |
||||
` |
`)
|
||||
database.prepare(createMatiereEnseignantTableQuery).run() |
|
||||
|
|
||||
const createParcourTableQuery = ` |
await connection.query(` |
||||
CREATE TABLE IF NOT EXISTS parcours ( |
CREATE TABLE IF NOT EXISTS parcours ( |
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |
id INT AUTO_INCREMENT PRIMARY KEY, |
||||
nom VARCHAR(250) NOT NULL, |
nom VARCHAR(250) NOT NULL, |
||||
uniter VARCHAR(250) NOT NULL, |
uniter VARCHAR(250) NOT NULL, |
||||
mention_id INTEGER DEFAULT NULL, -- Clé étrangère vers mentions |
mention_id INT DEFAULT NULL, |
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP |
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP |
||||
); |
) ENGINE=InnoDB; |
||||
` |
`)
|
||||
database.prepare(createParcourTableQuery).run() |
|
||||
|
|
||||
const createParcourSemestreTableQuery = ` |
await connection.query(` |
||||
CREATE TABLE IF NOT EXISTS parcoursmatiere ( |
CREATE TABLE IF NOT EXISTS parcoursmatiere ( |
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |
id INT AUTO_INCREMENT PRIMARY KEY, |
||||
matiere_id INTEGER NOT NULL, |
matiere_id INT NOT NULL, |
||||
parcour_id INTEGER NOT NULL, |
parcour_id INT NOT NULL, |
||||
FOREIGN KEY (matiere_id) REFERENCES matieres(id), |
FOREIGN KEY (matiere_id) REFERENCES matieres(id), |
||||
FOREIGN KEY (parcour_id) REFERENCES parcours(id) |
FOREIGN KEY (parcour_id) REFERENCES parcours(id) |
||||
); |
) ENGINE=InnoDB; |
||||
` |
`)
|
||||
database.prepare(createParcourSemestreTableQuery).run() |
|
||||
|
|
||||
const createTableEcolageQuery = ` |
await connection.query(` |
||||
CREATE TABLE IF NOT EXISTS trancheecolage ( |
CREATE TABLE IF NOT EXISTS trancheecolage ( |
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |
id INT AUTO_INCREMENT PRIMARY KEY, |
||||
etudiant_id INTEGER NOT NULL, |
etudiant_id INT NOT NULL, |
||||
tranchename VARCHAR(255) NOT NULL, |
tranchename VARCHAR(255) NOT NULL, |
||||
montant DOUBLE NOT NULL |
montant DOUBLE NOT NULL |
||||
); |
) ENGINE=InnoDB; |
||||
` |
`)
|
||||
database.prepare(createTableEcolageQuery).run() |
|
||||
|
|
||||
const createTableStoreIP = ` |
await connection.query(` |
||||
CREATE TABLE IF NOT EXISTS ipconfig ( |
CREATE TABLE IF NOT EXISTS ipconfig ( |
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |
id INT AUTO_INCREMENT PRIMARY KEY, |
||||
ipname VARCHAR(255) NOT NULL |
ipname VARCHAR(255) NOT NULL |
||||
); |
) ENGINE=InnoDB; |
||||
`;
|
|
||||
database.prepare(createTableStoreIP).run() |
|
||||
|
|
||||
// -------------------------------------- function pre-excuter --------------------------------------------
|
|
||||
|
|
||||
async function insertStatusesIfNotExist() { |
|
||||
// Préparation des requêtes
|
|
||||
const checkStatusQuery = database.prepare(` |
|
||||
SELECT COUNT(*) AS count FROM status WHERE nom = ?; |
|
||||
`)
|
`)
|
||||
const insertStatusQuery = database.prepare(` |
} finally { |
||||
INSERT INTO status (nom) VALUES (?); |
connection.release() |
||||
`)
|
|
||||
|
|
||||
// Tableau des statuts à vérifier/insérer
|
|
||||
const arrayStatus = ['Nouveau', 'Passant', 'Redoublant', 'Renvoyé', 'Ancien'] |
|
||||
|
|
||||
for (let index = 0; index < arrayStatus.length; index++) { |
|
||||
const statusName = arrayStatus[index] |
|
||||
|
|
||||
// Vérification si le statut existe déjà
|
|
||||
const result = checkStatusQuery.get(statusName) |
|
||||
|
|
||||
// Si le statut n'existe pas, on l'insère
|
|
||||
if (result.count === 0) { |
|
||||
insertStatusQuery.run(statusName) |
|
||||
} |
|
||||
} |
} |
||||
} |
} |
||||
// execute the function
|
|
||||
insertStatusesIfNotExist() |
|
||||
|
|
||||
async function insertDefaultNoteSystemIfNotExist() { |
|
||||
// Préparation de la requête pour vérifier si une entrée existe déjà
|
|
||||
const checkNoteSystemQuery = database.prepare(` |
|
||||
SELECT COUNT(*) AS count FROM notesystems; |
|
||||
`)
|
|
||||
|
|
||||
// Préparation de la requête pour insérer une entrée par défaut
|
|
||||
const insertNoteSystemQuery = database.prepare(` |
|
||||
INSERT INTO notesystems (admis, redouble, renvoyer) |
|
||||
VALUES (?, ?, ?); |
|
||||
`)
|
|
||||
|
|
||||
// Valeurs par défaut à insérer
|
async function insertDefaultAdmin() { |
||||
const defaultValues = { |
const conn = await pool.getConnection() |
||||
admis: 10.0, |
try { |
||||
redouble: 9.99, |
const [rows] = await conn.query(`SELECT COUNT(*) as count FROM users WHERE username = ?`, [ |
||||
renvoyer: 7.99 |
'admin' |
||||
|
]) |
||||
|
if (rows[0].count === 0) { |
||||
|
const hashedPassword = bcrypt.hashSync('123456789', 10) |
||||
|
await conn.query( |
||||
|
` |
||||
|
INSERT INTO users (username, email, password, roles) |
||||
|
VALUES (?, ?, ?, ?)`,
|
||||
|
['admin', 'admin@example.com', hashedPassword, 'admin'] |
||||
|
) |
||||
} |
} |
||||
|
} finally { |
||||
// Vérification si une entrée existe déjà
|
conn.release() |
||||
const result = checkNoteSystemQuery.get() |
|
||||
|
|
||||
if (result.count === 0) { |
|
||||
// Insérer les valeurs par défaut si aucune entrée n'existe
|
|
||||
insertNoteSystemQuery.run(defaultValues.admis, defaultValues.redouble, defaultValues.renvoyer) |
|
||||
} |
} |
||||
} |
} |
||||
|
|
||||
insertDefaultNoteSystemIfNotExist() |
async function insertStatusesIfNotExist() { |
||||
|
const conn = await pool.getConnection() |
||||
async function semestreCreate() { |
|
||||
const query = database.prepare('INSERT INTO semestres (nom) VALUES (?)') |
|
||||
// Préparation de la requête pour vérifier si une entrée existe déjà
|
|
||||
const checkSemestreQuery = database.prepare(` |
|
||||
SELECT COUNT(*) AS count FROM semestres; |
|
||||
`)
|
|
||||
|
|
||||
try { |
try { |
||||
let arraySemestre = [ |
const statuses = ['Nouveau', 'Passant', 'Redoublant', 'Renvoyé', 'Ancien'] |
||||
'S1', |
for (let name of statuses) { |
||||
'S2', |
const [rows] = await conn.query(`SELECT COUNT(*) as count FROM status WHERE nom = ?`, [name]) |
||||
'S3', |
if (rows[0].count === 0) { |
||||
'S4', |
await conn.query(`INSERT INTO status (nom) VALUES (?)`, [name]) |
||||
'S5', |
|
||||
'S6', |
|
||||
'S7', |
|
||||
'S8', |
|
||||
'S9', |
|
||||
'S10', |
|
||||
'S11', |
|
||||
'S12', |
|
||||
'S13', |
|
||||
'S14', |
|
||||
'S14', |
|
||||
'S16' |
|
||||
] |
|
||||
// Vérification si une entrée existe déjà
|
|
||||
const result = checkSemestreQuery.get() |
|
||||
|
|
||||
if (result.count === 0) { |
|
||||
database.transaction(() => { |
|
||||
for (let index = 0; index < arraySemestre.length; index++) { |
|
||||
query.run(arraySemestre[index]) |
|
||||
} |
} |
||||
})() |
|
||||
} |
} |
||||
} catch (error) { |
} finally { |
||||
console.log(error) |
conn.release() |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
const createNecessaryParameterTable = () => { |
|
||||
// Check if the table is empty
|
|
||||
const rowCount = database.prepare(`SELECT COUNT(*) AS count FROM nessesaryTable`).get().count |
|
||||
|
|
||||
// If the table is empty, insert the default value
|
|
||||
if (rowCount === 0) { |
|
||||
const insertDefaultQuery = ` |
|
||||
INSERT INTO nessesaryTable (uniter_heure) VALUES (15); |
|
||||
` |
|
||||
database.prepare(insertDefaultQuery).run() |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
// Call the function when the app runs
|
|
||||
createNecessaryParameterTable() |
|
||||
|
|
||||
semestreCreate() |
|
||||
|
|
||||
// Function to get the IP from the database
|
|
||||
function getIP() { |
|
||||
const data = database.prepare("SELECT * FROM ipconfig WHERE id = 1").get(); |
|
||||
|
|
||||
if (data) { |
|
||||
return data.ipname; |
|
||||
} else { |
|
||||
return null; // Explicitly return `null` if no data is found
|
|
||||
} |
|
||||
} |
|
||||
|
|
||||
// Get the new IP from the database
|
|
||||
let newIP = getIP(); |
|
||||
|
|
||||
if (newIP) { |
|
||||
// Construct the database path using the new IP from the database
|
|
||||
dbPath = `\\\\${newIP}\\base\\data.db`; |
|
||||
|
|
||||
// Reconnect to SQLite database with the updated path
|
|
||||
database = new sqlite(dbPath); // Re-initialize database connection with new path
|
|
||||
console.log("now COnnect to the ", dbPath); |
|
||||
} |
|
||||
|
|
||||
module.exports = { |
module.exports = { |
||||
database |
pool, |
||||
|
createTables, |
||||
|
insertDefaultAdmin, |
||||
|
insertStatusesIfNotExist |
||||
} |
} |
||||
|
|||||
@ -0,0 +1,307 @@ |
|||||
|
const mysql = require('mysql2/promise') |
||||
|
const bcrypt = require('bcryptjs') |
||||
|
|
||||
|
const pool = mysql.createPool({ |
||||
|
host: '127.0.0.1', |
||||
|
user: 'root', |
||||
|
password: '', |
||||
|
database: 'university', |
||||
|
waitForConnections: true, |
||||
|
connectionLimit: 10, |
||||
|
queueLimit: 0 |
||||
|
}) |
||||
|
|
||||
|
async function createTables() { |
||||
|
const connection = await pool.getConnection() |
||||
|
|
||||
|
try { |
||||
|
// Users table
|
||||
|
await connection.query(` |
||||
|
CREATE TABLE IF NOT EXISTS users ( |
||||
|
id INT AUTO_INCREMENT PRIMARY KEY, |
||||
|
username VARCHAR(200) NOT NULL, |
||||
|
email VARCHAR(250) NOT NULL UNIQUE, |
||||
|
password TEXT NOT NULL, |
||||
|
roles VARCHAR(250) NOT NULL, |
||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP |
||||
|
) ENGINE=InnoDB; |
||||
|
`)
|
||||
|
|
||||
|
// Status table
|
||||
|
await connection.query(` |
||||
|
CREATE TABLE IF NOT EXISTS status ( |
||||
|
id INT AUTO_INCREMENT PRIMARY KEY, |
||||
|
nom VARCHAR(200) NOT NULL, |
||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP |
||||
|
) ENGINE=InnoDB; |
||||
|
`)
|
||||
|
|
||||
|
// Mentions table
|
||||
|
await connection.query(` |
||||
|
CREATE TABLE IF NOT EXISTS mentions ( |
||||
|
id INT AUTO_INCREMENT PRIMARY KEY, |
||||
|
nom VARCHAR(250) NOT NULL, |
||||
|
uniter VARCHAR(50) NOT NULL, |
||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP |
||||
|
) ENGINE=InnoDB; |
||||
|
`)
|
||||
|
|
||||
|
await connection.query(` |
||||
|
CREATE TABLE IF NOT EXISTS niveaus ( |
||||
|
id INT AUTO_INCREMENT PRIMARY KEY, |
||||
|
nom VARCHAR(50) NOT NULL, |
||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP |
||||
|
) ENGINE=InnoDB; |
||||
|
`)
|
||||
|
|
||||
|
await connection.query(` |
||||
|
CREATE TABLE IF NOT EXISTS etudiants ( |
||||
|
id INT AUTO_INCREMENT PRIMARY KEY, |
||||
|
nom VARCHAR(250) DEFAULT NULL, |
||||
|
prenom VARCHAR(250) DEFAULT NULL, |
||||
|
photos TEXT DEFAULT NULL, |
||||
|
date_de_naissances DATE DEFAULT NULL, |
||||
|
niveau VARCHAR(250) NOT NULL, |
||||
|
annee_scolaire VARCHAR(20) NOT NULL, |
||||
|
status INT DEFAULT NULL, |
||||
|
mention_id INT NOT NULL, |
||||
|
num_inscription TEXT NOT NULL, |
||||
|
sexe VARCHAR(20) DEFAULT NULL, |
||||
|
cin VARCHAR(250) DEFAULT NULL, |
||||
|
date_delivrance DATE DEFAULT NULL, |
||||
|
nationalite DATE DEFAULT NULL, |
||||
|
annee_bacc DATE DEFAULT NULL, |
||||
|
serie VARCHAR(20) DEFAULT NULL, |
||||
|
boursier TINYINT(1) DEFAULT 0, |
||||
|
domaine VARCHAR(250) DEFAULT NULL, |
||||
|
contact VARCHAR(20) DEFAULT NULL, |
||||
|
parcours VARCHAR(250) DEFAULT NULL, |
||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
||||
|
FOREIGN KEY (status) REFERENCES status(id), |
||||
|
FOREIGN KEY (mention_id) REFERENCES mentions(id) |
||||
|
) ENGINE=InnoDB; |
||||
|
`)
|
||||
|
|
||||
|
await connection.query(` |
||||
|
CREATE TABLE IF NOT EXISTS matieres ( |
||||
|
id INT AUTO_INCREMENT PRIMARY KEY, |
||||
|
nom VARCHAR(250) UNIQUE NOT NULL, |
||||
|
unite_enseignement VARCHAR(250) NOT NULL, |
||||
|
credit INT NOT NULL, |
||||
|
heure INT NOT NULL, |
||||
|
ue VARCHAR(10) NOT NULL, |
||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP |
||||
|
) ENGINE=InnoDB; |
||||
|
`)
|
||||
|
|
||||
|
await connection.query(` |
||||
|
CREATE TABLE IF NOT EXISTS semestres ( |
||||
|
id INT AUTO_INCREMENT PRIMARY KEY, |
||||
|
nom VARCHAR(30) NOT NULL, |
||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP |
||||
|
) ENGINE=InnoDB; |
||||
|
`)
|
||||
|
|
||||
|
await connection.query(` |
||||
|
CREATE TABLE IF NOT EXISTS matiere_mention ( |
||||
|
id INT AUTO_INCREMENT PRIMARY KEY, |
||||
|
matiere_id INT NOT NULL, |
||||
|
mention_id INT NOT NULL, |
||||
|
FOREIGN KEY (matiere_id) REFERENCES matieres(id), |
||||
|
FOREIGN KEY (mention_id) REFERENCES mentions(id) |
||||
|
) ENGINE=InnoDB; |
||||
|
`)
|
||||
|
|
||||
|
await connection.query(` |
||||
|
CREATE TABLE IF NOT EXISTS matiere_semestre ( |
||||
|
id INT AUTO_INCREMENT PRIMARY KEY, |
||||
|
matiere_id INT NOT NULL, |
||||
|
semestre_id INT NOT NULL, |
||||
|
mention_id INT NOT NULL, |
||||
|
FOREIGN KEY (matiere_id) REFERENCES matieres(id), |
||||
|
FOREIGN KEY (semestre_id) REFERENCES semestres(id), |
||||
|
FOREIGN KEY (mention_id) REFERENCES mentions(id) |
||||
|
) ENGINE=InnoDB; |
||||
|
`)
|
||||
|
|
||||
|
await connection.query(` |
||||
|
CREATE TABLE IF NOT EXISTS notes ( |
||||
|
id INT AUTO_INCREMENT PRIMARY KEY, |
||||
|
etudiant_id INT NOT NULL, |
||||
|
matiere_id INT NOT NULL, |
||||
|
etudiant_niveau VARCHAR(50) NOT NULL, |
||||
|
mention_id INT NOT NULL, |
||||
|
note FLOAT DEFAULT NULL, |
||||
|
annee_scolaire VARCHAR(50) NOT NULL, |
||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
||||
|
FOREIGN KEY (etudiant_id) REFERENCES etudiants(id), |
||||
|
FOREIGN KEY (matiere_id) REFERENCES matieres(id), |
||||
|
FOREIGN KEY (mention_id) REFERENCES mentions(id) |
||||
|
) ENGINE=InnoDB; |
||||
|
`)
|
||||
|
|
||||
|
await connection.query(` |
||||
|
CREATE TABLE IF NOT EXISTS notesrepech ( |
||||
|
id INT AUTO_INCREMENT PRIMARY KEY, |
||||
|
etudiant_id INT NOT NULL, |
||||
|
matiere_id INT NOT NULL, |
||||
|
etudiant_niveau VARCHAR(50) NOT NULL, |
||||
|
mention_id INT NOT NULL, |
||||
|
note FLOAT DEFAULT NULL, |
||||
|
annee_scolaire VARCHAR(50) NOT NULL, |
||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
||||
|
FOREIGN KEY (etudiant_id) REFERENCES etudiants(id), |
||||
|
FOREIGN KEY (matiere_id) REFERENCES matieres(id), |
||||
|
FOREIGN KEY (mention_id) REFERENCES mentions(id) |
||||
|
) ENGINE=InnoDB; |
||||
|
`)
|
||||
|
|
||||
|
await connection.query(` |
||||
|
CREATE TABLE IF NOT EXISTS notesystems ( |
||||
|
id INT AUTO_INCREMENT PRIMARY KEY, |
||||
|
admis FLOAT NOT NULL DEFAULT 10, |
||||
|
redouble FLOAT NOT NULL DEFAULT 9.99, |
||||
|
renvoyer FLOAT NOT NULL DEFAULT 7.99, |
||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP |
||||
|
) ENGINE=InnoDB; |
||||
|
`)
|
||||
|
|
||||
|
await connection.query(` |
||||
|
CREATE TABLE IF NOT EXISTS anneescolaire ( |
||||
|
id INT AUTO_INCREMENT PRIMARY KEY, |
||||
|
code VARCHAR(30) NOT NULL, |
||||
|
debut DATE NOT NULL, |
||||
|
fin DATE NOT NULL, |
||||
|
is_current TINYINT(1) DEFAULT 0, |
||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP |
||||
|
) ENGINE=InnoDB; |
||||
|
`)
|
||||
|
|
||||
|
await connection.query(` |
||||
|
CREATE TABLE IF NOT EXISTS traitmentsystem ( |
||||
|
id INT AUTO_INCREMENT PRIMARY KEY, |
||||
|
code VARCHAR(30) NOT NULL, |
||||
|
debut DATE NOT NULL, |
||||
|
fin DATE NOT NULL, |
||||
|
is_finished TINYINT(1) DEFAULT 0, |
||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP |
||||
|
) ENGINE=InnoDB; |
||||
|
`)
|
||||
|
|
||||
|
await connection.query(` |
||||
|
CREATE TABLE IF NOT EXISTS nessesaryTable ( |
||||
|
id INT AUTO_INCREMENT PRIMARY KEY, |
||||
|
uniter_heure INT NOT NULL, |
||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP |
||||
|
) ENGINE=InnoDB; |
||||
|
`)
|
||||
|
|
||||
|
await connection.query(` |
||||
|
CREATE TABLE IF NOT EXISTS matiereEnseignants ( |
||||
|
id INT AUTO_INCREMENT PRIMARY KEY, |
||||
|
matiere_id INT NOT NULL, |
||||
|
nom_enseignant VARCHAR(250) NOT NULL, |
||||
|
prenom_enseignant VARCHAR(250) NOT NULL, |
||||
|
contact VARCHAR(11) NOT NULL, |
||||
|
date DATE NOT NULL, |
||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
||||
|
FOREIGN KEY (matiere_id) REFERENCES matieres(id) |
||||
|
) ENGINE=InnoDB; |
||||
|
`)
|
||||
|
|
||||
|
await connection.query(` |
||||
|
CREATE TABLE IF NOT EXISTS parcours ( |
||||
|
id INT AUTO_INCREMENT PRIMARY KEY, |
||||
|
nom VARCHAR(250) NOT NULL, |
||||
|
uniter VARCHAR(250) NOT NULL, |
||||
|
mention_id INT DEFAULT NULL, |
||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP |
||||
|
) ENGINE=InnoDB; |
||||
|
`)
|
||||
|
|
||||
|
await connection.query(` |
||||
|
CREATE TABLE IF NOT EXISTS parcoursmatiere ( |
||||
|
id INT AUTO_INCREMENT PRIMARY KEY, |
||||
|
matiere_id INT NOT NULL, |
||||
|
parcour_id INT NOT NULL, |
||||
|
FOREIGN KEY (matiere_id) REFERENCES matieres(id), |
||||
|
FOREIGN KEY (parcour_id) REFERENCES parcours(id) |
||||
|
) ENGINE=InnoDB; |
||||
|
`)
|
||||
|
|
||||
|
await connection.query(` |
||||
|
CREATE TABLE IF NOT EXISTS trancheecolage ( |
||||
|
id INT AUTO_INCREMENT PRIMARY KEY, |
||||
|
etudiant_id INT NOT NULL, |
||||
|
tranchename VARCHAR(255) NOT NULL, |
||||
|
montant DOUBLE NOT NULL |
||||
|
) ENGINE=InnoDB; |
||||
|
`)
|
||||
|
|
||||
|
await connection.query(` |
||||
|
CREATE TABLE IF NOT EXISTS ipconfig ( |
||||
|
id INT AUTO_INCREMENT PRIMARY KEY, |
||||
|
ipname VARCHAR(255) NOT NULL |
||||
|
) ENGINE=InnoDB; |
||||
|
`)
|
||||
|
} finally { |
||||
|
connection.release() |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
async function insertDefaultAdmin() { |
||||
|
const conn = await pool.getConnection() |
||||
|
try { |
||||
|
const [rows] = await conn.query(`SELECT COUNT(*) as count FROM users WHERE username = ?`, [ |
||||
|
'admin' |
||||
|
]) |
||||
|
if (rows[0].count === 0) { |
||||
|
const hashedPassword = bcrypt.hashSync('123456789', 10) |
||||
|
await conn.query( |
||||
|
` |
||||
|
INSERT INTO users (username, email, password, roles) |
||||
|
VALUES (?, ?, ?, ?)`,
|
||||
|
['admin', 'admin@example.com', hashedPassword, 'admin'] |
||||
|
) |
||||
|
} |
||||
|
} finally { |
||||
|
conn.release() |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
async function insertStatusesIfNotExist() { |
||||
|
const conn = await pool.getConnection() |
||||
|
try { |
||||
|
const statuses = ['Nouveau', 'Passant', 'Redoublant', 'Renvoyé', 'Ancien'] |
||||
|
for (let name of statuses) { |
||||
|
const [rows] = await conn.query(`SELECT COUNT(*) as count FROM status WHERE nom = ?`, [name]) |
||||
|
if (rows[0].count === 0) { |
||||
|
await conn.query(`INSERT INTO status (nom) VALUES (?)`, [name]) |
||||
|
} |
||||
|
} |
||||
|
} finally { |
||||
|
conn.release() |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
module.exports = { |
||||
|
pool, |
||||
|
createTables, |
||||
|
insertDefaultAdmin, |
||||
|
insertStatusesIfNotExist |
||||
|
} |
||||
@ -0,0 +1,15 @@ |
|||||
|
{ |
||||
|
"compilerOptions": { |
||||
|
"module": "ESNext", |
||||
|
"moduleResolution": "Bundler", |
||||
|
"target": "ES2022", |
||||
|
"jsx": "react-jsx", |
||||
|
"allowImportingTsExtensions": true, |
||||
|
"strictNullChecks": true, |
||||
|
"strictFunctionTypes": true |
||||
|
}, |
||||
|
"exclude": [ |
||||
|
"node_modules", |
||||
|
"**/node_modules/*" |
||||
|
] |
||||
|
} |
||||
@ -0,0 +1,210 @@ |
|||||
|
import { contextBridge, ipcRenderer } from 'electron' |
||||
|
import { electronAPI } from '@electron-toolkit/preload' |
||||
|
const { getNessesarytable } = require('../../database/function/System') |
||||
|
const { getNiveau } = require('../../database/Models/Niveau') |
||||
|
const { getAllUsers } = require('../../database/Models/Users') |
||||
|
const { getAllEtudiants, getDataToDashboard } = require('../../database/Models/Etudiants') |
||||
|
const { verifyEtudiantIfHeHasNotes, blockShowMoyene } = require('../../database/Models/Notes') |
||||
|
|
||||
|
const { synchronizeData } = require('../../database/api/SyncronisationDataUsers') |
||||
|
const { synchronizeDataEtudiants } = require('../../database/api/SyncronisationDataEtudiants') |
||||
|
const { synchronizeDataNotes } = require('../../database/api/CheckUpdateNote') |
||||
|
const { getMatiere, getSemestre, getEnseignants } = require('../../database/Models/Matieres') |
||||
|
const { getSysteme } = require('../../database/Models/NoteSysrem') |
||||
|
const { getStatus } = require('../../database/Models/Status') |
||||
|
const { getAnneeScolaire, getInterval } = require('../../database/Models/AnneeScolaire') |
||||
|
const { getMentions } = require('../../database/Models/Mentions') |
||||
|
const { getAll } = require('../../database/api/Get') |
||||
|
const { getParcours } = require('../../database/Models/Parcours') |
||||
|
const { getIPConfig } = require('../../database/Models/IpConfig') |
||||
|
|
||||
|
// Custom APIs for renderer
|
||||
|
const api = {} |
||||
|
|
||||
|
// Use `contextBridge` APIs to expose Electron APIs to
|
||||
|
// renderer only if context isolation is enabled, otherwise
|
||||
|
// just add to the DOM global.
|
||||
|
if (process.contextIsolated) { |
||||
|
try { |
||||
|
contextBridge.exposeInMainWorld('electron', electronAPI) |
||||
|
contextBridge.exposeInMainWorld('api', api) |
||||
|
|
||||
|
/** |
||||
|
* contextBridge for Tray |
||||
|
*/ |
||||
|
contextBridge.exposeInMainWorld('Tray', { |
||||
|
onNavigate: (callback) => { |
||||
|
ipcRenderer.on('navigateToRoute', (event, route) => { |
||||
|
callback(route) // Pass the route to the renderer callback
|
||||
|
}) |
||||
|
} |
||||
|
}) |
||||
|
|
||||
|
/** |
||||
|
* contextBridge for users |
||||
|
*/ |
||||
|
contextBridge.exposeInMainWorld('allUser', { |
||||
|
users: () => getAllUsers(), |
||||
|
login: (credentials) => ipcRenderer.invoke('login', credentials), |
||||
|
insertUsers: (credentials) => ipcRenderer.invoke('insertUser', credentials), |
||||
|
forgotPassword: (credentials) => ipcRenderer.invoke('forgotPassword', credentials), |
||||
|
quit: () => ipcRenderer.invoke('quit'), |
||||
|
minimize: () => ipcRenderer.invoke('minimize'), |
||||
|
updateUsers: (credentials) => ipcRenderer.invoke('updateUsers', credentials) |
||||
|
}) |
||||
|
|
||||
|
contextBridge.exposeInMainWorld('syncro', { |
||||
|
getall: () => getAll() |
||||
|
}) |
||||
|
|
||||
|
// syncronisation des donner
|
||||
|
window.addEventListener('online', async () => { |
||||
|
if (navigator.onLine) { |
||||
|
// synchronizeData()
|
||||
|
// synchronizeDataEtudiants()
|
||||
|
// synchronizeDataNotes()
|
||||
|
await getAll() |
||||
|
} |
||||
|
}) |
||||
|
// send data
|
||||
|
getAll() |
||||
|
|
||||
|
/** |
||||
|
* contextBridge for etudiants |
||||
|
*/ |
||||
|
contextBridge.exposeInMainWorld('etudiants', { |
||||
|
insertEtudiant: (credentials) => ipcRenderer.invoke('insertEtudiant', credentials), |
||||
|
getEtudiants: () => getAllEtudiants(), |
||||
|
FilterDataByNiveau: (credential) => ipcRenderer.invoke('getByNiveau', credential), |
||||
|
getSingle: (credential) => ipcRenderer.invoke('single', credential), |
||||
|
updateEtudiants: (credentials) => ipcRenderer.invoke('updateETudiants', credentials), |
||||
|
getDataToDashboards: () => getDataToDashboard(), |
||||
|
updateEtudiantsPDP: (credentials) => ipcRenderer.invoke('updateETudiantsPDP', credentials), |
||||
|
importExcel: (credentials) => ipcRenderer.invoke('importexcel', credentials), |
||||
|
changeParcours: (credentials) => ipcRenderer.invoke('changeParcours', credentials), |
||||
|
createTranche: (credentials) => ipcRenderer.invoke('createTranche', credentials), |
||||
|
getTranche: (credentials) => ipcRenderer.invoke('getTranche', credentials), |
||||
|
updateTranche: (credentials) => ipcRenderer.invoke('updateTranche', credentials), |
||||
|
deleteTranche: (credentials) => ipcRenderer.invoke('deleteTranche', credentials), |
||||
|
getSingleTranche: (credentials) => ipcRenderer.invoke('getSingleTranche', credentials) |
||||
|
}) |
||||
|
|
||||
|
/** |
||||
|
* cobtextBridge for niveaus |
||||
|
*/ |
||||
|
contextBridge.exposeInMainWorld('niveaus', { |
||||
|
getNiveau: () => getNiveau(), |
||||
|
getSingleNiveau: (credential) => ipcRenderer.invoke('singleNiveau', credential), |
||||
|
insertNiveau: (credentials) => ipcRenderer.invoke('insertNiveau', credentials), |
||||
|
updateSingleNiveau: (credentials) => ipcRenderer.invoke('updateSingleNiveau', credentials), |
||||
|
importNiveau: (credentials) => ipcRenderer.invoke('importNiveau', credentials), |
||||
|
deleteNiveaus: (credentials) => ipcRenderer.invoke('deleteNiveaus', credentials) |
||||
|
}) |
||||
|
|
||||
|
/** |
||||
|
* contextBridge for notes |
||||
|
*/ |
||||
|
contextBridge.exposeInMainWorld('notes', { |
||||
|
getNotes: (credentials) => ipcRenderer.invoke('getSingleNote', credentials), |
||||
|
insertNote: (credentials) => ipcRenderer.invoke('insertNote', credentials), |
||||
|
updateNote: (credentials) => ipcRenderer.invoke('updatetNote', credentials), |
||||
|
getMoyenne: (credentials) => ipcRenderer.invoke('getMoyene', credentials), |
||||
|
noteMatiere: (credentials) => ipcRenderer.invoke('noteMatiere', credentials), |
||||
|
noteRelerer: (credentials) => ipcRenderer.invoke('noteRelerer', credentials), |
||||
|
getMoyenneVerify: () => verifyEtudiantIfHeHasNotes(), |
||||
|
getblockNote: () => blockShowMoyene() |
||||
|
}) |
||||
|
|
||||
|
/** |
||||
|
* contextbridge for note repechage |
||||
|
*/ |
||||
|
contextBridge.exposeInMainWorld('noteRepech', { |
||||
|
getNotesRepech: (credentials) => ipcRenderer.invoke('getNotesRepech', credentials), |
||||
|
updateNoteRepech: (credentials) => ipcRenderer.invoke('updatetNoteRepech', credentials), |
||||
|
getMoyenneRepech: (credentials) => ipcRenderer.invoke('getMoyenneRepech', credentials) |
||||
|
}) |
||||
|
|
||||
|
/** |
||||
|
* contextBridge for matieres |
||||
|
*/ |
||||
|
contextBridge.exposeInMainWorld('matieres', { |
||||
|
getMatiere: () => getMatiere(), |
||||
|
createMatiere: (credentials) => ipcRenderer.invoke('createMatiere', credentials), |
||||
|
getMatiereByID: (credentials) => ipcRenderer.invoke('getMatiereByID', credentials), |
||||
|
updateMatiere: (credentials) => ipcRenderer.invoke('updateMatiere', credentials), |
||||
|
importExcel: (credentials) => ipcRenderer.invoke('importExcelMatiere', credentials), |
||||
|
displayMatiereFromForm: (credentials) => |
||||
|
ipcRenderer.invoke('displayMatiereFromForm', credentials), |
||||
|
deleteMatiere: (credentials) => ipcRenderer.invoke('deleteMatiere', credentials), |
||||
|
asign: (credentials) => ipcRenderer.invoke('asign', credentials), |
||||
|
getAsign: (credentials) => ipcRenderer.invoke('getAsign', credentials), |
||||
|
asignSemestre: (credentials) => ipcRenderer.invoke('asignSemestre', credentials), |
||||
|
getSemestreMatiere: (credentials) => ipcRenderer.invoke('getSemestreMatiere', credentials), |
||||
|
getSemestre: () => getSemestre(), |
||||
|
getNessesary: () => getNessesarytable(), |
||||
|
getENseignant: () => getEnseignants(), |
||||
|
insertUpdateMentionSemestre: (credentials) => |
||||
|
ipcRenderer.invoke('insertUpdateMentionSemestre', credentials), |
||||
|
updateNessesary: (credentials) => ipcRenderer.invoke('updateNessesary', credentials), |
||||
|
insertProf: (credentials) => ipcRenderer.invoke('insertProf', credentials), |
||||
|
getSingleProf: (credentials) => ipcRenderer.invoke('getSingleProf', credentials), |
||||
|
updateProf: (credentials) => ipcRenderer.invoke('updateProf', credentials) |
||||
|
}) |
||||
|
|
||||
|
/** |
||||
|
* contextBridge for note systeme |
||||
|
*/ |
||||
|
contextBridge.exposeInMainWorld('notesysteme', { |
||||
|
getSyteme: () => getSysteme(), |
||||
|
updateNoteSysteme: (credentials) => ipcRenderer.invoke('updateNoteSysteme', credentials), |
||||
|
insertParcours: (credentials) => ipcRenderer.invoke('insertParcours', credentials), |
||||
|
getSingleParcours: (credentials) => ipcRenderer.invoke('getSingleParcours', credentials), |
||||
|
deleteParcours: (credentials) => ipcRenderer.invoke('deleteParcours', credentials), |
||||
|
updateParcours: (credentials) => ipcRenderer.invoke('updateParcours', credentials), |
||||
|
parcourMatiere: (credentials) => ipcRenderer.invoke('parcourMatiere', credentials), |
||||
|
getParcours: () => getParcours(), |
||||
|
extractFiches: (credentials) => ipcRenderer.invoke('extractFiches', credentials), |
||||
|
getParcourMatiere: (credentials) => ipcRenderer.invoke('getParcourMatiere', credentials), |
||||
|
createIPConfig: (credentials) => ipcRenderer.invoke('createIPConfig', credentials), |
||||
|
getIPConfig: () => getIPConfig(), |
||||
|
updateIPConfig: (credentials) => ipcRenderer.invoke('updateIPConfig', credentials) |
||||
|
}) |
||||
|
|
||||
|
/** |
||||
|
* contextbridge for status |
||||
|
*/ |
||||
|
contextBridge.exposeInMainWorld('statuss', { |
||||
|
getStatus: () => getStatus() |
||||
|
}) |
||||
|
|
||||
|
/** |
||||
|
* contextbridge for annee scolaire |
||||
|
*/ |
||||
|
contextBridge.exposeInMainWorld('anneescolaire', { |
||||
|
getAnneeScolaire: () => getAnneeScolaire(), |
||||
|
getInterval: () => getInterval(), |
||||
|
createAnneeScolaire: (credentials) => ipcRenderer.invoke('createAnneeScolaire', credentials), |
||||
|
deleteAnneeScolaire: (credentials) => ipcRenderer.invoke('deleteAnneeScolaire', credentials), |
||||
|
getSingleAnneeScolaire: (credentials) => |
||||
|
ipcRenderer.invoke('getSingleAnneeScolaire', credentials), |
||||
|
updateAnneeScolaire: (credentials) => ipcRenderer.invoke('updateAnneeScolaire', credentials), |
||||
|
setCurrent: (credentials) => ipcRenderer.invoke('setCurrent', credentials) |
||||
|
}) |
||||
|
|
||||
|
/** |
||||
|
* contextbridge for mention |
||||
|
*/ |
||||
|
contextBridge.exposeInMainWorld('mention', { |
||||
|
createMention: (credentials) => ipcRenderer.invoke('createMention', credentials), |
||||
|
getMention: () => getMentions(), |
||||
|
getSingleMention: (credentials) => ipcRenderer.invoke('getSingleMention', credentials), |
||||
|
updateMention: (credentials) => ipcRenderer.invoke('updateMention', credentials), |
||||
|
deleteMention: (credentials) => ipcRenderer.invoke('deleteMention', credentials) |
||||
|
}) |
||||
|
} catch (error) { |
||||
|
console.error(error) |
||||
|
} |
||||
|
} else { |
||||
|
window.electron = electronAPI |
||||
|
window.api = api |
||||
|
} |
||||
Loading…
Reference in new issue