Compare commits
2 Commits
82b5e6a68e
...
0cf0a72814
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0cf0a72814 | ||
|
|
290f5747fb |
@ -1,4 +1,4 @@
|
|||||||
const { database } = require('../database')
|
const { pool } = require('../database')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* function to create annee scolaire
|
* function to create annee scolaire
|
||||||
@ -8,14 +8,17 @@ const { database } = require('../database')
|
|||||||
* @returns promise
|
* @returns promise
|
||||||
*/
|
*/
|
||||||
async function createAnneeScolaire(code, debut, fin) {
|
async function createAnneeScolaire(code, debut, fin) {
|
||||||
const query = database.prepare('INSERT INTO anneescolaire (code, debut, fin) VALUES (?, ?, ?)')
|
const sql = 'INSERT INTO anneescolaire (code, debut, fin) VALUES (?, ?, ?)'
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response = await query.run(code, debut, fin)
|
let [result] = await pool.query(sql, [code, debut, fin])
|
||||||
|
|
||||||
return response
|
return {
|
||||||
|
success: true,
|
||||||
|
id: result.insertId
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return { success: false, error: 'Erreur veullez réeseyer' }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,81 +27,101 @@ async function createAnneeScolaire(code, debut, fin) {
|
|||||||
* @returns promise
|
* @returns promise
|
||||||
*/
|
*/
|
||||||
async function getAnneeScolaire() {
|
async function getAnneeScolaire() {
|
||||||
const query = database.prepare('SELECT * FROM anneescolaire ORDER BY code DESC')
|
const sql = 'SELECT * FROM anneescolaire ORDER BY code DESC'
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response = await query.all()
|
let [rows] = await pool.query(sql)
|
||||||
|
|
||||||
return response
|
return rows
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return { success: false, error: 'Erreur veullez réeseyer' }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getInterval() {
|
async function getInterval() {
|
||||||
const query = database.prepare('SELECT debut, fin FROM anneescolaire ORDER BY id DESC')
|
const sql = 'SELECT debut, fin FROM anneescolaire ORDER BY id DESC'
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response = await query.all()
|
let [rows] = await pool.query(sql)
|
||||||
|
|
||||||
return response
|
return rows
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return { success: false, error: 'Erreur veullez réeseyer' }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getSingleAnneScolaire(id) {
|
async function getSingleAnneScolaire(id) {
|
||||||
const query = database.prepare('SELECT * FROM anneescolaire WHERE id = ?')
|
const sql = 'SELECT * FROM anneescolaire WHERE id = ?'
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response = await query.get(id)
|
let [rows] = await pool.query(sql, [id])
|
||||||
|
|
||||||
return response
|
return rows[0]
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return { success: false, error: 'Erreur veullez réeseyer' }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteAnneeScolaire(id) {
|
async function deleteAnneeScolaire(id) {
|
||||||
const query = database.prepare('DELETE FROM anneescolaire WHERE id = ?')
|
const sql = 'DELETE FROM anneescolaire WHERE id = ?'
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response = query.run(id)
|
let [result] = await pool.query(sql, [id])
|
||||||
|
|
||||||
return response
|
if (result.affectedRows === 0) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: 'Année universitaire non trouvé.'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: 'Année universitaire supprimé avec succès.'
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return { success: false, error: 'Erreur veullez réeseyer' }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateAnneeScolaire(id, code, debut, fin) {
|
async function updateAnneeScolaire(id, code, debut, fin) {
|
||||||
const query = database.prepare(
|
const sql = 'UPDATE anneescolaire SET code = ?, debut = ?, fin = ? WHERE id = ?'
|
||||||
'UPDATE anneescolaire SET code = ?, debut = ?, fin = ? WHERE id = ?'
|
|
||||||
)
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response = query.run(code, debut, fin, id)
|
let [result] = await pool.query(sql, [code, debut, fin, id])
|
||||||
|
|
||||||
return response
|
if (result.affectedRows === 0) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: 'Année universitaire non trouvé ou aucune modification effectuée.'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: 'Année universitaire mis à jour avec succès.'
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return { success: false, error: 'Erreur veullez réeseyer' }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setCurrent(id) {
|
async function setCurrent(id) {
|
||||||
const query = database.prepare(
|
const sql = 'UPDATE anneescolaire SET is_current = 0 WHERE id > 0 AND is_current = 1'
|
||||||
'UPDATE anneescolaire SET is_current = 0 WHERE id > 0 AND is_current = 1'
|
const sql2 = 'UPDATE anneescolaire SET is_current = 1 WHERE id = ?'
|
||||||
)
|
|
||||||
const query2 = database.prepare('UPDATE anneescolaire SET is_current = 1 WHERE id = ?')
|
pool.query(sql)
|
||||||
|
|
||||||
let clear = query.run()
|
|
||||||
console.log(clear)
|
|
||||||
try {
|
try {
|
||||||
let response = query2.run(id)
|
const [result] = pool.query(sql2, [id])
|
||||||
|
console.log(result)
|
||||||
|
|
||||||
return response
|
return {
|
||||||
|
success: true,
|
||||||
|
id: result.insertId
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return { success: false, error: 'Erreur veullez réeseyer' }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
305
database/Models/Etudiants.backup.js
Normal file
305
database/Models/Etudiants.backup.js
Normal file
@ -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
|
||||||
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
const { database } = require('../database')
|
const { pool } = require('../database')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* function to insert etudiant into databases
|
* function to insert etudiant into databases
|
||||||
@ -24,12 +24,11 @@ async function insertEtudiant(
|
|||||||
contact,
|
contact,
|
||||||
parcours
|
parcours
|
||||||
) {
|
) {
|
||||||
const query = database.prepare(
|
const sql =
|
||||||
'INSERT INTO etudiants (nom, prenom, photos, date_de_naissances, niveau, annee_scolaire, status, mention_id, num_inscription, sexe, cin, date_delivrance, nationalite, annee_bacc, serie, boursier, domaine, contact, parcours) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'
|
'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 {
|
try {
|
||||||
let response = await query.run(
|
let [result] = await pool.query(sql, [
|
||||||
nom,
|
nom,
|
||||||
prenom,
|
prenom,
|
||||||
photos,
|
photos,
|
||||||
@ -49,8 +48,12 @@ async function insertEtudiant(
|
|||||||
domaine,
|
domaine,
|
||||||
contact,
|
contact,
|
||||||
parcours
|
parcours
|
||||||
)
|
])
|
||||||
return response
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
id: result.insertId
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return error
|
||||||
}
|
}
|
||||||
@ -62,11 +65,11 @@ async function insertEtudiant(
|
|||||||
* @returns JSON
|
* @returns JSON
|
||||||
*/
|
*/
|
||||||
async function getAllEtudiants() {
|
async function getAllEtudiants() {
|
||||||
const query = database.prepare('SELECT * FROM etudiants ORDER BY annee_scolaire DESC')
|
const sql = 'SELECT * FROM etudiants ORDER BY annee_scolaire DESC'
|
||||||
try {
|
try {
|
||||||
let response = await query.all()
|
let [rows] = await pool.query(sql)
|
||||||
|
|
||||||
return response
|
return rows
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return error
|
||||||
}
|
}
|
||||||
@ -80,16 +83,12 @@ async function getAllEtudiants() {
|
|||||||
* @returns Promise
|
* @returns Promise
|
||||||
*/
|
*/
|
||||||
async function getSingleEtudiant(id) {
|
async function getSingleEtudiant(id) {
|
||||||
const query = database.prepare('SELECT * FROM etudiants WHERE id = ?')
|
const sql = 'SELECT * FROM etudiants WHERE id = ?'
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const etudiants = await query.get(id)
|
const [rows] = await pool.query(sql, [id])
|
||||||
|
|
||||||
if (etudiants) {
|
return rows[0]
|
||||||
return etudiants
|
|
||||||
} else {
|
|
||||||
return { message: 'etudiants pas trouver' }
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return error
|
||||||
}
|
}
|
||||||
@ -101,13 +100,11 @@ async function getSingleEtudiant(id) {
|
|||||||
* @returns JSON
|
* @returns JSON
|
||||||
*/
|
*/
|
||||||
async function FilterDataByNiveau(niveau) {
|
async function FilterDataByNiveau(niveau) {
|
||||||
const query = database.prepare(
|
const sql = 'SELECT * FROM etudiants WHERE niveau = ? ORDER BY annee_scolaire DESC'
|
||||||
'SELECT * FROM etudiants WHERE niveau = ? ORDER BY annee_scolaire DESC'
|
|
||||||
)
|
|
||||||
try {
|
try {
|
||||||
let response = await query.all(niveau)
|
let [rows] = await pool.query(sql, [niveau])
|
||||||
|
|
||||||
return response
|
return rows
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return error
|
||||||
}
|
}
|
||||||
@ -149,12 +146,11 @@ async function updateEtudiant(
|
|||||||
contact,
|
contact,
|
||||||
parcours
|
parcours
|
||||||
) {
|
) {
|
||||||
const query = database.prepare(
|
const sql =
|
||||||
'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 = ?'
|
'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 {
|
try {
|
||||||
let response = await query.run(
|
let [result] = await pool.query(sql, [
|
||||||
nom,
|
nom,
|
||||||
prenom,
|
prenom,
|
||||||
photos,
|
photos,
|
||||||
@ -175,9 +171,19 @@ async function updateEtudiant(
|
|||||||
contact,
|
contact,
|
||||||
parcours,
|
parcours,
|
||||||
id
|
id
|
||||||
)
|
])
|
||||||
|
|
||||||
return response
|
if (result.affectedRows === 0) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: 'Année universitaire non trouvé.'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: 'Année universitaire supprimé avec succès.'
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return error
|
||||||
}
|
}
|
||||||
@ -189,14 +195,17 @@ async function updateEtudiant(
|
|||||||
* @returns promise
|
* @returns promise
|
||||||
*/
|
*/
|
||||||
async function getDataToDashboard() {
|
async function getDataToDashboard() {
|
||||||
const query = database.prepare('SELECT * FROM niveaus')
|
const query = 'SELECT * FROM niveaus'
|
||||||
const query2 = database.prepare('SELECT * FROM etudiants')
|
const query2 = 'SELECT * FROM etudiants'
|
||||||
const query3 = database.prepare('SELECT DISTINCT annee_scolaire FROM etudiants') // get all année scolaire sans doublan
|
const query3 = 'SELECT DISTINCT annee_scolaire FROM etudiants' // get all année scolaire sans doublan
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let niveau = query.all()
|
let [rows] = await pool.query(query)
|
||||||
let etudiants = query2.all()
|
let niveau = rows
|
||||||
let anne_scolaire = query3.all()
|
;[rows] = await pool.query(query2)
|
||||||
|
let etudiants = rows
|
||||||
|
;[rows] = await pool.query(query3)
|
||||||
|
let anne_scolaire = rows
|
||||||
|
|
||||||
return { niveau, etudiants, anne_scolaire }
|
return { niveau, etudiants, anne_scolaire }
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -205,38 +214,59 @@ async function getDataToDashboard() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function changePDP(photos, id) {
|
async function changePDP(photos, id) {
|
||||||
const query = database.prepare('UPDATE etudiants SET photos = ? WHERE id = ?')
|
const sql = 'UPDATE etudiants SET photos = ? WHERE id = ?'
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response = await query.run(photos, id)
|
let [result] = await pool.query(sql, [photos, id])
|
||||||
|
|
||||||
return response
|
if (result.affectedRows === 0) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: 'Année universitaire non trouvé.'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: 'Année universitaire supprimé avec succès.'
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateParcours(parcours, id) {
|
async function updateParcours(parcours, id) {
|
||||||
const query = database.prepare('UPDATE etudiants SET parcours = ? WHERE id = ?')
|
const sql = 'UPDATE etudiants SET parcours = ? WHERE id = ?'
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response = await query.run(parcours, id)
|
let [result] = await pool.query(sql, [parcours, id])
|
||||||
|
|
||||||
return response
|
if (result.affectedRows === 0) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: 'Année universitaire non trouvé.'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: 'Année universitaire supprimé avec succès.'
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createTranche(etudiant_id, tranchename, montant) {
|
async function createTranche(etudiant_id, tranchename, montant) {
|
||||||
const query = database.prepare(
|
const sql = 'INSERT INTO trancheecolage (etudiant_id, tranchename, montant) VALUES (?, ?, ?)'
|
||||||
'INSERT INTO trancheecolage (etudiant_id, tranchename, montant) VALUES (?, ?, ?)'
|
|
||||||
)
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response = query.run(etudiant_id, tranchename, montant)
|
let [result] = pool.query(sql, [etudiant_id, tranchename, montant])
|
||||||
|
|
||||||
return response
|
return {
|
||||||
|
success: true,
|
||||||
|
id: result.insertId
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return error
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
const { database } = require('../database');
|
const { database } = require('../database.backup');
|
||||||
|
|
||||||
const createConfigIp = (ipname) => {
|
const createConfigIp = (ipname) => {
|
||||||
const query = database.prepare('INSERT INTO ipconfig (ipname) VALUES (?)');
|
const query = database.prepare('INSERT INTO ipconfig (ipname) VALUES (?)');
|
||||||
|
|||||||
354
database/Models/Matieres.backup.js
Normal file
354
database/Models/Matieres.backup.js
Normal file
@ -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
|
||||||
|
}
|
||||||
@ -1,6 +1,5 @@
|
|||||||
const { database } = require('../database')
|
const { pool } = require('../database')
|
||||||
const { matiereSysteme } = require('../function/System')
|
const { matiereSysteme } = require('../function/System')
|
||||||
const { convertArrayAndString } = require('../function/StringArrayConvertion')
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* function uset to create matiere
|
* function uset to create matiere
|
||||||
@ -8,19 +7,22 @@ const { convertArrayAndString } = require('../function/StringArrayConvertion')
|
|||||||
* @returns Promise
|
* @returns Promise
|
||||||
*/
|
*/
|
||||||
async function createMatiere(nom, credit, uniter, ue) {
|
async function createMatiere(nom, credit, uniter, ue) {
|
||||||
const query = database.prepare(
|
const sql =
|
||||||
'INSERT INTO matieres (nom, unite_enseignement, credit, heure, ue) VALUES (?, ?, ?, ?, ?)'
|
'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
|
|
||||||
|
|
||||||
|
const uniterHeure = 'SELECT uniter_heure FROM nessesaryTable'
|
||||||
|
let [rows] = await pool.query(uniterHeure)
|
||||||
|
const uniterHeureValue = rows[0].uniter_heure
|
||||||
|
const heure = credit * uniterHeureValue
|
||||||
try {
|
try {
|
||||||
response = await query.run(nom, uniter, credit, heure, ue)
|
const [result] = await pool.query(sql, [nom, uniter, credit, heure, ue])
|
||||||
|
|
||||||
return response
|
return {
|
||||||
|
success: true,
|
||||||
|
id: result.insertId
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return { success: false, error: 'Erreur veullez réeseyer' + error }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,14 +31,14 @@ async function createMatiere(nom, credit, uniter, ue) {
|
|||||||
* @returns Promise
|
* @returns Promise
|
||||||
*/
|
*/
|
||||||
async function getMatiere() {
|
async function getMatiere() {
|
||||||
const query = database.prepare('SELECT * FROM matieres ORDER BY id DESC')
|
const sql = 'SELECT * FROM matieres ORDER BY id DESC'
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response = await query.all()
|
let [rows] = await pool.query(sql)
|
||||||
|
|
||||||
return response
|
return rows
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return { success: false, error: 'Erreur veullez réeseyer' + error }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,7 +53,7 @@ async function displayMatiereFromForm(niveau, mention_id, parcours) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Prepare the query
|
// Prepare the query
|
||||||
let matiereQuery = database.prepare(`
|
let matiereQuery = `
|
||||||
SELECT DISTINCT m.*
|
SELECT DISTINCT m.*
|
||||||
FROM matieres m
|
FROM matieres m
|
||||||
JOIN matiere_semestre ms ON m.id = ms.matiere_id
|
JOIN matiere_semestre ms ON m.id = ms.matiere_id
|
||||||
@ -61,17 +63,21 @@ async function displayMatiereFromForm(niveau, mention_id, parcours) {
|
|||||||
WHERE (s.nom LIKE ? OR s.nom LIKE ?)
|
WHERE (s.nom LIKE ? OR s.nom LIKE ?)
|
||||||
AND ms.mention_id = ?
|
AND ms.mention_id = ?
|
||||||
AND p.nom = ?
|
AND p.nom = ?
|
||||||
`)
|
`
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Execute the query with parameters
|
// Execute the query with parameters
|
||||||
let response = matiereQuery.all(`%${semestre[0]}%`, `%${semestre[1]}%`, mention_id, parcours)
|
let [rows] = await pool.query(matiereQuery, [
|
||||||
|
`%${semestre[0]}%`,
|
||||||
|
`%${semestre[1]}%`,
|
||||||
|
mention_id,
|
||||||
|
parcours
|
||||||
|
])
|
||||||
|
|
||||||
console.log(response)
|
|
||||||
// Log the response
|
// Log the response
|
||||||
return response
|
return rows
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return { success: false, error: 'Erreur veullez réeseyer' + error }
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (semestre.length < 2) {
|
if (semestre.length < 2) {
|
||||||
@ -80,23 +86,27 @@ async function displayMatiereFromForm(niveau, mention_id, parcours) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Prepare the query
|
// Prepare the query
|
||||||
let matiereQuery = database.prepare(`
|
let matiereQuery = `
|
||||||
SELECT DISTINCT m.*
|
SELECT DISTINCT m.*
|
||||||
FROM matieres m
|
FROM matieres m
|
||||||
JOIN matiere_semestre ms ON m.id = ms.matiere_id
|
JOIN matiere_semestre ms ON m.id = ms.matiere_id
|
||||||
JOIN semestres s ON ms.semestre_id = s.id
|
JOIN semestres s ON ms.semestre_id = s.id
|
||||||
WHERE (s.nom LIKE ? OR s.nom LIKE ?)
|
WHERE (s.nom LIKE ? OR s.nom LIKE ?)
|
||||||
AND ms.mention_id = ?
|
AND ms.mention_id = ?
|
||||||
`)
|
`
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Execute the query with parameters
|
// Execute the query with parameters
|
||||||
let response = matiereQuery.all(`%${semestre[0]}%`, `%${semestre[1]}%`, mention_id)
|
let [rows] = await pool.query(matiereQuery, [
|
||||||
console.log(response)
|
`%${semestre[0]}%`,
|
||||||
|
`%${semestre[1]}%`,
|
||||||
|
mention_id
|
||||||
|
])
|
||||||
|
|
||||||
// Log the response
|
// Log the response
|
||||||
return response
|
return rows
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return { success: false, error: 'Erreur veullez réeseyer' + error }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -107,14 +117,14 @@ async function displayMatiereFromForm(niveau, mention_id, parcours) {
|
|||||||
* @returns promise
|
* @returns promise
|
||||||
*/
|
*/
|
||||||
async function getSingleMatiere(id) {
|
async function getSingleMatiere(id) {
|
||||||
const query = await database.prepare('SELECT * FROM matieres WHERE id = ?')
|
const sql = 'SELECT * FROM matieres WHERE id = ?'
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response = query.get(id)
|
let [rows] = await pool.query(sql, [id])
|
||||||
|
|
||||||
return response
|
return rows[0]
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return { success: false, error: 'Erreur veullez réeseyer' + error }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,211 +135,325 @@ async function getSingleMatiere(id) {
|
|||||||
* @returns promise
|
* @returns promise
|
||||||
*/
|
*/
|
||||||
async function updateMatiere(nom, id, credit, uniter, ue) {
|
async function updateMatiere(nom, id, credit, uniter, ue) {
|
||||||
const query = database.prepare(
|
const sql =
|
||||||
'UPDATE matieres SET nom = ?, credit = ?, unite_enseignement = ?, heure = ?, ue = ? WHERE id = ?'
|
'UPDATE matieres SET nom = ?, credit = ?, unite_enseignement = ?, heure = ?, ue = ? WHERE id = ?'
|
||||||
)
|
|
||||||
|
|
||||||
const uniterHeure = await database.prepare('SELECT uniter_heure FROM nessesaryTable').get()
|
const uniterHeure = 'SELECT uniter_heure FROM nessesaryTable'
|
||||||
const heure = credit * uniterHeure.uniter_heure
|
let [rows] = await pool.query(uniterHeure)
|
||||||
|
const uniterHeureValue = rows[0].uniter_heure
|
||||||
|
const heure = credit * uniterHeureValue
|
||||||
|
|
||||||
try {
|
try {
|
||||||
response = await query.run(nom, credit, uniter, heure, ue, id)
|
let [result] = await pool.query(sql, [nom, credit, uniter, heure, ue, id])
|
||||||
|
|
||||||
return response
|
if (result.affectedRows === 0) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: 'Année universitaire non trouvé ou aucune modification effectuée.'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: 'Année universitaire mis à jour avec succès.'
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return { success: false, error: 'Erreur veullez réeseyer' + error }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteMatiere(id) {
|
async function deleteMatiere(id) {
|
||||||
const query = database.prepare('DELETE FROM matieres WHERE id = ?')
|
const sql = 'DELETE FROM matieres WHERE id = ?'
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response = query.run(id)
|
let [result] = await pool.query(sql, [id])
|
||||||
|
|
||||||
return response
|
if (result.affectedRows === 0) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: 'Année universitaire non trouvé.'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: 'Année universitaire supprimé avec succès.'
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return { success: false, error: 'Erreur veullez réeseyer' + error }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assign mentions to a matiere
|
||||||
|
* @param {Object} formData - keys = mention_ids, values = true/false
|
||||||
|
* @param {number} id - matiere_id
|
||||||
|
*/
|
||||||
async function asygnationToMention(formData, id) {
|
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 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(
|
if (selectedKeys.length === 0) {
|
||||||
`DELETE FROM notes WHERE matiere_id = ? AND mention_id NOT IN (${placeholders})`
|
return { success: false, error: 'No mentions selected.' }
|
||||||
)
|
}
|
||||||
|
|
||||||
|
// build placeholders like (?, ?, ?)
|
||||||
|
const placeholders = selectedKeys.map(() => '?').join(',')
|
||||||
|
|
||||||
|
const deleteMentionSql = `
|
||||||
|
DELETE FROM matiere_mention
|
||||||
|
WHERE matiere_id = ?
|
||||||
|
`
|
||||||
|
|
||||||
|
const deleteSemestreMentionSql = `
|
||||||
|
DELETE FROM matiere_semestre
|
||||||
|
WHERE matiere_id = ?
|
||||||
|
AND mention_id NOT IN (${placeholders})
|
||||||
|
`
|
||||||
|
|
||||||
|
const deleteNotesSql = `
|
||||||
|
DELETE FROM notes
|
||||||
|
WHERE matiere_id = ?
|
||||||
|
AND mention_id NOT IN (${placeholders})
|
||||||
|
`
|
||||||
|
|
||||||
|
const insertMentionSql = `
|
||||||
|
INSERT INTO matiere_mention (matiere_id, mention_id)
|
||||||
|
VALUES (?, ?)
|
||||||
|
`
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response
|
const connection = await pool.getConnection()
|
||||||
await clearQuery.run(id)
|
try {
|
||||||
await clearNoreQuery.run(id, ...selectedKeys)
|
await connection.beginTransaction()
|
||||||
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
|
// delete all from matiere_mention for this matiere
|
||||||
} catch (error) {
|
await connection.query(deleteMentionSql, [id])
|
||||||
return error
|
|
||||||
|
// delete from matiere_semestre not in selected mentions
|
||||||
|
await connection.query(deleteSemestreMentionSql, [id, ...selectedKeys])
|
||||||
|
|
||||||
|
// delete from notes not in selected mentions
|
||||||
|
await connection.query(deleteNotesSql, [id, ...selectedKeys])
|
||||||
|
|
||||||
|
// re-insert new mentions
|
||||||
|
for (const mentionId of selectedKeys) {
|
||||||
|
await connection.query(insertMentionSql, [id, mentionId])
|
||||||
|
}
|
||||||
|
|
||||||
|
await connection.commit()
|
||||||
|
|
||||||
|
return { success: true }
|
||||||
|
} catch (error) {
|
||||||
|
await connection.rollback()
|
||||||
|
console.error(error)
|
||||||
|
return { success: false, error: error.message }
|
||||||
|
} finally {
|
||||||
|
connection.release()
|
||||||
|
}
|
||||||
|
} catch (connErr) {
|
||||||
|
console.error(connErr)
|
||||||
|
return { success: false, error: 'Database connection error.' }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getMentionMatiere(id) {
|
async function getMentionMatiere(id) {
|
||||||
const query = database.prepare('SELECT * FROM matiere_mention WHERE matiere_id = ?')
|
const sql = 'SELECT * FROM matiere_mention WHERE matiere_id = ?'
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response = await query.all(id)
|
let [rows] = await pool.query(sql, [id])
|
||||||
|
|
||||||
return response
|
return rows
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getMentionMatiereChecked(matiere_id) {
|
async function getMentionMatiereChecked(matiere_id) {
|
||||||
const getMentionMatiere = database.prepare('SELECT * FROM matiere_mention WHERE matiere_id = ?')
|
const getMentionMatiere = 'SELECT * FROM matiere_mention WHERE matiere_id = ?'
|
||||||
let MentionArray = await getMentionMatiere.all(matiere_id)
|
let [rows] = await pool.query(getMentionMatiere, [matiere_id])
|
||||||
|
let MentionArray = rows
|
||||||
let arrayID = []
|
let arrayID = []
|
||||||
|
|
||||||
for (let index = 0; index < MentionArray.length; index++) {
|
for (let index = 0; index < MentionArray.length; index++) {
|
||||||
arrayID.push(MentionArray[index].mention_id)
|
arrayID.push(MentionArray[index].mention_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
const mentionQuery = database.prepare(
|
const mentionQuery = `SELECT * FROM mentions WHERE id IN (${arrayID.map(() => '?').join(', ')})`
|
||||||
`SELECT * FROM mentions WHERE id IN (${arrayID.map(() => '?').join(', ')})`
|
|
||||||
)
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const results = await mentionQuery.all(...arrayID)
|
let [rows] = await pool.query(mentionQuery, [...arrayID])
|
||||||
|
|
||||||
return results
|
return rows
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getSemestreMatiere(id) {
|
async function getSemestreMatiere(id) {
|
||||||
const query = database.prepare('SELECT * FROM matiere_semestre WHERE matiere_id = ?')
|
const sql = 'SELECT * FROM matiere_semestre WHERE matiere_id = ?'
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response = await query.all(id)
|
let [rows] = await pool.query(sql, [id])
|
||||||
|
|
||||||
return response
|
return rows
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getSemestre() {
|
async function getSemestre() {
|
||||||
const query = database.prepare('SELECT * FROM semestres')
|
const sql = 'SELECT * FROM semestres'
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response = await query.all()
|
let [rows] = await pool.query(sql)
|
||||||
|
|
||||||
return response
|
return rows
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function insertUpdateMentionSemestre(matiere_id, formData) {
|
async function insertUpdateMentionSemestre(matiere_id, formData) {
|
||||||
const clearQuery = database.prepare('DELETE FROM matiere_semestre WHERE matiere_id = ?')
|
try {
|
||||||
clearQuery.run(matiere_id)
|
const connection = await pool.getConnection()
|
||||||
|
|
||||||
const query = database.prepare(
|
try {
|
||||||
'INSERT INTO matiere_semestre (matiere_id, semestre_id, mention_id) VALUES (?, ?, ?)'
|
await connection.beginTransaction()
|
||||||
)
|
|
||||||
let response
|
// Clear all old rows
|
||||||
database.transaction(() => {
|
const deleteSql = `
|
||||||
for (const key in formData) {
|
DELETE FROM matiere_semestre
|
||||||
if (formData.hasOwnProperty(key)) {
|
WHERE matiere_id = ?
|
||||||
for (let jindex = 0; jindex < formData[key].length; jindex++) {
|
`
|
||||||
response = query.run(matiere_id, formData[key][jindex], key)
|
await connection.query(deleteSql, [matiere_id])
|
||||||
|
|
||||||
|
// Prepare INSERT
|
||||||
|
const insertSql = `
|
||||||
|
INSERT INTO matiere_semestre (matiere_id, semestre_id, mention_id)
|
||||||
|
VALUES (?, ?, ?)
|
||||||
|
`
|
||||||
|
|
||||||
|
// Insert new rows
|
||||||
|
for (const mention_id of Object.keys(formData)) {
|
||||||
|
for (const semestre_id of formData[mention_id]) {
|
||||||
|
await connection.query(insertSql, [matiere_id, semestre_id, mention_id])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await connection.commit()
|
||||||
|
|
||||||
|
return { success: true }
|
||||||
|
} catch (err) {
|
||||||
|
await connection.rollback()
|
||||||
|
console.error(err)
|
||||||
|
return { success: false, error: err.message }
|
||||||
|
} finally {
|
||||||
|
connection.release()
|
||||||
}
|
}
|
||||||
})()
|
} catch (err) {
|
||||||
return response
|
console.error(err)
|
||||||
|
return { success: false, error: 'Database connection failed.' }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getEnseignants() {
|
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 {
|
try {
|
||||||
// Get the latest `id` for each `matiere_id`
|
const latestIdsSql = `
|
||||||
const latestIds = getIdQuery.all().map((row) => row.id)
|
SELECT MAX(id) AS id
|
||||||
|
FROM matiereEnseignants
|
||||||
|
GROUP BY matiere_id
|
||||||
|
ORDER BY MAX(date) DESC
|
||||||
|
`
|
||||||
|
|
||||||
|
const [rows] = await pool.query(latestIdsSql)
|
||||||
|
|
||||||
|
const latestIds = rows.map((r) => r.id)
|
||||||
|
|
||||||
// If no ids exist, return an empty array
|
|
||||||
if (latestIds.length === 0) {
|
if (latestIds.length === 0) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch the full details using the filtered IDs
|
// Build placeholders (?, ?, ?, …)
|
||||||
let response = query.all(...latestIds)
|
const placeholders = latestIds.map(() => `?`).join(`,`)
|
||||||
|
const fetchSql = `
|
||||||
|
SELECT *
|
||||||
|
FROM matiereEnseignants
|
||||||
|
WHERE id IN (${placeholders})
|
||||||
|
`
|
||||||
|
|
||||||
return response
|
const [enseignants] = await pool.query(fetchSql, latestIds)
|
||||||
|
|
||||||
|
return enseignants
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
return error
|
return error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function insertNewProf(matiere_id, nom, prenom, contact, date) {
|
async function insertNewProf(matiere_id, nom, prenom, contact, date) {
|
||||||
const query = database.prepare(
|
const sql = `
|
||||||
'INSERT INTO matiereEnseignants (matiere_id, nom_enseignant, prenom_enseignant, contact, date) VALUES (?, ?, ?, ?, ?)'
|
INSERT INTO matiereEnseignants
|
||||||
)
|
(matiere_id, nom_enseignant, prenom_enseignant, contact, date)
|
||||||
|
VALUES (?, ?, ?, ?, ?)
|
||||||
|
`
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response = query.run(matiere_id, nom, prenom, contact, date)
|
const [result] = await pool.query(sql, [matiere_id, nom, prenom, contact, date])
|
||||||
|
|
||||||
return response
|
return {
|
||||||
|
success: true,
|
||||||
|
id: result.insertId
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
return error
|
return error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getSIngleProf(id) {
|
async function getSIngleProf(matiere_id) {
|
||||||
try {
|
const sql = `
|
||||||
const prof = await database
|
SELECT *
|
||||||
.prepare('SELECT * FROM matiereEnseignants WHERE matiere_id = ?')
|
FROM matiereEnseignants
|
||||||
.get(id)
|
WHERE matiere_id = ?
|
||||||
|
ORDER BY date DESC
|
||||||
|
LIMIT 1
|
||||||
|
`
|
||||||
|
|
||||||
return prof
|
try {
|
||||||
|
const [rows] = await pool.query(sql, [matiere_id])
|
||||||
|
return rows[0] || null
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
return error
|
return error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateProf(matiere_id, nom, prenom, contact, date) {
|
async function updateProf(matiere_id, nom, prenom, contact, date) {
|
||||||
const query = database.prepare(
|
const sql = `
|
||||||
'UPDATE matiereEnseignants SET nom_enseignant = ?, prenom_enseignant = ?, contact = ?, date = ? WHERE matiere_id = ?'
|
UPDATE matiereEnseignants
|
||||||
)
|
SET nom_enseignant = ?,
|
||||||
|
prenom_enseignant = ?,
|
||||||
|
contact = ?,
|
||||||
|
date = ?
|
||||||
|
WHERE matiere_id = ?
|
||||||
|
`
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response = query.run(nom, prenom, contact, date, matiere_id)
|
const [result] = await pool.query(sql, [nom, prenom, contact, date, matiere_id])
|
||||||
|
|
||||||
return response
|
if (result.affectedRows === 0) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: 'Année universitaire non trouvé.'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: 'Année universitaire supprimé avec succès.'
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
return error
|
return error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,62 +1,85 @@
|
|||||||
const { database } = require('../database')
|
const { pool } = require('../database')
|
||||||
|
|
||||||
async function createMention(nom, uniter) {
|
async function createMention(nom, uniter) {
|
||||||
const query = database.prepare('INSERT INTO mentions (nom, uniter) VALUES (?, ?)')
|
const sql = 'INSERT INTO mentions (nom, uniter) VALUES (?, ?)'
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response = await query.run(nom, uniter)
|
let [result] = await pool.query(sql, [nom, uniter])
|
||||||
|
|
||||||
return response
|
return {
|
||||||
|
success: true,
|
||||||
|
id: result.insertId
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return { success: false, error: 'Erreur veullez réeseyer' + error }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteMention(id) {
|
async function deleteMention(id) {
|
||||||
const query = database.prepare('DELETE FROM mentions WHERE id = ?')
|
const sql = 'DELETE FROM mentions WHERE id = ?'
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response = await query.run(id)
|
let [result] = await pool.query(sql, [id])
|
||||||
|
|
||||||
return response
|
if (result.affectedRows === 0) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: 'Année universitaire non trouvé.'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: 'Année universitaire supprimé avec succès.'
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return { success: false, error: 'Erreur veullez réeseyer' + error }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getMentions() {
|
async function getMentions() {
|
||||||
const query = database.prepare('SELECT * FROM mentions')
|
const sql = 'SELECT * FROM mentions'
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response = await query.all()
|
let [rows] = await pool.query(sql)
|
||||||
|
|
||||||
return response
|
return rows
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return { success: false, error: 'Erreur veullez réeseyer' + error }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getSingleMention(id) {
|
async function getSingleMention(id) {
|
||||||
const query = database.prepare('SELECT * FROM mentions WHERE id = ?')
|
const sql = 'SELECT * FROM mentions WHERE id = ?'
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response = query.get(id)
|
let [rows] = await pool.query(sql, [id])
|
||||||
|
|
||||||
return response
|
return rows[0]
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return { success: false, error: 'Erreur veullez réeseyer' + error }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateMention(nom, uniter, id) {
|
async function updateMention(nom, uniter, id) {
|
||||||
const query = database.prepare('UPDATE mentions SET nom = ?, uniter = ? WHERE id = ?')
|
const sql = 'UPDATE mentions SET nom = ?, uniter = ? WHERE id = ?'
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response = query.run(nom, uniter, id)
|
let [result] = await pool.query(sql, [nom, uniter, id])
|
||||||
|
|
||||||
return response
|
if (result.affectedRows === 0) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: 'Année universitaire non trouvé ou aucune modification effectuée.'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: 'Année universitaire mis à jour avec succès.'
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return { success: false, error: 'Erreur veullez réeseyer' + error }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
const { database } = require('../database')
|
const { pool } = require('../database')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* function to insert niveau to database
|
* function to insert niveau to database
|
||||||
@ -15,14 +15,15 @@ async function insertNiveau(nom) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Prepare the query for insertion
|
// Prepare the query for insertion
|
||||||
const query = database.prepare('INSERT INTO niveaus (nom) VALUES (?)')
|
const sql = `INSERT INTO niveaus (nom) VALUES (?)`
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let responses = []
|
let responses = []
|
||||||
|
|
||||||
for (const name of nom_multiple) {
|
for (const name of nom_multiple) {
|
||||||
// Insert each name and collect the response
|
// Insert each name and collect the response
|
||||||
let response = await query.run(name)
|
const [result] = await pool.query(sql, [name])
|
||||||
responses.push(response)
|
responses.push(result)
|
||||||
}
|
}
|
||||||
if (nom_multiple.length === responses.length) {
|
if (nom_multiple.length === responses.length) {
|
||||||
return JSON.stringify({
|
return JSON.stringify({
|
||||||
@ -31,7 +32,7 @@ async function insertNiveau(nom) {
|
|||||||
})
|
})
|
||||||
} else return false
|
} else return false
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error // Return the error if any occurs
|
return { success: false, error: 'Erreur veullez réeseyer' }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,14 +42,18 @@ async function insertNiveau(nom) {
|
|||||||
* @returns Promise
|
* @returns Promise
|
||||||
*/
|
*/
|
||||||
async function getSingleNiveau(id) {
|
async function getSingleNiveau(id) {
|
||||||
const query = database.prepare('SELECT * FROM niveaus WHERE id = ?')
|
const sql = 'SELECT * FROM niveaus WHERE id = ?'
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response = await query.get(id)
|
let [rows] = await pool.query(sql, [id])
|
||||||
|
|
||||||
return response
|
if (rows.length > 0) {
|
||||||
|
return rows[0]
|
||||||
|
} else {
|
||||||
|
return null
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return { success: false, error: 'Erreur veullez réeseyer' }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,14 +64,24 @@ async function getSingleNiveau(id) {
|
|||||||
* @returns Promise
|
* @returns Promise
|
||||||
*/
|
*/
|
||||||
async function updateNiveau(nom, id) {
|
async function updateNiveau(nom, id) {
|
||||||
const query = database.prepare('UPDATE niveaus SET nom = ? WHERE id = ?')
|
const sql = 'UPDATE niveaus SET nom = ? WHERE id = ?'
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response = query.run(nom, id)
|
let [result] = await pool.query(sql, [nom, id])
|
||||||
|
|
||||||
return response
|
if (result.affectedRows === 0) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: 'Niveau non trouvé ou aucune modification effectuée.'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: 'Utilisateur mis à jour avec succès.'
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return { success: false, error: 'Erreur veullez réeseyer' + error }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,26 +89,39 @@ async function updateNiveau(nom, id) {
|
|||||||
* function to get all niveau
|
* function to get all niveau
|
||||||
*/
|
*/
|
||||||
async function getNiveau() {
|
async function getNiveau() {
|
||||||
const query = database.prepare('SELECT * FROM niveaus')
|
const sql = 'SELECT * FROM niveaus'
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response = query.all()
|
let [rows] = await pool.query(sql)
|
||||||
|
|
||||||
return response
|
return rows
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return { success: false, error: 'Erreur veullez réeseyer' }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteNiveau(id) {
|
async function deleteNiveau(id) {
|
||||||
const query = database.prepare('DELETE FROM niveaus WHERE id = ?')
|
const sql = 'DELETE FROM niveaus WHERE id = ?'
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response = await query.run(id)
|
let [result] = await pool.query(sql, [id])
|
||||||
|
|
||||||
return response
|
if (result.affectedRows === 0) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: 'Niveau non trouvé.'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: 'Niveau supprimé avec succès.'
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return {
|
||||||
|
success: false,
|
||||||
|
error: 'Erreur lors de la suppression, veuillez réessayer.'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
const { database } = require('../database')
|
const { database } = require('../database.backup')
|
||||||
const { getNiveau } = require('./Niveau')
|
const { getNiveau } = require('./Niveau')
|
||||||
const { matiereSysteme } = require('../function/System')
|
const { matiereSysteme } = require('../function/System')
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
const { database } = require('../database')
|
const { database } = require('../database.backup')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* function to get all Systeme note
|
* function to get all Systeme note
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
const { database } = require('../database')
|
const { database } = require('../database.backup')
|
||||||
const { getNiveau } = require('./Niveau')
|
const { getNiveau } = require('./Niveau')
|
||||||
const { matiereSysteme } = require('../function/System')
|
const { matiereSysteme } = require('../function/System')
|
||||||
|
|
||||||
|
|||||||
@ -1,169 +1,221 @@
|
|||||||
const { database } = require('../database')
|
const { pool } = require('../database')
|
||||||
const { matiereSystemReverse } = require('../function/System')
|
const { matiereSystemReverse } = require('../function/System')
|
||||||
const dayjs = require('dayjs')
|
const dayjs = require('dayjs')
|
||||||
|
|
||||||
async function insertParcour(nom, uniter, mention_id) {
|
async function insertParcour(nom, uniter, mention_id) {
|
||||||
const query = database.prepare('INSERT INTO parcours (nom, uniter, mention_id) VALUES (?, ?, ?)')
|
const sql = 'INSERT INTO parcours (nom, uniter, mention_id) VALUES (?, ?, ?)'
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response = query.run(nom, uniter, mention_id == null ? 0 : mention_id)
|
let [result] = await pool.query(sql, [nom, uniter, mention_id == null ? 0 : mention_id])
|
||||||
|
|
||||||
return response
|
return {
|
||||||
|
success: true,
|
||||||
|
id: result.insertId
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getParcourMatiere(id) {
|
async function getParcourMatiere(id) {
|
||||||
const parcourMatiereQuery = database.prepare('SELECT * FROM parcoursmatiere WHERE matiere_id = ?')
|
const sql = `SELECT * FROM parcoursmatiere WHERE matiere_id = ?`
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response
|
const [rows] = await pool.query(sql, [id])
|
||||||
return (response = await parcourMatiereQuery.all(id))
|
return rows
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
return error
|
return error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getParcours() {
|
async function getParcours() {
|
||||||
const query = database.prepare('SELECT * FROM parcours ORDER BY id DESC')
|
const sql = 'SELECT * FROM parcours ORDER BY id DESC'
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response = query.all()
|
let [rows] = await pool.query(sql)
|
||||||
|
|
||||||
return response
|
return rows
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getSingleParcours(id) {
|
async function getSingleParcours(id) {
|
||||||
const query = database.prepare('SELECT * FROM parcours WHERE id = ?')
|
const sql = 'SELECT * FROM parcours WHERE id = ?'
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response = await query.get(id)
|
let [rows] = await pool.query(sql, [id])
|
||||||
|
|
||||||
return response
|
return rows[0]
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deletes(id) {
|
async function deletes(id) {
|
||||||
const query = database.prepare('DELETE FROM parcours WHERE id = ?')
|
const sql = 'DELETE FROM parcours WHERE id = ?'
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response = await query.run(id)
|
let [result] = await pool.query(sql, [id])
|
||||||
|
|
||||||
return response
|
if (result.affectedRows === 0) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: 'Année universitaire non trouvé.'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: 'Année universitaire supprimé avec succès.'
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateparcour(id, nom, uniter, mention_id) {
|
async function updateparcour(id, nom, uniter, mention_id) {
|
||||||
const query = database.prepare(
|
const sql = 'UPDATE parcours SET nom = ?, uniter = ?, mention_id = ? WHERE id = ?'
|
||||||
'UPDATE parcours SET nom = ?, uniter = ?, mention_id = ? WHERE id = ?'
|
|
||||||
)
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response = await query.run(nom, uniter, mention_id, id)
|
let [result] = await pool.query(sql, [nom, uniter, mention_id, id])
|
||||||
|
|
||||||
return response
|
if (result.affectedRows === 0) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: 'Année universitaire non trouvé ou aucune modification effectuée.'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: 'Année universitaire mis à jour avec succès.'
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
return error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function parcourMatiere(matiere_id, parcour_id) {
|
async function parcourMatiere(matiere_id, parcour_ids) {
|
||||||
const query = database.prepare(
|
|
||||||
'INSERT INTO parcoursmatiere (matiere_id, parcour_id) VALUES (?, ?)'
|
|
||||||
)
|
|
||||||
|
|
||||||
database.prepare('DELETE FROM parcoursmatiere WHERE matiere_id = ?').run(matiere_id)
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response
|
// 1. Delete all existing relations for this matiere
|
||||||
database.transaction(() => {
|
const deleteSql = `DELETE FROM parcoursmatiere WHERE matiere_id = ?`
|
||||||
for (let index = 0; index < parcour_id.length; index++) {
|
await pool.query(deleteSql, [matiere_id])
|
||||||
response = query.run(matiere_id, parcour_id[index])
|
|
||||||
}
|
|
||||||
})()
|
|
||||||
|
|
||||||
return response
|
// 2. Insert new relations
|
||||||
|
if (parcour_ids.length === 0) {
|
||||||
|
return { success: true, message: 'No parcours to insert' }
|
||||||
|
}
|
||||||
|
|
||||||
|
const insertSql = `
|
||||||
|
INSERT INTO parcoursmatiere (matiere_id, parcour_id)
|
||||||
|
VALUES ${parcour_ids.map(() => '(?, ?)').join(',')}
|
||||||
|
`
|
||||||
|
|
||||||
|
// Flatten values like: [matiere_id, parcour_id1, matiere_id, parcour_id2, ...]
|
||||||
|
const values = parcour_ids.flatMap((pid) => [matiere_id, pid])
|
||||||
|
|
||||||
|
const [result] = await pool.query(insertSql, values)
|
||||||
|
|
||||||
|
return { success: true, affectedRows: result.affectedRows }
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
console.error(error)
|
||||||
|
return { success: false, error: error.message }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function extractFiche(matiere_id) {
|
async function extractFiche(matiere_id) {
|
||||||
const query = database.prepare(
|
const now = dayjs().format('YYYY')
|
||||||
'SELECT matiere_semestre.semestre_id, matiere_semestre.mention_id, semestres.* FROM matiere_semestre INNER JOIN semestres ON (matiere_semestre.semestre_id = semestres.id) WHERE matiere_semestre.matiere_id = ?'
|
|
||||||
)
|
|
||||||
const allStudentQuery = database.prepare(
|
|
||||||
'SELECT * FROM etudiants WHERE niveau LIKE ? AND annee_scolaire LIKE ?'
|
|
||||||
)
|
|
||||||
const parcourMatiereQuery = database.prepare(
|
|
||||||
'SELECT * FROM parcoursmatiere INNER JOIN parcours ON (parcoursmatiere.parcour_id = parcours.id) WHERE parcoursmatiere.matiere_id = ?'
|
|
||||||
)
|
|
||||||
|
|
||||||
|
const connection = await pool.getConnection()
|
||||||
try {
|
try {
|
||||||
let matiereSemestre = query.all(matiere_id)
|
await connection.beginTransaction()
|
||||||
|
|
||||||
|
// Get semestre and mention
|
||||||
|
const [matiereSemestre] = await connection.query(
|
||||||
|
`
|
||||||
|
SELECT matiere_semestre.semestre_id, matiere_semestre.mention_id, semestres.*
|
||||||
|
FROM matiere_semestre
|
||||||
|
INNER JOIN semestres ON matiere_semestre.semestre_id = semestres.id
|
||||||
|
WHERE matiere_semestre.matiere_id = ?
|
||||||
|
`,
|
||||||
|
[matiere_id]
|
||||||
|
)
|
||||||
|
|
||||||
|
// Get parcours
|
||||||
|
const [parcours] = await connection.query(
|
||||||
|
`
|
||||||
|
SELECT * FROM parcoursmatiere
|
||||||
|
INNER JOIN parcours ON parcoursmatiere.parcour_id = parcours.id
|
||||||
|
WHERE parcoursmatiere.matiere_id = ?
|
||||||
|
`,
|
||||||
|
[matiere_id]
|
||||||
|
)
|
||||||
|
|
||||||
let response = []
|
let response = []
|
||||||
let allSTudent = []
|
|
||||||
let allMention_id = []
|
let allMention_id = []
|
||||||
let realSponse = []
|
|
||||||
let now = dayjs().format('YYYY')
|
|
||||||
|
|
||||||
realSponse = await database.transaction(async () => {
|
for (let index = 0; index < matiereSemestre.length; index++) {
|
||||||
let parcours = parcourMatiereQuery.all(Number(matiere_id))
|
response.push(await matiereSystemReverse(matiereSemestre[index].nom))
|
||||||
for (let index = 0; index < matiereSemestre.length; index++) {
|
allMention_id.push(matiereSemestre[index].mention_id)
|
||||||
response.push(await matiereSystemReverse(matiereSemestre[index].nom))
|
}
|
||||||
allMention_id.push(matiereSemestre[index].mention_id)
|
|
||||||
|
// Remove duplicates
|
||||||
|
let newResponse = []
|
||||||
|
for (let index = 0; index < response.length; index++) {
|
||||||
|
if (response[index] !== response[index + 1]) {
|
||||||
|
newResponse.push(response[index])
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let newResponse = []
|
// Get all students for the matched niveau and school year
|
||||||
for (let index = 0; index < response.length; index++) {
|
let allStudents = []
|
||||||
if (response[index] != response[index + 1]) {
|
for (let index = 0; index < newResponse.length; index++) {
|
||||||
newResponse.push(response[index])
|
const [students] = await connection.query(
|
||||||
}
|
`
|
||||||
}
|
SELECT * FROM etudiants
|
||||||
|
WHERE niveau LIKE ? AND annee_scolaire LIKE ?
|
||||||
|
`,
|
||||||
|
[`%${newResponse[index]}%`, `%${now}%`]
|
||||||
|
)
|
||||||
|
allStudents.push(...students)
|
||||||
|
}
|
||||||
|
|
||||||
for (let index = 0; index < newResponse.length; index++) {
|
// Filter students by mention
|
||||||
allSTudent = allStudentQuery.all(`%${newResponse[index]}%`, `%${now}%`)
|
const studentFiltredMention = allStudents.filter((etudiant) =>
|
||||||
}
|
allMention_id.includes(etudiant.mention_id)
|
||||||
|
)
|
||||||
|
|
||||||
let studentFiltredMention = []
|
// Filter by parcours
|
||||||
for (let index = 0; index < allSTudent.length; index++) {
|
let allData = []
|
||||||
if (allMention_id.includes(allSTudent[index].mention_id)) {
|
|
||||||
studentFiltredMention.push(allSTudent[index])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let allData = []
|
|
||||||
|
|
||||||
for (let j = 0; j < parcours.length; j++) {
|
for (let j = 0; j < parcours.length; j++) {
|
||||||
for (let index = 0; index < studentFiltredMention.length; index++) {
|
for (let index = 0; index < studentFiltredMention.length; index++) {
|
||||||
if (parcours[j].parcour_id == 1) {
|
const currentStudent = studentFiltredMention[index]
|
||||||
if (
|
const parcoursName = parcours[j].nom
|
||||||
studentFiltredMention[index].parcours == null ||
|
const parcour_id = parcours[j].parcour_id
|
||||||
studentFiltredMention[index].parcours == parcours[j].nom
|
|
||||||
) {
|
if (parcour_id == 1) {
|
||||||
allData.push(studentFiltredMention[index])
|
if (currentStudent.parcours == null || currentStudent.parcours == parcoursName) {
|
||||||
}
|
allData.push(currentStudent)
|
||||||
} else {
|
}
|
||||||
if (studentFiltredMention[index].parcours == parcours[j].nom) {
|
} else {
|
||||||
allData.push(studentFiltredMention[index])
|
if (currentStudent.parcours == parcoursName) {
|
||||||
}
|
allData.push(currentStudent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return allData
|
await connection.commit()
|
||||||
})()
|
connection.release()
|
||||||
|
return allData
|
||||||
return realSponse
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error
|
await connection.rollback()
|
||||||
|
connection.release()
|
||||||
|
console.error(error)
|
||||||
|
return { success: false, error: error.message }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
const { database } = require('../database')
|
const { database } = require('../database.backup')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* function to return all status
|
* function to return all status
|
||||||
|
|||||||
149
database/Models/Users.backup.js
Normal file
149
database/Models/Users.backup.js
Normal file
@ -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
|
||||||
}
|
|
||||||
|
|
||||||
// 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) {
|
} catch (error) {
|
||||||
console.error('Error updating user:', error)
|
return { success: false, error: error }
|
||||||
throw error // Throw error to handle it in calling function if needed
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* function to get all users
|
||||||
|
* @returns {Array}
|
||||||
|
*/
|
||||||
|
async function getAllUsers() {
|
||||||
|
const sql = `SELECT * FROM users`
|
||||||
|
|
||||||
|
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])
|
||||||
|
|
||||||
|
if (rows.length > 0) {
|
||||||
|
return rows[0]
|
||||||
|
} else {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* function used when users try to log in
|
||||||
|
* @param {String} username
|
||||||
|
* @param {String} password
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
|
async function loginUsers(username, password) {
|
||||||
|
const sql = `SELECT * FROM users WHERE LOWER(username) = ?`
|
||||||
|
|
||||||
|
try {
|
||||||
|
const [rows] = await pool.query(sql, [username.toLowerCase()])
|
||||||
|
|
||||||
|
if (rows.length === 0) {
|
||||||
|
return { success: false, error: 'Utilisateur inexistant' }
|
||||||
|
}
|
||||||
|
|
||||||
|
const user = rows[0]
|
||||||
|
|
||||||
|
// compare the password
|
||||||
|
const passwordMatch = await bcrypt.compare(password, user.password)
|
||||||
|
|
||||||
|
if (!passwordMatch) {
|
||||||
|
return { success: false, error: 'Mot de passe incorrect' }
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 update users
|
||||||
|
* @param {String} username
|
||||||
|
* @param {String} email
|
||||||
|
* @param {String} password
|
||||||
|
* @param {String} roles
|
||||||
|
* @param {Number} id
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
|
async function updateUser(username, email, password, roles, id) {
|
||||||
|
let sql, params
|
||||||
|
|
||||||
|
if (password !== null) {
|
||||||
|
const hashedPassword = await bcrypt.hash(password, 10)
|
||||||
|
sql = `UPDATE users SET username = ?, email = ?, password = ?, roles = ? WHERE id = ?`
|
||||||
|
params = [username, email, hashedPassword, roles, id]
|
||||||
|
} else {
|
||||||
|
sql = `UPDATE users SET username = ?, email = ?, roles = ? WHERE id = ?`
|
||||||
|
params = [username, email, roles, id]
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const [result] = await pool.query(sql, params)
|
||||||
|
|
||||||
|
if (result.affectedRows === 0) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: 'Utilisateur non trouvé ou aucune modification effectuée.'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: 'Utilisateur mis à jour avec succès.'
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
return { success: false, error: 'Erreur veullez réeseyer' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* function to delete users
|
||||||
|
* @param {Number} id
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
|
async function deleteUser(id) {
|
||||||
|
const sql = `DELETE FROM users WHERE id = ?`
|
||||||
|
|
||||||
|
try {
|
||||||
|
const [result] = await pool.query(sql, [id])
|
||||||
|
|
||||||
|
if (result.affectedRows === 0) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: 'Utilisateur non trouvé.'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: 'Utilisateur supprimé avec succès.'
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
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
|
||||||
}
|
}
|
||||||
|
|||||||
444
database/database.backup.js
Normal file
444
database/database.backup.js
Normal file
@ -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
|
|
||||||
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 {
|
try {
|
||||||
let arraySemestre = [
|
// Users table
|
||||||
'S1',
|
await connection.query(`
|
||||||
'S2',
|
CREATE TABLE IF NOT EXISTS users (
|
||||||
'S3',
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
'S4',
|
username VARCHAR(200) NOT NULL,
|
||||||
'S5',
|
email VARCHAR(250) NOT NULL UNIQUE,
|
||||||
'S6',
|
password TEXT NOT NULL,
|
||||||
'S7',
|
roles VARCHAR(250) NOT NULL,
|
||||||
'S8',
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
'S9',
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||||
'S10',
|
) ENGINE=InnoDB;
|
||||||
'S11',
|
`)
|
||||||
'S12',
|
|
||||||
'S13',
|
|
||||||
'S14',
|
|
||||||
'S14',
|
|
||||||
'S16'
|
|
||||||
]
|
|
||||||
// Vérification si une entrée existe déjà
|
|
||||||
const result = checkSemestreQuery.get()
|
|
||||||
|
|
||||||
if (result.count === 0) {
|
// Status table
|
||||||
database.transaction(() => {
|
await connection.query(`
|
||||||
for (let index = 0; index < arraySemestre.length; index++) {
|
CREATE TABLE IF NOT EXISTS status (
|
||||||
query.run(arraySemestre[index])
|
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) UNIQUE 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 UNIQUE NOT NULL,
|
||||||
|
sexe VARCHAR(20) DEFAULT NULL,
|
||||||
|
cin VARCHAR(250) DEFAULT NULL,
|
||||||
|
date_delivrance DATE DEFAULT NULL,
|
||||||
|
nationalite DATE DEFAULT NULL,
|
||||||
|
annee_bacc DATE DEFAULT NULL,
|
||||||
|
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']
|
||||||
|
)
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} finally {
|
||||||
console.log(error)
|
conn.release()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const createNecessaryParameterTable = () => {
|
async function insertStatusesIfNotExist() {
|
||||||
// Check if the table is empty
|
const conn = await pool.getConnection()
|
||||||
const rowCount = database.prepare(`SELECT COUNT(*) AS count FROM nessesaryTable`).get().count
|
try {
|
||||||
|
const statuses = ['Nouveau', 'Passant', 'Redoublant', 'Renvoyé', 'Ancien']
|
||||||
// If the table is empty, insert the default value
|
for (let name of statuses) {
|
||||||
if (rowCount === 0) {
|
const [rows] = await conn.query(`SELECT COUNT(*) as count FROM status WHERE nom = ?`, [name])
|
||||||
const insertDefaultQuery = `
|
if (rows[0].count === 0) {
|
||||||
INSERT INTO nessesaryTable (uniter_heure) VALUES (15);
|
await conn.query(`INSERT INTO status (nom) VALUES (?)`, [name])
|
||||||
`
|
}
|
||||||
database.prepare(insertDefaultQuery).run()
|
}
|
||||||
|
} finally {
|
||||||
|
conn.release()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
}
|
}
|
||||||
|
|||||||
307
database/database2.js
Normal file
307
database/database2.js
Normal file
@ -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
|
||||||
|
}
|
||||||
@ -1,261 +1,261 @@
|
|||||||
const { database } = require('../database')
|
const { pool } = require('../database')
|
||||||
const dayjs = require('dayjs')
|
const dayjs = require('dayjs')
|
||||||
|
|
||||||
async function updateCurrentYears() {
|
async function updateCurrentYears() {
|
||||||
const fullDate = dayjs().format('YYYY-MM-DD')
|
const fullDate = dayjs().format('YYYY-MM-DD')
|
||||||
|
|
||||||
// Clear current year flag
|
// Clear current year flag
|
||||||
const clearCurrent = database.prepare('UPDATE anneescolaire SET is_Current = 0 WHERE id > 0')
|
const clearCurrent = 'UPDATE anneescolaire SET is_Current = 0 WHERE id > 0'
|
||||||
clearCurrent.run()
|
pool.query(clearCurrent)
|
||||||
|
|
||||||
// Set the new current year
|
// Set the new current year
|
||||||
const updateCurrent = database.prepare(`
|
const updateCurrent = `
|
||||||
UPDATE anneescolaire
|
UPDATE anneescolaire
|
||||||
SET is_Current = 1
|
SET is_Current = 1
|
||||||
WHERE ? >= debut AND ? <= fin
|
WHERE ? >= debut AND ? <= fin
|
||||||
`)
|
`
|
||||||
// console.log();
|
// console.log();
|
||||||
updateCurrent.run(fullDate, fullDate)
|
pool.query(updateCurrent, [fullDate, fullDate])
|
||||||
|
|
||||||
// Check if the update was successful
|
// Check if the update was successful
|
||||||
const check = database
|
const sql = `
|
||||||
.prepare(
|
SELECT * FROM anneescolaire
|
||||||
`
|
WHERE ? >= debut AND ? <= fin
|
||||||
SELECT * FROM anneescolaire
|
`
|
||||||
WHERE ? >= debut AND ? <= fin
|
const [rows] = await pool.query(sql, [fullDate, fullDate])
|
||||||
`
|
|
||||||
)
|
|
||||||
.get(fullDate, fullDate)
|
|
||||||
|
|
||||||
// Insert into traitmentsystem if a current year exists
|
const check = rows[0]
|
||||||
if (check) {
|
if (!check) return
|
||||||
let search = database.prepare('SELECT * FROM traitmentsystem WHERE code = ?').get(check.code)
|
|
||||||
console.log(search)
|
// 2. Check if already in traitmentsystem
|
||||||
if (!search) {
|
const searchSql = `SELECT * FROM traitmentsystem WHERE code = ?`
|
||||||
const insertQuery = database.prepare(`
|
const [searchRows] = await pool.query(searchSql, [check.code])
|
||||||
|
|
||||||
|
if (searchRows.length === 0) {
|
||||||
|
// 3. Insert into traitmentsystem
|
||||||
|
const insertSql = `
|
||||||
INSERT INTO traitmentsystem (code, debut, fin)
|
INSERT INTO traitmentsystem (code, debut, fin)
|
||||||
VALUES (?, ?, ?)
|
VALUES (?, ?, ?)
|
||||||
`)
|
`
|
||||||
insertQuery.run(check.code, check.debut, check.fin)
|
await pool.query(insertSql, [check.code, check.debut, check.fin])
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
console.log('No active school year found for the current date.')
|
console.log('No active school year found for the current date.')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateStudents() {
|
// async function updateStudents() {
|
||||||
const getInfinishedYears = database
|
// const getInfinishedYears = database
|
||||||
.prepare('SELECT * FROM traitmentsystem WHERE is_finished = 0 ORDER BY id ASC')
|
// .prepare('SELECT * FROM traitmentsystem WHERE is_finished = 0 ORDER BY id ASC')
|
||||||
.get()
|
// .get()
|
||||||
|
|
||||||
const allEtudiants = database
|
// const allEtudiants = database
|
||||||
.prepare('SELECT * FROM etudiants WHERE annee_scolaire = ?')
|
// .prepare('SELECT * FROM etudiants WHERE annee_scolaire = ?')
|
||||||
.all(getInfinishedYears.code)
|
// .all(getInfinishedYears.code)
|
||||||
|
|
||||||
function checkNull(params) {
|
// function checkNull(params) {
|
||||||
if (params == null || params == undefined) {
|
// if (params == null || params == undefined) {
|
||||||
return null
|
// return null
|
||||||
}
|
// }
|
||||||
return params
|
// return params
|
||||||
}
|
// }
|
||||||
|
|
||||||
function compareSessionNotes(session1, session2) {
|
// function compareSessionNotes(session1, session2) {
|
||||||
let notes
|
// let notes
|
||||||
if (session2) {
|
// if (session2) {
|
||||||
if (session1 < session2.note) {
|
// if (session1 < session2.note) {
|
||||||
notes = session2.note
|
// notes = session2.note
|
||||||
} else {
|
// } else {
|
||||||
notes = session1
|
// notes = session1
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
notes = session1
|
// notes = session1
|
||||||
}
|
// }
|
||||||
return notes
|
// return notes
|
||||||
}
|
// }
|
||||||
|
|
||||||
database.transaction(() => {
|
// database.transaction(() => {
|
||||||
// get all note of student
|
// // get all note of student
|
||||||
const queryNotes = database.prepare(
|
// const queryNotes = database.prepare(
|
||||||
`SELECT DISTINCT etudiant_id FROM notes WHERE etudiant_niveau = ? AND annee_scolaire = ?`
|
// `SELECT DISTINCT etudiant_id FROM notes WHERE etudiant_niveau = ? AND annee_scolaire = ?`
|
||||||
)
|
// )
|
||||||
let allEtudiantWithNotes = []
|
// let allEtudiantWithNotes = []
|
||||||
let etudiantWithNotes = []
|
// let etudiantWithNotes = []
|
||||||
let dataToMap = []
|
// let dataToMap = []
|
||||||
let allEtudiantWithNotesRepech = []
|
// let allEtudiantWithNotesRepech = []
|
||||||
let etudiantWithNotesRepech = []
|
// let etudiantWithNotesRepech = []
|
||||||
|
|
||||||
for (const etudiant of allEtudiants) {
|
// for (const etudiant of allEtudiants) {
|
||||||
const results = queryNotes.all(etudiant.niveau, etudiant.annee_scolaire)
|
// const results = queryNotes.all(etudiant.niveau, etudiant.annee_scolaire)
|
||||||
etudiantWithNotes.push(...results) // Avoid nested arrays
|
// etudiantWithNotes.push(...results) // Avoid nested arrays
|
||||||
}
|
// }
|
||||||
|
|
||||||
const uniqueId = etudiantWithNotes.filter(
|
// const uniqueId = etudiantWithNotes.filter(
|
||||||
(item, index, self) => index === self.findIndex((t) => t.etudiant_id === item.etudiant_id)
|
// (item, index, self) => index === self.findIndex((t) => t.etudiant_id === item.etudiant_id)
|
||||||
)
|
// )
|
||||||
|
|
||||||
const query2 = database.prepare(
|
// const query2 = database.prepare(
|
||||||
'SELECT notes.*, etudiants.*, matieres.id, matieres.nom AS nomMat, matieres.credit FROM notes LEFT JOIN etudiants ON (notes.etudiant_id = etudiants.id) LEFT JOIN matieres ON (notes.matiere_id = matieres.id) WHERE notes.etudiant_id = ?'
|
// 'SELECT notes.*, etudiants.*, matieres.id, matieres.nom AS nomMat, matieres.credit FROM notes LEFT JOIN etudiants ON (notes.etudiant_id = etudiants.id) LEFT JOIN matieres ON (notes.matiere_id = matieres.id) WHERE notes.etudiant_id = ?'
|
||||||
)
|
// )
|
||||||
|
|
||||||
for (let j = 0; j < uniqueId.length; j++) {
|
// for (let j = 0; j < uniqueId.length; j++) {
|
||||||
allEtudiantWithNotes.push(query2.all(uniqueId[j].etudiant_id))
|
// allEtudiantWithNotes.push(query2.all(uniqueId[j].etudiant_id))
|
||||||
}
|
// }
|
||||||
|
|
||||||
const query = database.prepare(
|
// const query = database.prepare(
|
||||||
`SELECT DISTINCT etudiant_id FROM notesrepech WHERE etudiant_niveau = ? AND annee_scolaire = ?`
|
// `SELECT DISTINCT etudiant_id FROM notesrepech WHERE etudiant_niveau = ? AND annee_scolaire = ?`
|
||||||
)
|
// )
|
||||||
|
|
||||||
for (const etudiant of allEtudiants) {
|
// for (const etudiant of allEtudiants) {
|
||||||
const results = query.all(etudiant.niveau, etudiant.annee_scolaire)
|
// const results = query.all(etudiant.niveau, etudiant.annee_scolaire)
|
||||||
etudiantWithNotesRepech.push(...results) // Avoid nested arrays
|
// etudiantWithNotesRepech.push(...results) // Avoid nested arrays
|
||||||
}
|
// }
|
||||||
|
|
||||||
const uniqueIdRepech = etudiantWithNotes.filter(
|
// const uniqueIdRepech = etudiantWithNotes.filter(
|
||||||
(item, index, self) => index === self.findIndex((t) => t.etudiant_id === item.etudiant_id)
|
// (item, index, self) => index === self.findIndex((t) => t.etudiant_id === item.etudiant_id)
|
||||||
)
|
// )
|
||||||
|
|
||||||
const query2Repech = database.prepare(
|
// const query2Repech = database.prepare(
|
||||||
'SELECT notesrepech.*, etudiants.*, matieres.id, matieres.nom AS nomMat, matieres.credit FROM notesrepech INNER JOIN etudiants ON (notesrepech.etudiant_id = etudiants.id) INNER JOIN matieres ON (notesrepech.matiere_id = matieres.id) WHERE notesrepech.etudiant_id = ?'
|
// 'SELECT notesrepech.*, etudiants.*, matieres.id, matieres.nom AS nomMat, matieres.credit FROM notesrepech INNER JOIN etudiants ON (notesrepech.etudiant_id = etudiants.id) INNER JOIN matieres ON (notesrepech.matiere_id = matieres.id) WHERE notesrepech.etudiant_id = ?'
|
||||||
)
|
// )
|
||||||
|
|
||||||
for (let j = 0; j < uniqueIdRepech.length; j++) {
|
// for (let j = 0; j < uniqueIdRepech.length; j++) {
|
||||||
allEtudiantWithNotesRepech.push(query2Repech.all(uniqueIdRepech[j].etudiant_id))
|
// allEtudiantWithNotesRepech.push(query2Repech.all(uniqueIdRepech[j].etudiant_id))
|
||||||
}
|
// }
|
||||||
|
|
||||||
for (let index = 0; index < allEtudiantWithNotes.length; index++) {
|
// for (let index = 0; index < allEtudiantWithNotes.length; index++) {
|
||||||
let total = 0
|
// let total = 0
|
||||||
let note = 0
|
// let note = 0
|
||||||
let totalCredit = 0
|
// let totalCredit = 0
|
||||||
|
|
||||||
// Create a new object for each student
|
// // Create a new object for each student
|
||||||
let modelJson = {
|
// let modelJson = {
|
||||||
id: '',
|
// id: '',
|
||||||
nom: '',
|
// nom: '',
|
||||||
prenom: '',
|
// prenom: '',
|
||||||
photos: '',
|
// photos: '',
|
||||||
moyenne: '',
|
// moyenne: '',
|
||||||
mention: '',
|
// mention: '',
|
||||||
niveau: '',
|
// niveau: '',
|
||||||
annee_scolaire: ''
|
// annee_scolaire: ''
|
||||||
}
|
// }
|
||||||
|
|
||||||
for (let j = 0; j < allEtudiantWithNotes[index].length; j++) {
|
// for (let j = 0; j < allEtudiantWithNotes[index].length; j++) {
|
||||||
modelJson.id = allEtudiantWithNotes[index][j].etudiant_id
|
// modelJson.id = allEtudiantWithNotes[index][j].etudiant_id
|
||||||
modelJson.nom = allEtudiantWithNotes[index][j].nom
|
// modelJson.nom = allEtudiantWithNotes[index][j].nom
|
||||||
modelJson.prenom = allEtudiantWithNotes[index][j].prenom
|
// modelJson.prenom = allEtudiantWithNotes[index][j].prenom
|
||||||
modelJson.photos = allEtudiantWithNotes[index][j].photos
|
// modelJson.photos = allEtudiantWithNotes[index][j].photos
|
||||||
modelJson.mention = allEtudiantWithNotes[index][j].mention_id
|
// modelJson.mention = allEtudiantWithNotes[index][j].mention_id
|
||||||
modelJson.niveau = allEtudiantWithNotes[index][j].niveau
|
// modelJson.niveau = allEtudiantWithNotes[index][j].niveau
|
||||||
modelJson.annee_scolaire = allEtudiantWithNotes[index][j].annee_scolaire
|
// modelJson.annee_scolaire = allEtudiantWithNotes[index][j].annee_scolaire
|
||||||
|
|
||||||
// console.log(checkNull(session[index][j]));
|
// // console.log(checkNull(session[index][j]));
|
||||||
if (allEtudiantWithNotesRepech[index]) {
|
// if (allEtudiantWithNotesRepech[index]) {
|
||||||
note +=
|
// note +=
|
||||||
compareSessionNotes(
|
// compareSessionNotes(
|
||||||
allEtudiantWithNotes[index][j].note,
|
// allEtudiantWithNotes[index][j].note,
|
||||||
checkNull(allEtudiantWithNotesRepech[index][j])
|
// checkNull(allEtudiantWithNotesRepech[index][j])
|
||||||
) * allEtudiantWithNotes[index][j].credit
|
// ) * allEtudiantWithNotes[index][j].credit
|
||||||
} else {
|
// } else {
|
||||||
note += allEtudiantWithNotes[index][j].note * allEtudiantWithNotes[index][j].credit
|
// note += allEtudiantWithNotes[index][j].note * allEtudiantWithNotes[index][j].credit
|
||||||
}
|
// }
|
||||||
totalCredit += allEtudiantWithNotes[index][j].credit
|
// totalCredit += allEtudiantWithNotes[index][j].credit
|
||||||
}
|
// }
|
||||||
|
|
||||||
total = note / totalCredit
|
// total = note / totalCredit
|
||||||
modelJson.moyenne = total.toFixed(2)
|
// modelJson.moyenne = total.toFixed(2)
|
||||||
|
|
||||||
// Add the new object to the array
|
// // Add the new object to the array
|
||||||
dataToMap.push(modelJson)
|
// dataToMap.push(modelJson)
|
||||||
}
|
// }
|
||||||
|
|
||||||
// update all etudiant
|
// // update all etudiant
|
||||||
let updated = false
|
// let updated = false
|
||||||
if (dataToMap.length != 0) {
|
// if (dataToMap.length != 0) {
|
||||||
let noteSystem = database.prepare('SELECT * FROM notesystems').get()
|
// let noteSystem = database.prepare('SELECT * FROM notesystems').get()
|
||||||
for (let index = 0; index < dataToMap.length; index++) {
|
// for (let index = 0; index < dataToMap.length; index++) {
|
||||||
if (dataToMap[index].moyenne >= noteSystem.admis) {
|
// if (dataToMap[index].moyenne >= noteSystem.admis) {
|
||||||
let updateQuery = database.prepare(
|
// let updateQuery = database.prepare(
|
||||||
'UPDATE etudiants SET niveau = ?, annee_scolaire = ?, status = ? WHERE id = ?'
|
// 'UPDATE etudiants SET niveau = ?, annee_scolaire = ?, status = ? WHERE id = ?'
|
||||||
)
|
// )
|
||||||
updateQuery.run(
|
// updateQuery.run(
|
||||||
nextLevel(dataToMap[index].niveau),
|
// nextLevel(dataToMap[index].niveau),
|
||||||
updateSchoolYear(dataToMap[index].annee_scolaire),
|
// updateSchoolYear(dataToMap[index].annee_scolaire),
|
||||||
2,
|
// 2,
|
||||||
dataToMap[index].id
|
// dataToMap[index].id
|
||||||
)
|
// )
|
||||||
updated = true
|
// updated = true
|
||||||
} else if (
|
// } else if (
|
||||||
dataToMap[index].moyenne < noteSystem.admis &&
|
// dataToMap[index].moyenne < noteSystem.admis &&
|
||||||
dataToMap[index].moyenne >= noteSystem.redouble
|
// dataToMap[index].moyenne >= noteSystem.redouble
|
||||||
) {
|
// ) {
|
||||||
let updateQuery = database.prepare(
|
// let updateQuery = database.prepare(
|
||||||
'UPDATE etudiants SET niveau = ?, annee_scolaire = ? status = ? WHERE id = ?'
|
// 'UPDATE etudiants SET niveau = ?, annee_scolaire = ? status = ? WHERE id = ?'
|
||||||
)
|
// )
|
||||||
updateQuery.run(
|
// updateQuery.run(
|
||||||
dataToMap[index].niveau,
|
// dataToMap[index].niveau,
|
||||||
updateSchoolYear(dataToMap[index].annee_scolaire),
|
// updateSchoolYear(dataToMap[index].annee_scolaire),
|
||||||
3,
|
// 3,
|
||||||
dataToMap[index].id
|
// dataToMap[index].id
|
||||||
)
|
// )
|
||||||
updated = true
|
// updated = true
|
||||||
} else {
|
// } else {
|
||||||
let updateQuery = database.prepare(
|
// let updateQuery = database.prepare(
|
||||||
'UPDATE etudiants SET niveau = ?, annee_scolaire = ? status = ? WHERE id = ?'
|
// 'UPDATE etudiants SET niveau = ?, annee_scolaire = ? status = ? WHERE id = ?'
|
||||||
)
|
// )
|
||||||
updateQuery.run(
|
// updateQuery.run(
|
||||||
dataToMap[index].niveau,
|
// dataToMap[index].niveau,
|
||||||
dataToMap[index].annee_scolaire,
|
// dataToMap[index].annee_scolaire,
|
||||||
4,
|
// 4,
|
||||||
dataToMap[index].id
|
// dataToMap[index].id
|
||||||
)
|
// )
|
||||||
updated = true
|
// updated = true
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (updated) {
|
// if (updated) {
|
||||||
const updateInfinishedYears = database.prepare(
|
// const updateInfinishedYears = database.prepare(
|
||||||
'UPDATE traitmentsystem SET is_finished = 1 WHERE id = ?'
|
// 'UPDATE traitmentsystem SET is_finished = 1 WHERE id = ?'
|
||||||
)
|
// )
|
||||||
|
|
||||||
updateInfinishedYears.run(getInfinishedYears.id)
|
// updateInfinishedYears.run(getInfinishedYears.id)
|
||||||
}
|
// }
|
||||||
})()
|
// })()
|
||||||
}
|
// }
|
||||||
|
|
||||||
function nextLevel(niveau) {
|
// function nextLevel(niveau) {
|
||||||
if (niveau == 'L1') {
|
// if (niveau == 'L1') {
|
||||||
return 'L2'
|
// return 'L2'
|
||||||
} else if (niveau == 'L2') {
|
// } else if (niveau == 'L2') {
|
||||||
return 'L3'
|
// return 'L3'
|
||||||
} else if (niveau == 'L3') {
|
// } else if (niveau == 'L3') {
|
||||||
return 'M1'
|
// return 'M1'
|
||||||
} else if (niveau == 'M1') {
|
// } else if (niveau == 'M1') {
|
||||||
return 'M2'
|
// return 'M2'
|
||||||
} else if (niveau == 'M2') {
|
// } else if (niveau == 'M2') {
|
||||||
return 'D1'
|
// return 'D1'
|
||||||
} else if (niveau == 'D1') {
|
// } else if (niveau == 'D1') {
|
||||||
return 'D2'
|
// return 'D2'
|
||||||
} else if (niveau == 'D2') {
|
// } else if (niveau == 'D2') {
|
||||||
return 'D3'
|
// return 'D3'
|
||||||
} else if (niveau == 'D3') {
|
// } else if (niveau == 'D3') {
|
||||||
return 'PHD'
|
// return 'PHD'
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
function updateSchoolYear(year) {
|
// function updateSchoolYear(year) {
|
||||||
// Split the year into two parts
|
// // Split the year into two parts
|
||||||
const [startYear, endYear] = year.split('-').map(Number)
|
// const [startYear, endYear] = year.split('-').map(Number)
|
||||||
|
|
||||||
// Increment both the start and end year by 1
|
// // Increment both the start and end year by 1
|
||||||
const newStartYear = startYear + 1
|
// const newStartYear = startYear + 1
|
||||||
const newEndYear = endYear + 1
|
// const newEndYear = endYear + 1
|
||||||
|
|
||||||
// Join the new years with a hyphen
|
// // Join the new years with a hyphen
|
||||||
const newYear = `${newStartYear}-${newEndYear}`
|
// const newYear = `${newStartYear}-${newEndYear}`
|
||||||
|
|
||||||
return newYear
|
// return newYear
|
||||||
}
|
// }
|
||||||
|
|
||||||
async function matiereSysteme(etudiant_niveau) {
|
async function matiereSysteme(etudiant_niveau) {
|
||||||
let systeme
|
let systeme
|
||||||
@ -300,33 +300,33 @@ async function matiereSystemReverse(semestre) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getNessesarytable() {
|
// async function getNessesarytable() {
|
||||||
try {
|
// try {
|
||||||
const query = await database.prepare('SELECT * FROM nessesaryTable').get()
|
// const query = await database.prepare('SELECT * FROM nessesaryTable').get()
|
||||||
|
|
||||||
return query
|
// return query
|
||||||
} catch (error) {
|
// } catch (error) {
|
||||||
return error
|
// return error
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
async function updateNessesaryTable(id, multiplicateur) {
|
// async function updateNessesaryTable(id, multiplicateur) {
|
||||||
const query = database.prepare('UPDATE nessesaryTable SET uniter_heure = ? WHERE id = ?')
|
// const query = database.prepare('UPDATE nessesaryTable SET uniter_heure = ? WHERE id = ?')
|
||||||
|
|
||||||
try {
|
// try {
|
||||||
let update = query.run(multiplicateur, id)
|
// let update = query.run(multiplicateur, id)
|
||||||
|
|
||||||
return update
|
// return update
|
||||||
} catch (error) {
|
// } catch (error) {
|
||||||
return error
|
// return error
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
matiereSysteme,
|
matiereSysteme,
|
||||||
updateCurrentYears,
|
updateCurrentYears,
|
||||||
updateStudents,
|
// updateStudents,
|
||||||
getNessesarytable,
|
// getNessesarytable,
|
||||||
updateNessesaryTable,
|
// updateNessesaryTable,
|
||||||
matiereSystemReverse
|
matiereSystemReverse
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,7 @@ const path = require('path')
|
|||||||
const XLSX = require('xlsx')
|
const XLSX = require('xlsx')
|
||||||
const { parse } = require('csv-parse/sync')
|
const { parse } = require('csv-parse/sync')
|
||||||
const { createMatiere } = require('../Models/Matieres')
|
const { createMatiere } = require('../Models/Matieres')
|
||||||
const { database } = require('../database')
|
const { database } = require('../database.backup')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to import data from the first column of an XLSX or CSV file into SQLite database
|
* Function to import data from the first column of an XLSX or CSV file into SQLite database
|
||||||
|
|||||||
15
jsconfig.json
Normal file
15
jsconfig.json
Normal file
@ -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/*"
|
||||||
|
]
|
||||||
|
}
|
||||||
@ -10,6 +10,7 @@
|
|||||||
"lint": "eslint . --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix",
|
"lint": "eslint . --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix",
|
||||||
"start": "electron-vite preview",
|
"start": "electron-vite preview",
|
||||||
"dev": "electron-vite dev",
|
"dev": "electron-vite dev",
|
||||||
|
"test": "electronmon --exec",
|
||||||
"build": "electron-vite build",
|
"build": "electron-vite build",
|
||||||
"postinstall": "electron-builder install-app-deps",
|
"postinstall": "electron-builder install-app-deps",
|
||||||
"build:unpack": "npm run build && electron-builder --dir",
|
"build:unpack": "npm run build && electron-builder --dir",
|
||||||
@ -36,6 +37,7 @@
|
|||||||
"@emotion/styled": "^11.13.0",
|
"@emotion/styled": "^11.13.0",
|
||||||
"@mui/material": "^6.1.1",
|
"@mui/material": "^6.1.1",
|
||||||
"@mui/x-data-grid": "^7.18.0",
|
"@mui/x-data-grid": "^7.18.0",
|
||||||
|
"@tanstack/react-query": "^5.83.0",
|
||||||
"ag-psd": "^22.0.2",
|
"ag-psd": "^22.0.2",
|
||||||
"axios": "^1.9.0",
|
"axios": "^1.9.0",
|
||||||
"bcryptjs": "^2.4.3",
|
"bcryptjs": "^2.4.3",
|
||||||
@ -52,6 +54,7 @@
|
|||||||
"html2canvas": "^1.4.1",
|
"html2canvas": "^1.4.1",
|
||||||
"jspdf": "^2.5.2",
|
"jspdf": "^2.5.2",
|
||||||
"jspdf-autotable": "^5.0.2",
|
"jspdf-autotable": "^5.0.2",
|
||||||
|
"mysql2": "^3.14.2",
|
||||||
"papaparse": "^5.4.1",
|
"papaparse": "^5.4.1",
|
||||||
"pdf-lib": "^1.17.1",
|
"pdf-lib": "^1.17.1",
|
||||||
"qrcode": "^1.5.4",
|
"qrcode": "^1.5.4",
|
||||||
@ -74,6 +77,7 @@
|
|||||||
"electron": "^31.0.2",
|
"electron": "^31.0.2",
|
||||||
"electron-builder": "^24.13.3",
|
"electron-builder": "^24.13.3",
|
||||||
"electron-vite": "^2.3.0",
|
"electron-vite": "^2.3.0",
|
||||||
|
"electronmon": "^2.0.3",
|
||||||
"eslint": "^8.57.0",
|
"eslint": "^8.57.0",
|
||||||
"eslint-plugin-react": "^7.34.3",
|
"eslint-plugin-react": "^7.34.3",
|
||||||
"npm": "^10.9.2",
|
"npm": "^10.9.2",
|
||||||
|
|||||||
@ -1,31 +1,121 @@
|
|||||||
import { app, shell, BrowserWindow, ipcMain, Tray } from 'electron'
|
import { app, shell, BrowserWindow, ipcMain, Tray, Menu } from 'electron'
|
||||||
import { join } from 'path'
|
import { join } from 'path'
|
||||||
|
const path = require('path')
|
||||||
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
|
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
|
||||||
import icon from '../../resources/icon.png?asset'
|
import icon from '../../resources/logo.ico?asset' // Your tray icon file
|
||||||
|
const database = require('../../database/database2')
|
||||||
|
|
||||||
|
database
|
||||||
|
.createTables()
|
||||||
|
.then(() => database.insertDefaultAdmin())
|
||||||
|
.then(() => database.insertStatusesIfNotExist())
|
||||||
|
.catch(console.error)
|
||||||
|
|
||||||
|
const { createConfigIp, updateIPConfig } = require('../../database/Models/IpConfig')
|
||||||
|
const { importFileToDatabase } = require('../../database/import/Etudiants')
|
||||||
const { loginUser, forgotPassword, insertUser, updateUser } = require('../../database/Models/Users')
|
const { loginUser, forgotPassword, insertUser, updateUser } = require('../../database/Models/Users')
|
||||||
const {
|
const {
|
||||||
insertEtudiant,
|
insertEtudiant,
|
||||||
getSingleEtudiant,
|
getSingleEtudiant,
|
||||||
FilterDataByNiveau,
|
FilterDataByNiveau,
|
||||||
updateEtudiant
|
updateEtudiant,
|
||||||
|
changePDP,
|
||||||
|
updateParcours,
|
||||||
|
createTranche,
|
||||||
|
getTranche,
|
||||||
|
updateTranche,
|
||||||
|
deleteTranche,
|
||||||
|
getSingleTranche
|
||||||
} = require('../../database/Models/Etudiants')
|
} = require('../../database/Models/Etudiants')
|
||||||
const { insertNiveau } = require('../../database/Models/Niveau')
|
const {
|
||||||
const { insertNote } = require('../../database/Models/Notes')
|
insertNiveau,
|
||||||
|
updateNiveau,
|
||||||
|
getSingleNiveau,
|
||||||
|
deleteNiveau
|
||||||
|
} = require('../../database/Models/Niveau')
|
||||||
|
const {
|
||||||
|
insertNote,
|
||||||
|
getNote,
|
||||||
|
updateNote,
|
||||||
|
showMoyen,
|
||||||
|
getMatiereAndNote,
|
||||||
|
getNotesWithRepechToDisplay
|
||||||
|
} = require('../../database/Models/Notes')
|
||||||
|
const {
|
||||||
|
createMatiere,
|
||||||
|
getSingleMatiere,
|
||||||
|
updateMatiere,
|
||||||
|
displayMatiereFromForm,
|
||||||
|
deleteMatiere,
|
||||||
|
asygnationToMention,
|
||||||
|
getMentionMatiere,
|
||||||
|
getMentionMatiereChecked,
|
||||||
|
getSemestreMatiere,
|
||||||
|
insertUpdateMentionSemestre,
|
||||||
|
insertNewProf,
|
||||||
|
getSIngleProf,
|
||||||
|
updateProf
|
||||||
|
} = require('../../database/Models/Matieres')
|
||||||
|
const { importFileToDatabaseMatiere } = require('../../database/import/Matieres')
|
||||||
|
const { importNiveau } = require('../../database/import/Niveau')
|
||||||
|
const { updateSysteme } = require('../../database/Models/NoteSysrem')
|
||||||
|
const {
|
||||||
|
createAnneeScolaire,
|
||||||
|
deleteAnneeScolaire,
|
||||||
|
getSingleAnneScolaire,
|
||||||
|
updateAnneeScolaire,
|
||||||
|
setCurrent
|
||||||
|
} = require('../../database/Models/AnneeScolaire')
|
||||||
|
const {
|
||||||
|
createMention,
|
||||||
|
deleteMention,
|
||||||
|
getSingleMention,
|
||||||
|
updateMention
|
||||||
|
} = require('../../database/Models/Mentions')
|
||||||
|
const {
|
||||||
|
getNoteRepech,
|
||||||
|
updateNoteRepech,
|
||||||
|
showMoyenRepech
|
||||||
|
} = require('../../database/Models/NoteRepechage')
|
||||||
|
const {
|
||||||
|
updateCurrentYears,
|
||||||
|
updateStudents,
|
||||||
|
updateNessesaryTable
|
||||||
|
} = require('../../database/function/System')
|
||||||
|
const { autoUpdater } = require('electron-updater')
|
||||||
|
const { URL } = require('../../database/api/Config')
|
||||||
|
const {
|
||||||
|
insertParcour,
|
||||||
|
getSingleParcours,
|
||||||
|
deletes,
|
||||||
|
updateparcour,
|
||||||
|
parcourMatiere,
|
||||||
|
extractFiche,
|
||||||
|
getParcourMatiere
|
||||||
|
} = require('../../database/Models/Parcours')
|
||||||
|
|
||||||
// declare mainWindow in the global scope
|
// Declare mainWindow and tray in the global scope
|
||||||
let mainWindow
|
let mainWindow
|
||||||
let tray = null
|
let tray = null
|
||||||
|
updateCurrentYears()
|
||||||
|
updateStudents()
|
||||||
|
|
||||||
|
autoUpdater.setFeedURL({
|
||||||
|
provider: 'generic',
|
||||||
|
url: `${URL}/latest` // Ensure this points to the folder containing latest.yml
|
||||||
|
})
|
||||||
|
|
||||||
function createWindow() {
|
function createWindow() {
|
||||||
// Create the browser window.
|
// Create the browser window.
|
||||||
mainWindow = new BrowserWindow({
|
mainWindow = new BrowserWindow({
|
||||||
width: 1000,
|
width: 1375,
|
||||||
minWidth: 1000,
|
minWidth: 1375,
|
||||||
height: 670,
|
height: 740,
|
||||||
minHeight: 670,
|
minHeight: 740,
|
||||||
show: false,
|
show: false,
|
||||||
autoHideMenuBar: true,
|
autoHideMenuBar: true,
|
||||||
fullscreen: true, // This will make the window fullscreen when opened
|
fullscreen: false,
|
||||||
|
icon: path.join(__dirname, 'resources', 'logo.ico'), // Path to your icon,
|
||||||
...(process.platform === 'linux' ? { icon } : {}),
|
...(process.platform === 'linux' ? { icon } : {}),
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
preload: join(__dirname, '../preload/index.js'),
|
preload: join(__dirname, '../preload/index.js'),
|
||||||
@ -35,7 +125,15 @@ function createWindow() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Désactiver les raccourcis clavier
|
||||||
|
mainWindow.webContents.on('before-input-event', (event, input) => {
|
||||||
|
if (input.control || input.meta || input.alt || input.key === 'F11') {
|
||||||
|
event.preventDefault()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
mainWindow.on('ready-to-show', () => {
|
mainWindow.on('ready-to-show', () => {
|
||||||
|
mainWindow.maximize() // Maximiser la fenêtre
|
||||||
mainWindow.show()
|
mainWindow.show()
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -44,44 +142,134 @@ function createWindow() {
|
|||||||
return { action: 'deny' }
|
return { action: 'deny' }
|
||||||
})
|
})
|
||||||
|
|
||||||
// HMR for renderer base on electron-vite cli.
|
// Load the appropriate URL based on environment
|
||||||
// Load the remote URL for development or the local html file for production.
|
|
||||||
if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
|
if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
|
||||||
mainWindow.loadURL(process.env['ELECTRON_RENDERER_URL'])
|
mainWindow.loadURL(process.env['ELECTRON_RENDERER_URL'])
|
||||||
} else {
|
} else {
|
||||||
mainWindow.loadFile(join(__dirname, '../renderer/index.html'))
|
mainWindow.loadFile(join(__dirname, '../renderer/index.html'))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle window close (hide instead of closing)
|
||||||
|
mainWindow.on('close', (event) => {
|
||||||
|
if (!app.isQuiting) {
|
||||||
|
event.preventDefault()
|
||||||
|
mainWindow.hide() // Minimize to tray instead of closing
|
||||||
|
} else {
|
||||||
|
// Destroy the tray when quitting
|
||||||
|
if (tray) tray.destroy()
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method will be called when Electron has finished
|
// Function to create the system tray
|
||||||
// initialization and is ready to create browser windows.
|
function createTray() {
|
||||||
// Some APIs can only be used after this event occurs.
|
const iconPath = icon // Use your icon path here
|
||||||
app.whenReady().then(() => {
|
tray = new Tray(iconPath)
|
||||||
// Set app user model id for windows
|
|
||||||
electronApp.setAppUserModelId('com.electron')
|
// Create a context menu for the tray
|
||||||
|
const contextMenu = Menu.buildFromTemplate([
|
||||||
|
{
|
||||||
|
label: 'Ouvrir',
|
||||||
|
click: () => {
|
||||||
|
mainWindow.show()
|
||||||
|
mainWindow.webContents.send('navigateToRoute', '#/') // Send the route as a string
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'A Propos',
|
||||||
|
click: () => {
|
||||||
|
mainWindow.show()
|
||||||
|
mainWindow.webContents.send('navigateToRoute', '#/apropos') // Send the route as a string
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Quit',
|
||||||
|
click: () => {
|
||||||
|
// Clear localStorage in the renderer process
|
||||||
|
mainWindow.webContents
|
||||||
|
.executeJavaScript('localStorage.removeItem("ACCESS_TOKEN");')
|
||||||
|
.then(() => {
|
||||||
|
console.log('localStorage cleared.')
|
||||||
|
// Ensure the app quits entirely
|
||||||
|
if (tray) {
|
||||||
|
app.quit()
|
||||||
|
tray.destroy()
|
||||||
|
// if (app.quit()) {
|
||||||
|
// tray.destroy()
|
||||||
|
// }
|
||||||
|
} // Quit the app
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error('Error clearing localStorage:', err)
|
||||||
|
// Quit the app even if clearing fails
|
||||||
|
if (tray) {
|
||||||
|
app.quit()
|
||||||
|
tray.destroy()
|
||||||
|
// if (app.quit()) {
|
||||||
|
// tray.destroy()
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
])
|
||||||
|
|
||||||
|
tray.setToolTip('My Electron App')
|
||||||
|
tray.setContextMenu(contextMenu)
|
||||||
|
|
||||||
|
// Show the app when the tray icon is clicked
|
||||||
|
tray.on('click', () => {
|
||||||
|
mainWindow.show()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
app.whenReady().then(() => {
|
||||||
|
electronApp.setAppUserModelId('com.electron')
|
||||||
|
autoUpdater.checkForUpdatesAndNotify()
|
||||||
|
|
||||||
// Default open or close DevTools by F12 in development
|
|
||||||
// and ignore CommandOrControl + R in production.
|
|
||||||
// see https://github.com/alex8088/electron-toolkit/tree/master/packages/utils
|
|
||||||
app.on('browser-window-created', (_, window) => {
|
app.on('browser-window-created', (_, window) => {
|
||||||
optimizer.watchWindowShortcuts(window)
|
optimizer.watchWindowShortcuts(window)
|
||||||
})
|
})
|
||||||
|
|
||||||
// IPC test
|
|
||||||
ipcMain.on('pingpong', () => console.log('pongsss'))
|
|
||||||
|
|
||||||
createWindow()
|
createWindow()
|
||||||
|
createTray() // Create the tray icon
|
||||||
|
|
||||||
app.on('activate', function () {
|
app.on('activate', function () {
|
||||||
// On macOS it's common to re-create a window in the app when the
|
|
||||||
// dock icon is clicked and there are no other windows open.
|
|
||||||
if (BrowserWindow.getAllWindows().length === 0) createWindow()
|
if (BrowserWindow.getAllWindows().length === 0) createWindow()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// Quit when all windows are closed, except on macOS. There, it's common
|
// When an update is available
|
||||||
// for applications and their menu bar to stay active until the user quits
|
autoUpdater.on('update-available', () => {
|
||||||
// explicitly with Cmd + Q.
|
dialog.showMessageBox({
|
||||||
|
type: 'info',
|
||||||
|
title: 'Mise à jour disponible',
|
||||||
|
message: 'Une nouvelle version est disponible. Téléchargement en cours...'
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
// When the update is downloaded
|
||||||
|
autoUpdater.on('update-downloaded', (info) => {
|
||||||
|
dialog
|
||||||
|
.showMessageBox({
|
||||||
|
type: 'info',
|
||||||
|
title: 'Mise à jour prête',
|
||||||
|
message: `La version ${info.version} a été téléchargée. Redémarrer maintenant ?`,
|
||||||
|
buttons: ['Redémarrer', 'Plus tard']
|
||||||
|
})
|
||||||
|
.then((result) => {
|
||||||
|
if (result.response === 0) {
|
||||||
|
autoUpdater.quitAndInstall()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
// If an error occurs
|
||||||
|
autoUpdater.on('error', (error) => {
|
||||||
|
dialog.showErrorBox('Update Error', error == null ? 'Unknown' : error.message)
|
||||||
|
})
|
||||||
|
|
||||||
|
// Quit the app when all windows are closed, except on macOS
|
||||||
app.on('window-all-closed', () => {
|
app.on('window-all-closed', () => {
|
||||||
if (process.platform !== 'darwin') {
|
if (process.platform !== 'darwin') {
|
||||||
app.quit()
|
app.quit()
|
||||||
@ -126,9 +314,9 @@ ipcMain.handle('forgotPassword', async (event, credentials) => {
|
|||||||
|
|
||||||
// event for updating users
|
// event for updating users
|
||||||
ipcMain.handle('updateUsers', async (event, credentials) => {
|
ipcMain.handle('updateUsers', async (event, credentials) => {
|
||||||
const { username, email, passwordVerif, password, id } = credentials
|
const { username, newUsername, email, newEmail, passwordVerif, password, id } = credentials
|
||||||
|
|
||||||
const update = await updateUser(username, email, password, id)
|
const update = await updateUser(newUsername, newEmail, password, id)
|
||||||
|
|
||||||
return update
|
return update
|
||||||
})
|
})
|
||||||
@ -147,8 +335,27 @@ ipcMain.handle('minimize', async () => {
|
|||||||
|
|
||||||
// event for insert etudiants
|
// event for insert etudiants
|
||||||
ipcMain.handle('insertEtudiant', async (event, credentials) => {
|
ipcMain.handle('insertEtudiant', async (event, credentials) => {
|
||||||
const { nom, prenom, photos, date_de_naissances, niveau, annee_scolaire, num_inscription } =
|
const {
|
||||||
credentials
|
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
|
||||||
|
} = credentials
|
||||||
|
|
||||||
const insert = await insertEtudiant(
|
const insert = await insertEtudiant(
|
||||||
nom,
|
nom,
|
||||||
@ -157,7 +364,19 @@ ipcMain.handle('insertEtudiant', async (event, credentials) => {
|
|||||||
date_de_naissances,
|
date_de_naissances,
|
||||||
niveau,
|
niveau,
|
||||||
annee_scolaire,
|
annee_scolaire,
|
||||||
num_inscription
|
status,
|
||||||
|
num_inscription,
|
||||||
|
mention_id,
|
||||||
|
sexe,
|
||||||
|
nationaliter,
|
||||||
|
cin,
|
||||||
|
date_delivrence,
|
||||||
|
annee_bacc,
|
||||||
|
serie,
|
||||||
|
boursier,
|
||||||
|
domaine,
|
||||||
|
contact,
|
||||||
|
parcours
|
||||||
)
|
)
|
||||||
|
|
||||||
return insert
|
return insert
|
||||||
@ -192,8 +411,28 @@ ipcMain.handle('insertNiveau', async (event, credentials) => {
|
|||||||
|
|
||||||
// event for updating etudiants
|
// event for updating etudiants
|
||||||
ipcMain.handle('updateETudiants', async (event, credentials) => {
|
ipcMain.handle('updateETudiants', async (event, credentials) => {
|
||||||
const { nom, prenom, photos, date_de_naissances, niveau, annee_scolaire, num_inscription, id } =
|
const {
|
||||||
credentials
|
nom,
|
||||||
|
prenom,
|
||||||
|
photos,
|
||||||
|
date_de_naissances,
|
||||||
|
niveau,
|
||||||
|
annee_scolaire,
|
||||||
|
status,
|
||||||
|
mention_id,
|
||||||
|
num_inscription,
|
||||||
|
id,
|
||||||
|
sexe,
|
||||||
|
nationalite,
|
||||||
|
cin,
|
||||||
|
date_delivrance,
|
||||||
|
annee_bacc,
|
||||||
|
serie,
|
||||||
|
boursier,
|
||||||
|
domaine,
|
||||||
|
contact,
|
||||||
|
parcours
|
||||||
|
} = credentials
|
||||||
|
|
||||||
const updating = await updateEtudiant(
|
const updating = await updateEtudiant(
|
||||||
nom,
|
nom,
|
||||||
@ -202,54 +441,472 @@ ipcMain.handle('updateETudiants', async (event, credentials) => {
|
|||||||
date_de_naissances,
|
date_de_naissances,
|
||||||
niveau,
|
niveau,
|
||||||
annee_scolaire,
|
annee_scolaire,
|
||||||
|
status,
|
||||||
|
mention_id,
|
||||||
num_inscription,
|
num_inscription,
|
||||||
id
|
id,
|
||||||
|
sexe,
|
||||||
|
nationalite,
|
||||||
|
cin,
|
||||||
|
date_delivrance,
|
||||||
|
annee_bacc,
|
||||||
|
serie,
|
||||||
|
boursier,
|
||||||
|
domaine,
|
||||||
|
contact,
|
||||||
|
parcours
|
||||||
)
|
)
|
||||||
|
|
||||||
return updating
|
return updating
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// event for updating etudiants pdp
|
||||||
|
ipcMain.handle('updateETudiantsPDP', async (event, credentials) => {
|
||||||
|
const { pdp, id } = credentials
|
||||||
|
|
||||||
|
const updating = await changePDP(pdp, id)
|
||||||
|
|
||||||
|
return updating
|
||||||
|
})
|
||||||
|
|
||||||
// event for adding notes
|
// event for adding notes
|
||||||
ipcMain.handle('insertNote', async (event, credentials) => {
|
ipcMain.handle('insertNote', async (event, credentials) => {
|
||||||
const {
|
const { etudiant_id, etudiant_niveau, mention_id, formData, annee_scolaire } = credentials
|
||||||
etudiant_id,
|
|
||||||
Algebre,
|
|
||||||
Analyse,
|
|
||||||
Mecanique_Generale_I,
|
|
||||||
Resistance_Materiaux,
|
|
||||||
Electricite,
|
|
||||||
Chimie_Generale_1,
|
|
||||||
Algorithmique,
|
|
||||||
Thermodynamique_Physique,
|
|
||||||
Mecanique_Fluide,
|
|
||||||
Optique_Geometrique,
|
|
||||||
Calcul_Numerique,
|
|
||||||
Calcul_Vectoriel_Integral,
|
|
||||||
Francais,
|
|
||||||
Anglais,
|
|
||||||
Dessin_Technique,
|
|
||||||
Programmation
|
|
||||||
} = credentials
|
|
||||||
|
|
||||||
const insert = await insertNote(
|
const insert = await insertNote(
|
||||||
etudiant_id,
|
etudiant_id,
|
||||||
Algebre,
|
etudiant_niveau,
|
||||||
Analyse,
|
mention_id,
|
||||||
Mecanique_Generale_I,
|
formData,
|
||||||
Resistance_Materiaux,
|
annee_scolaire
|
||||||
Electricite,
|
|
||||||
Chimie_Generale_1,
|
|
||||||
Algorithmique,
|
|
||||||
Thermodynamique_Physique,
|
|
||||||
Mecanique_Fluide,
|
|
||||||
Optique_Geometrique,
|
|
||||||
Calcul_Numerique,
|
|
||||||
Calcul_Vectoriel_Integral,
|
|
||||||
Francais,
|
|
||||||
Anglais,
|
|
||||||
Dessin_Technique,
|
|
||||||
Programmation
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return insert
|
return insert
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// event for get single note
|
||||||
|
ipcMain.handle('getSingleNote', async (event, credentials) => {
|
||||||
|
const { id, niveau, mention_id } = credentials
|
||||||
|
|
||||||
|
const get = await getNote(id, niveau, mention_id)
|
||||||
|
|
||||||
|
return get
|
||||||
|
})
|
||||||
|
|
||||||
|
// event for get single note repech
|
||||||
|
ipcMain.handle('getNotesRepech', async (event, credentials) => {
|
||||||
|
const { id, niveau, mention_id } = credentials
|
||||||
|
|
||||||
|
const get = await getNoteRepech(id, niveau, mention_id)
|
||||||
|
|
||||||
|
return get
|
||||||
|
})
|
||||||
|
|
||||||
|
// event for updating note
|
||||||
|
ipcMain.handle('updatetNote', async (event, credentials) => {
|
||||||
|
const { formData, niveau, id, mention_id, annee_scolaire } = credentials
|
||||||
|
|
||||||
|
const update = await updateNote(formData, niveau, id, mention_id, annee_scolaire)
|
||||||
|
|
||||||
|
return update
|
||||||
|
})
|
||||||
|
|
||||||
|
// event for updating note repech
|
||||||
|
ipcMain.handle('updatetNoteRepech', async (event, credentials) => {
|
||||||
|
const { formData2, niveau, id } = credentials
|
||||||
|
|
||||||
|
const update = await updateNoteRepech(formData2, niveau, id)
|
||||||
|
|
||||||
|
return update
|
||||||
|
})
|
||||||
|
|
||||||
|
// event to get single matiere
|
||||||
|
ipcMain.handle('getMatiereByID', async (event, credentials) => {
|
||||||
|
const { id } = credentials
|
||||||
|
|
||||||
|
const matiere = await getSingleMatiere(id)
|
||||||
|
|
||||||
|
return matiere
|
||||||
|
})
|
||||||
|
|
||||||
|
// event for updating matiere
|
||||||
|
ipcMain.handle('updateMatiere', async (event, credentials) => {
|
||||||
|
const { nom, credit, uniter, ue, id } = credentials
|
||||||
|
|
||||||
|
const update = await updateMatiere(nom, id, credit, uniter, ue)
|
||||||
|
|
||||||
|
return update
|
||||||
|
})
|
||||||
|
// event for importExcel
|
||||||
|
ipcMain.handle('importexcel', async (event, credentials) => {
|
||||||
|
const files = credentials
|
||||||
|
console.log(files)
|
||||||
|
const insert = await importFileToDatabase(files)
|
||||||
|
|
||||||
|
return insert
|
||||||
|
})
|
||||||
|
|
||||||
|
// event for udatign a single niveau
|
||||||
|
ipcMain.handle('updateSingleNiveau', async (event, credentials) => {
|
||||||
|
const { nom, id } = credentials
|
||||||
|
|
||||||
|
const update = updateNiveau(nom, id)
|
||||||
|
|
||||||
|
return update
|
||||||
|
})
|
||||||
|
|
||||||
|
// event to get single niveau
|
||||||
|
ipcMain.handle('singleNiveau', async (event, credentials) => {
|
||||||
|
const { id } = credentials
|
||||||
|
|
||||||
|
const update = getSingleNiveau(id)
|
||||||
|
|
||||||
|
return update
|
||||||
|
})
|
||||||
|
|
||||||
|
// event for creating matiere
|
||||||
|
ipcMain.handle('createMatiere', async (event, credentials) => {
|
||||||
|
const { nom, credit, uniter, ue } = credentials
|
||||||
|
|
||||||
|
const create = createMatiere(nom, credit, uniter, ue)
|
||||||
|
|
||||||
|
return create
|
||||||
|
})
|
||||||
|
|
||||||
|
// event for import excel matiere
|
||||||
|
ipcMain.handle('importExcelMatiere', async (event, credentials) => {
|
||||||
|
const files = credentials
|
||||||
|
console.log(files)
|
||||||
|
const insert = await importFileToDatabaseMatiere(files)
|
||||||
|
|
||||||
|
return insert
|
||||||
|
})
|
||||||
|
|
||||||
|
// event for import excel niveau
|
||||||
|
ipcMain.handle('importNiveau', async (event, credentials) => {
|
||||||
|
const files = credentials
|
||||||
|
console.log(files)
|
||||||
|
const insert = await importNiveau(files)
|
||||||
|
|
||||||
|
return insert
|
||||||
|
})
|
||||||
|
|
||||||
|
// event for updating note systeme
|
||||||
|
ipcMain.handle('updateNoteSysteme', async (event, credentials) => {
|
||||||
|
const { id, admis, redouble, renvoyer } = credentials
|
||||||
|
|
||||||
|
const update = updateSysteme(id, admis, redouble, renvoyer)
|
||||||
|
return update
|
||||||
|
})
|
||||||
|
|
||||||
|
// event for updating note systeme
|
||||||
|
ipcMain.handle('createAnneeScolaire', async (event, credentials) => {
|
||||||
|
const { code, debut, fin } = credentials
|
||||||
|
|
||||||
|
const create = createAnneeScolaire(code, debut, fin)
|
||||||
|
return create
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('getMoyene', async (event, credentials) => {
|
||||||
|
const { niveau, scolaire } = credentials
|
||||||
|
console.log('index.js', niveau, scolaire)
|
||||||
|
|
||||||
|
const create = showMoyen(niveau, scolaire)
|
||||||
|
return create
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('getMoyenneRepech', async (event, credentials) => {
|
||||||
|
const { niveau, scolaire } = credentials
|
||||||
|
console.log('index.js', niveau, scolaire)
|
||||||
|
|
||||||
|
const create = showMoyenRepech(niveau, scolaire)
|
||||||
|
return create
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('noteMatiere', async (event, credentials) => {
|
||||||
|
const { id, niveau, annee_scolaire } = credentials
|
||||||
|
|
||||||
|
const get = getMatiereAndNote(id, niveau, annee_scolaire)
|
||||||
|
return get
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('displayMatiereFromForm', async (event, credentials) => {
|
||||||
|
const { niveau, mention_id, parcours } = credentials
|
||||||
|
|
||||||
|
const get = displayMatiereFromForm(niveau, mention_id, parcours)
|
||||||
|
return get
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('createMention', async (event, credentials) => {
|
||||||
|
const { nom, uniter } = credentials
|
||||||
|
|
||||||
|
const get = createMention(nom, uniter)
|
||||||
|
return get
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('getSingleMention', async (event, credentials) => {
|
||||||
|
const { id } = credentials
|
||||||
|
|
||||||
|
const get = getSingleMention(id)
|
||||||
|
return get
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('updateMention', async (event, credentials) => {
|
||||||
|
const { nom, uniter, id } = credentials
|
||||||
|
|
||||||
|
const get = updateMention(nom, uniter, id)
|
||||||
|
return get
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('deleteMention', async (event, credentials) => {
|
||||||
|
const { id } = credentials
|
||||||
|
|
||||||
|
const get = deleteMention(id)
|
||||||
|
return get
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('deleteNiveaus', async (event, credentials) => {
|
||||||
|
const { id } = credentials
|
||||||
|
|
||||||
|
const get = deleteNiveau(id)
|
||||||
|
return get
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('deleteMatiere', async (event, credentials) => {
|
||||||
|
const { id } = credentials
|
||||||
|
|
||||||
|
const get = deleteMatiere(id)
|
||||||
|
return get
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('asign', async (event, credentials) => {
|
||||||
|
const { formData, id } = credentials
|
||||||
|
// console.log(formData, id);
|
||||||
|
const get = asygnationToMention(formData, id)
|
||||||
|
|
||||||
|
return get
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('asignSemestre', async (event, credentials) => {
|
||||||
|
const { id } = credentials
|
||||||
|
|
||||||
|
const get = getMentionMatiereChecked(id)
|
||||||
|
|
||||||
|
return get
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('getAsign', async (event, credentials) => {
|
||||||
|
const { id } = credentials
|
||||||
|
// console.log(formData, id);
|
||||||
|
const get = getMentionMatiere(id)
|
||||||
|
|
||||||
|
return get
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('deleteAnneeScolaire', async (event, credentials) => {
|
||||||
|
const { id } = credentials
|
||||||
|
// console.log(formData, id);
|
||||||
|
const get = deleteAnneeScolaire(id)
|
||||||
|
|
||||||
|
return get
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('getSemestreMatiere', async (event, credentials) => {
|
||||||
|
const { id } = credentials
|
||||||
|
// console.log(formData, id);
|
||||||
|
const get = getSemestreMatiere(id)
|
||||||
|
|
||||||
|
return get
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('insertUpdateMentionSemestre', async (event, credentials) => {
|
||||||
|
const { id, selectedSemestres } = credentials
|
||||||
|
// console.log(formData, id);
|
||||||
|
const get = insertUpdateMentionSemestre(id, selectedSemestres)
|
||||||
|
|
||||||
|
return get
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('getSingleAnneeScolaire', async (event, credentials) => {
|
||||||
|
const { id } = credentials
|
||||||
|
// console.log(formData, id);
|
||||||
|
const get = getSingleAnneScolaire(id)
|
||||||
|
|
||||||
|
return get
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('updateAnneeScolaire', async (event, credentials) => {
|
||||||
|
const { code, debut, fin, id } = credentials
|
||||||
|
// console.log(formData, id);
|
||||||
|
const get = updateAnneeScolaire(id, code, debut, fin)
|
||||||
|
|
||||||
|
return get
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('setCurrent', async (event, credentials) => {
|
||||||
|
const { id } = credentials
|
||||||
|
// console.log(formData, id);
|
||||||
|
const get = setCurrent(id)
|
||||||
|
|
||||||
|
return get
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('noteRelerer', async (event, credentials) => {
|
||||||
|
const { id, anneescolaire, niveau } = credentials
|
||||||
|
// console.log(formData, id);
|
||||||
|
const get = getNotesWithRepechToDisplay(id, anneescolaire, niveau)
|
||||||
|
|
||||||
|
return get
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('updateNessesary', async (event, credentials) => {
|
||||||
|
const { id, multiplicateur } = credentials
|
||||||
|
// console.log(formData, id);
|
||||||
|
const get = updateNessesaryTable(id, multiplicateur)
|
||||||
|
|
||||||
|
return get
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('insertProf', async (event, credentials) => {
|
||||||
|
const { nom_enseignant, prenom_enseignant, contact, date, matiere_id } = credentials
|
||||||
|
// console.log(formData, id);
|
||||||
|
const get = insertNewProf(matiere_id, nom_enseignant, prenom_enseignant, contact, date)
|
||||||
|
|
||||||
|
return get
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('insertParcours', async (event, credentials) => {
|
||||||
|
const { nom, uniter, mention_id } = credentials
|
||||||
|
// console.log(formData, id);
|
||||||
|
const get = insertParcour(nom, uniter, mention_id)
|
||||||
|
|
||||||
|
return get
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('getSingleParcours', async (event, credentials) => {
|
||||||
|
const { id } = credentials
|
||||||
|
// console.log(formData, id);
|
||||||
|
const get = getSingleParcours(id)
|
||||||
|
|
||||||
|
return get
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('deleteParcours', async (event, credentials) => {
|
||||||
|
const { id } = credentials
|
||||||
|
// console.log(formData, id);
|
||||||
|
const get = deletes(id)
|
||||||
|
|
||||||
|
return get
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('updateParcours', async (event, credentials) => {
|
||||||
|
const { nom, uniter, mention_id, id } = credentials
|
||||||
|
// console.log(formData, id);
|
||||||
|
const get = updateparcour(id, nom, uniter, mention_id)
|
||||||
|
|
||||||
|
return get
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('parcourMatiere', async (event, credentials) => {
|
||||||
|
const { matiere_id, parcour_id } = credentials
|
||||||
|
// console.log(formData, id);
|
||||||
|
const get = parcourMatiere(matiere_id, parcour_id)
|
||||||
|
|
||||||
|
return get
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('getSingleProf', async (event, credentials) => {
|
||||||
|
const { id } = credentials
|
||||||
|
// console.log(formData, id);
|
||||||
|
const get = getSIngleProf(id)
|
||||||
|
|
||||||
|
return get
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('updateProf', async (event, credentials) => {
|
||||||
|
const { nom_enseignant, prenom_enseignant, contact, date, matiere_id } = credentials
|
||||||
|
// console.log(formData, id);
|
||||||
|
const get = updateProf(matiere_id, nom_enseignant, prenom_enseignant, contact, date)
|
||||||
|
|
||||||
|
return get
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('extractFiches', async (event, credentials) => {
|
||||||
|
const { matiere_id } = credentials
|
||||||
|
// console.log(formData, id);
|
||||||
|
const get = extractFiche(matiere_id)
|
||||||
|
|
||||||
|
return get
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('getParcourMatiere', async (event, credentials) => {
|
||||||
|
const { matiere_id } = credentials
|
||||||
|
// console.log(formData, id);
|
||||||
|
const get = getParcourMatiere(matiere_id)
|
||||||
|
|
||||||
|
return get
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('changeParcours', async (event, credentials) => {
|
||||||
|
const { parcours, user_id } = credentials
|
||||||
|
// console.log(formData, id);
|
||||||
|
const get = updateParcours(parcours, user_id)
|
||||||
|
|
||||||
|
return get
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('createTranche', async (event, credentials) => {
|
||||||
|
const { etudiant_id, tranchename, montant } = credentials
|
||||||
|
// console.log(formData, id);
|
||||||
|
const get = createTranche(etudiant_id, tranchename, montant)
|
||||||
|
|
||||||
|
return get
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('getTranche', async (event, credentials) => {
|
||||||
|
const { id } = credentials
|
||||||
|
// console.log(formData, id);
|
||||||
|
const get = getTranche(id)
|
||||||
|
|
||||||
|
return get
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('updateTranche', async (event, credentials) => {
|
||||||
|
const { id, tranchename, montant } = credentials
|
||||||
|
// console.log(formData, id);
|
||||||
|
const get = updateTranche(id, tranchename, montant)
|
||||||
|
|
||||||
|
return get
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('deleteTranche', async (event, credentials) => {
|
||||||
|
const { id } = credentials
|
||||||
|
console.log(id)
|
||||||
|
const get = deleteTranche(id)
|
||||||
|
|
||||||
|
return get
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('getSingleTranche', async (event, credentials) => {
|
||||||
|
const { id } = credentials
|
||||||
|
// console.log(formData, id);
|
||||||
|
const get = getSingleTranche(id)
|
||||||
|
|
||||||
|
return get
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('createIPConfig', async (event, credentials) => {
|
||||||
|
const { ipname } = credentials
|
||||||
|
// console.log(formData, id);
|
||||||
|
const get = createConfigIp(ipname)
|
||||||
|
|
||||||
|
return get
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('updateIPConfig', async (event, credentials) => {
|
||||||
|
const { id, ipname } = credentials
|
||||||
|
// console.log(formData, id);
|
||||||
|
const get = updateIPConfig(id, ipname)
|
||||||
|
|
||||||
|
return get
|
||||||
|
})
|
||||||
|
|||||||
@ -1,11 +1,19 @@
|
|||||||
import { app, shell, BrowserWindow, ipcMain, Tray, Menu, screen } from 'electron'
|
import { app, shell, BrowserWindow, ipcMain, Tray, Menu } from 'electron'
|
||||||
import { join } from 'path'
|
import { join } from 'path'
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
|
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
|
||||||
import icon from '../../resources/logo.ico?asset' // Your tray icon file
|
import icon from '../../resources/logo.ico?asset' // Your tray icon file
|
||||||
|
const database = require('../../database/database')
|
||||||
|
|
||||||
|
database
|
||||||
|
.createTables()
|
||||||
|
.then(() => database.insertDefaultAdmin())
|
||||||
|
.then(() => database.insertStatusesIfNotExist())
|
||||||
|
.catch(console.error)
|
||||||
|
|
||||||
|
const { loginUsers } = require('../../database/Models/Users')
|
||||||
const { createConfigIp, updateIPConfig } = require('../../database/Models/IpConfig')
|
const { createConfigIp, updateIPConfig } = require('../../database/Models/IpConfig')
|
||||||
const { importFileToDatabase } = require('../../database/import/Etudiants')
|
const { importFileToDatabase } = require('../../database/import/Etudiants')
|
||||||
const { loginUser, forgotPassword, insertUser, updateUser } = require('../../database/Models/Users')
|
|
||||||
const {
|
const {
|
||||||
insertEtudiant,
|
insertEtudiant,
|
||||||
getSingleEtudiant,
|
getSingleEtudiant,
|
||||||
@ -64,17 +72,15 @@ const {
|
|||||||
getSingleMention,
|
getSingleMention,
|
||||||
updateMention
|
updateMention
|
||||||
} = require('../../database/Models/Mentions')
|
} = require('../../database/Models/Mentions')
|
||||||
const { modifyPDF } = require('../../database/function/DownloadReleverNote')
|
|
||||||
const log = require('electron-log')
|
|
||||||
const {
|
const {
|
||||||
getNoteRepech,
|
getNoteRepech,
|
||||||
updateNoteRepech,
|
updateNoteRepech,
|
||||||
showMoyenRepech
|
showMoyenRepech
|
||||||
} = require('../../database/Models/NoteRepechage')
|
} = require('../../database/Models/NoteRepechage')
|
||||||
const {
|
const {
|
||||||
updateCurrentYears,
|
updateCurrentYears
|
||||||
updateStudents,
|
// updateStudents,
|
||||||
updateNessesaryTable
|
// updateNessesaryTable
|
||||||
} = require('../../database/function/System')
|
} = require('../../database/function/System')
|
||||||
const { autoUpdater } = require('electron-updater')
|
const { autoUpdater } = require('electron-updater')
|
||||||
const { URL } = require('../../database/api/Config')
|
const { URL } = require('../../database/api/Config')
|
||||||
@ -87,20 +93,18 @@ const {
|
|||||||
extractFiche,
|
extractFiche,
|
||||||
getParcourMatiere
|
getParcourMatiere
|
||||||
} = require('../../database/Models/Parcours')
|
} = require('../../database/Models/Parcours')
|
||||||
const express = require('express');
|
|
||||||
|
|
||||||
// Declare mainWindow and tray in the global scope
|
// Declare mainWindow and tray in the global scope
|
||||||
let mainWindow
|
let mainWindow
|
||||||
let tray = null
|
let tray = null
|
||||||
updateCurrentYears()
|
updateCurrentYears()
|
||||||
updateStudents()
|
// updateStudents()
|
||||||
|
|
||||||
autoUpdater.setFeedURL({
|
autoUpdater.setFeedURL({
|
||||||
provider: 'generic',
|
provider: 'generic',
|
||||||
url: `${URL}/latest` // Ensure this points to the folder containing latest.yml
|
url: `${URL}/latest` // Ensure this points to the folder containing latest.yml
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
function createWindow() {
|
function createWindow() {
|
||||||
// Create the browser window.
|
// Create the browser window.
|
||||||
mainWindow = new BrowserWindow({
|
mainWindow = new BrowserWindow({
|
||||||
@ -129,7 +133,6 @@ function createWindow() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
mainWindow.on('ready-to-show', () => {
|
mainWindow.on('ready-to-show', () => {
|
||||||
|
|
||||||
mainWindow.maximize() // Maximiser la fenêtre
|
mainWindow.maximize() // Maximiser la fenêtre
|
||||||
mainWindow.show()
|
mainWindow.show()
|
||||||
})
|
})
|
||||||
@ -206,7 +209,6 @@ function createTray() {
|
|||||||
// tray.destroy()
|
// tray.destroy()
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -223,7 +225,7 @@ function createTray() {
|
|||||||
|
|
||||||
app.whenReady().then(() => {
|
app.whenReady().then(() => {
|
||||||
electronApp.setAppUserModelId('com.electron')
|
electronApp.setAppUserModelId('com.electron')
|
||||||
autoUpdater.checkForUpdatesAndNotify();
|
autoUpdater.checkForUpdatesAndNotify()
|
||||||
|
|
||||||
app.on('browser-window-created', (_, window) => {
|
app.on('browser-window-created', (_, window) => {
|
||||||
optimizer.watchWindowShortcuts(window)
|
optimizer.watchWindowShortcuts(window)
|
||||||
@ -242,28 +244,30 @@ autoUpdater.on('update-available', () => {
|
|||||||
dialog.showMessageBox({
|
dialog.showMessageBox({
|
||||||
type: 'info',
|
type: 'info',
|
||||||
title: 'Mise à jour disponible',
|
title: 'Mise à jour disponible',
|
||||||
message: 'Une nouvelle version est disponible. Téléchargement en cours...',
|
message: 'Une nouvelle version est disponible. Téléchargement en cours...'
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
|
|
||||||
// When the update is downloaded
|
// When the update is downloaded
|
||||||
autoUpdater.on('update-downloaded', (info) => {
|
autoUpdater.on('update-downloaded', (info) => {
|
||||||
dialog.showMessageBox({
|
dialog
|
||||||
type: 'info',
|
.showMessageBox({
|
||||||
title: 'Mise à jour prête',
|
type: 'info',
|
||||||
message: `La version ${info.version} a été téléchargée. Redémarrer maintenant ?`,
|
title: 'Mise à jour prête',
|
||||||
buttons: ['Redémarrer', 'Plus tard'],
|
message: `La version ${info.version} a été téléchargée. Redémarrer maintenant ?`,
|
||||||
}).then((result) => {
|
buttons: ['Redémarrer', 'Plus tard']
|
||||||
if (result.response === 0) {
|
})
|
||||||
autoUpdater.quitAndInstall();
|
.then((result) => {
|
||||||
}
|
if (result.response === 0) {
|
||||||
});
|
autoUpdater.quitAndInstall()
|
||||||
});
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
// If an error occurs
|
// If an error occurs
|
||||||
autoUpdater.on('error', (error) => {
|
autoUpdater.on('error', (error) => {
|
||||||
dialog.showErrorBox('Update Error', error == null ? 'Unknown' : error.message);
|
dialog.showErrorBox('Update Error', error == null ? 'Unknown' : error.message)
|
||||||
});
|
})
|
||||||
|
|
||||||
// Quit the app when all windows are closed, except on macOS
|
// Quit the app when all windows are closed, except on macOS
|
||||||
app.on('window-all-closed', () => {
|
app.on('window-all-closed', () => {
|
||||||
@ -275,48 +279,6 @@ app.on('window-all-closed', () => {
|
|||||||
// In this file you can include the rest of your app"s specific main process
|
// In this file you can include the rest of your app"s specific main process
|
||||||
// code. You can also put them in separate files and require them here.
|
// code. You can also put them in separate files and require them here.
|
||||||
|
|
||||||
// Event for handling login
|
|
||||||
ipcMain.handle('login', async (event, credentials) => {
|
|
||||||
const { username, password } = credentials
|
|
||||||
|
|
||||||
const users = await loginUser(username, password)
|
|
||||||
|
|
||||||
if (users) {
|
|
||||||
return { success: true, user: users }
|
|
||||||
} else {
|
|
||||||
return { success: false }
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// Event for handling insert other user
|
|
||||||
ipcMain.handle('insertUser', async (event, credentials) => {
|
|
||||||
const { username, email, password, roles } = credentials
|
|
||||||
|
|
||||||
const users = await insertUser(username, email, password, roles)
|
|
||||||
|
|
||||||
return users
|
|
||||||
})
|
|
||||||
|
|
||||||
// event for handlign forgot password
|
|
||||||
ipcMain.handle('forgotPassword', async (event, credentials) => {
|
|
||||||
const { email, password, passwordConfirmation } = credentials
|
|
||||||
|
|
||||||
const updated = await forgotPassword(email, password, passwordConfirmation)
|
|
||||||
|
|
||||||
if (updated) {
|
|
||||||
return updated
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// event for updating users
|
|
||||||
ipcMain.handle('updateUsers', async (event, credentials) => {
|
|
||||||
const { username, newUsername, email, newEmail, passwordVerif, password, id } = credentials
|
|
||||||
|
|
||||||
const update = await updateUser(newUsername, newEmail, password, id)
|
|
||||||
|
|
||||||
return update
|
|
||||||
})
|
|
||||||
|
|
||||||
// event for quit app
|
// event for quit app
|
||||||
ipcMain.handle('quit', async () => {
|
ipcMain.handle('quit', async () => {
|
||||||
app.quit()
|
app.quit()
|
||||||
@ -329,6 +291,14 @@ ipcMain.handle('minimize', async () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
ipcMain.handle('login', async (event, credentials) => {
|
||||||
|
const { username, password } = credentials
|
||||||
|
|
||||||
|
// Pass username and password to loginUsers
|
||||||
|
let response = await loginUsers(username, password)
|
||||||
|
|
||||||
|
return response
|
||||||
|
})
|
||||||
// event for insert etudiants
|
// event for insert etudiants
|
||||||
ipcMain.handle('insertEtudiant', async (event, credentials) => {
|
ipcMain.handle('insertEtudiant', async (event, credentials) => {
|
||||||
const {
|
const {
|
||||||
@ -525,7 +495,7 @@ ipcMain.handle('getMatiereByID', async (event, credentials) => {
|
|||||||
return matiere
|
return matiere
|
||||||
})
|
})
|
||||||
|
|
||||||
// event for updating matiere
|
// // event for updating matiere
|
||||||
ipcMain.handle('updateMatiere', async (event, credentials) => {
|
ipcMain.handle('updateMatiere', async (event, credentials) => {
|
||||||
const { nom, credit, uniter, ue, id } = credentials
|
const { nom, credit, uniter, ue, id } = credentials
|
||||||
|
|
||||||
@ -569,7 +539,7 @@ ipcMain.handle('createMatiere', async (event, credentials) => {
|
|||||||
return create
|
return create
|
||||||
})
|
})
|
||||||
|
|
||||||
// event for import excel matiere
|
// // event for import excel matiere
|
||||||
ipcMain.handle('importExcelMatiere', async (event, credentials) => {
|
ipcMain.handle('importExcelMatiere', async (event, credentials) => {
|
||||||
const files = credentials
|
const files = credentials
|
||||||
console.log(files)
|
console.log(files)
|
||||||
@ -902,7 +872,7 @@ ipcMain.handle('createIPConfig', async (event, credentials) => {
|
|||||||
ipcMain.handle('updateIPConfig', async (event, credentials) => {
|
ipcMain.handle('updateIPConfig', async (event, credentials) => {
|
||||||
const { id, ipname } = credentials
|
const { id, ipname } = credentials
|
||||||
// console.log(formData, id);
|
// console.log(formData, id);
|
||||||
const get = updateIPConfig(id, ipname);
|
const get = updateIPConfig(id, ipname)
|
||||||
|
|
||||||
return get
|
return get
|
||||||
})
|
})
|
||||||
|
|||||||
210
src/preload/index.backup.js
Normal file
210
src/preload/index.backup.js
Normal file
@ -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
|
||||||
|
}
|
||||||
@ -5,10 +5,6 @@ const { getNiveau } = require('../../database/Models/Niveau')
|
|||||||
const { getAllUsers } = require('../../database/Models/Users')
|
const { getAllUsers } = require('../../database/Models/Users')
|
||||||
const { getAllEtudiants, getDataToDashboard } = require('../../database/Models/Etudiants')
|
const { getAllEtudiants, getDataToDashboard } = require('../../database/Models/Etudiants')
|
||||||
const { verifyEtudiantIfHeHasNotes, blockShowMoyene } = require('../../database/Models/Notes')
|
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 { getMatiere, getSemestre, getEnseignants } = require('../../database/Models/Matieres')
|
||||||
const { getSysteme } = require('../../database/Models/NoteSysrem')
|
const { getSysteme } = require('../../database/Models/NoteSysrem')
|
||||||
const { getStatus } = require('../../database/Models/Status')
|
const { getStatus } = require('../../database/Models/Status')
|
||||||
|
|||||||
@ -40,7 +40,7 @@ const AddAnneeScolaire = () => {
|
|||||||
if (isValid) {
|
if (isValid) {
|
||||||
let response = await window.anneescolaire.createAnneeScolaire(formData)
|
let response = await window.anneescolaire.createAnneeScolaire(formData)
|
||||||
console.log(response)
|
console.log(response)
|
||||||
if (response.changes) {
|
if (response.success) {
|
||||||
setStatus(200)
|
setStatus(200)
|
||||||
setOpen(true)
|
setOpen(true)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -96,8 +96,8 @@ const AddMatiere = () => {
|
|||||||
console.log(formData, valid)
|
console.log(formData, valid)
|
||||||
if (valid) {
|
if (valid) {
|
||||||
let response = await window.matieres.createMatiere(formData)
|
let response = await window.matieres.createMatiere(formData)
|
||||||
|
console.log(response)
|
||||||
if (response.changes == 1) {
|
if (response.success) {
|
||||||
setOpen(true)
|
setOpen(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -59,7 +59,7 @@ const AddMention = () => {
|
|||||||
try {
|
try {
|
||||||
let response = await window.mention.createMention(formData)
|
let response = await window.mention.createMention(formData)
|
||||||
|
|
||||||
if (response.changes) {
|
if (response.success) {
|
||||||
setOpen(true)
|
setOpen(true)
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@ -107,6 +107,7 @@ const AddNiveau = () => {
|
|||||||
|
|
||||||
if (validation) {
|
if (validation) {
|
||||||
let response = await window.niveaus.insertNiveau(formData)
|
let response = await window.niveaus.insertNiveau(formData)
|
||||||
|
|
||||||
let responses = JSON.parse(response)
|
let responses = JSON.parse(response)
|
||||||
if (responses.changes == 1) {
|
if (responses.changes == 1) {
|
||||||
setOpen(true)
|
setOpen(true)
|
||||||
@ -114,10 +115,6 @@ const AddNiveau = () => {
|
|||||||
nom: ''
|
nom: ''
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.code) {
|
|
||||||
nomError.current.textContent = `${formData.nom} existe déjà`
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -18,7 +18,7 @@ const AddParcours = ({ open, onClose, onSubmitSuccess }) => {
|
|||||||
const [formData, setFormData] = useState({
|
const [formData, setFormData] = useState({
|
||||||
nom: '',
|
nom: '',
|
||||||
uniter: '',
|
uniter: '',
|
||||||
mention_id: ''
|
mention_id: null
|
||||||
})
|
})
|
||||||
|
|
||||||
const [mention, setMention] = useState([])
|
const [mention, setMention] = useState([])
|
||||||
@ -37,14 +37,14 @@ const AddParcours = ({ open, onClose, onSubmitSuccess }) => {
|
|||||||
const handleSubmit = async (e) => {
|
const handleSubmit = async (e) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
let response = await window.notesysteme.insertParcours(formData)
|
let response = await window.notesysteme.insertParcours(formData)
|
||||||
|
console.log(response)
|
||||||
if (response.changes) {
|
if (response.success) {
|
||||||
onSubmitSuccess(true)
|
onSubmitSuccess(true)
|
||||||
onClose() // Close the modal after submission
|
onClose() // Close the modal after submission
|
||||||
setFormData({
|
setFormData({
|
||||||
nom: '',
|
nom: '',
|
||||||
uniter: '',
|
uniter: '',
|
||||||
mention_id: ''
|
mention_id: null
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -153,7 +153,7 @@ const AnneeScolaire = () => {
|
|||||||
|
|
||||||
const deleteButton = async (id) => {
|
const deleteButton = async (id) => {
|
||||||
let response = await window.anneescolaire.deleteAnneeScolaire({ id })
|
let response = await window.anneescolaire.deleteAnneeScolaire({ id })
|
||||||
if (response.changes) {
|
if (response.success) {
|
||||||
const updatedAnneeScolaire = anneeScolaire.filter((anneeScolaire) => anneeScolaire.id !== id)
|
const updatedAnneeScolaire = anneeScolaire.filter((anneeScolaire) => anneeScolaire.id !== id)
|
||||||
setAnneeScolaire(updatedAnneeScolaire)
|
setAnneeScolaire(updatedAnneeScolaire)
|
||||||
setIsDeleted(true)
|
setIsDeleted(true)
|
||||||
|
|||||||
@ -50,7 +50,7 @@ const AssignMatiereToMention = () => {
|
|||||||
|
|
||||||
let response = await window.matieres.asign({ formData, id })
|
let response = await window.matieres.asign({ formData, id })
|
||||||
console.log(response)
|
console.log(response)
|
||||||
if (response.changes) {
|
if (response.success) {
|
||||||
setOpen(true)
|
setOpen(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -73,7 +73,7 @@ const AssingMatiereToSemestre = () => {
|
|||||||
let response = await window.matieres.insertUpdateMentionSemestre({ id, selectedSemestres })
|
let response = await window.matieres.insertUpdateMentionSemestre({ id, selectedSemestres })
|
||||||
|
|
||||||
console.log(response)
|
console.log(response)
|
||||||
if (response.changes) {
|
if (response.success) {
|
||||||
setOpen(true)
|
setOpen(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import React, { useRef, useState } from 'react'
|
import { useRef, useState } from 'react'
|
||||||
// import { Container, Row, Col, Form, Button, Card, InputGroup } from 'react-bootstrap';
|
// import { Container, Row, Col, Form, Button, Card, InputGroup } from 'react-bootstrap';
|
||||||
import { Container, Grid, Card, Typography, TextField, Button, InputAdornment } from '@mui/material'
|
import { Container, Grid, Card, Typography, TextField, Button, InputAdornment } from '@mui/material'
|
||||||
import { FaUserCircle, FaLock, FaUser } from 'react-icons/fa'
|
import { FaUserCircle, FaLock, FaUser } from 'react-icons/fa'
|
||||||
@ -50,7 +50,7 @@ const Login = () => {
|
|||||||
// Redirect to main window
|
// Redirect to main window
|
||||||
setToken(JSON.stringify(response.user))
|
setToken(JSON.stringify(response.user))
|
||||||
} else {
|
} else {
|
||||||
invalidCredential(userNameError.current)
|
invalidCredential(userNameError.current, response.error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -260,7 +260,7 @@ const Matieres = () => {
|
|||||||
|
|
||||||
const deleteButton = async (id) => {
|
const deleteButton = async (id) => {
|
||||||
let response = await window.matieres.deleteMatiere({ id })
|
let response = await window.matieres.deleteMatiere({ id })
|
||||||
if (response.changes) {
|
if (response.success) {
|
||||||
const updatedMatieres = matiere.filter((matiere) => matiere.id !== id)
|
const updatedMatieres = matiere.filter((matiere) => matiere.id !== id)
|
||||||
setMatiere(updatedMatieres)
|
setMatiere(updatedMatieres)
|
||||||
setIsDeleted(true)
|
setIsDeleted(true)
|
||||||
|
|||||||
@ -106,7 +106,7 @@ const Mentions = () => {
|
|||||||
|
|
||||||
const deleteButton = async (id) => {
|
const deleteButton = async (id) => {
|
||||||
let response = await window.mention.deleteMention({ id })
|
let response = await window.mention.deleteMention({ id })
|
||||||
if (response.changes) {
|
if (response.success) {
|
||||||
const updatedMentions = mentions.filter((mention) => mention.id !== id)
|
const updatedMentions = mentions.filter((mention) => mention.id !== id)
|
||||||
setMentions(updatedMentions)
|
setMentions(updatedMentions)
|
||||||
setIsDeleted(true)
|
setIsDeleted(true)
|
||||||
|
|||||||
@ -42,8 +42,9 @@ const ModalAddProf = ({ open, onClose, matiere_id, onSubmitSuccess }) => {
|
|||||||
const handleSubmit = async (e) => {
|
const handleSubmit = async (e) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
let response = await window.matieres.insertProf(formData)
|
let response = await window.matieres.insertProf(formData)
|
||||||
|
console.log(response)
|
||||||
|
|
||||||
if (response.changes) {
|
if (response.success) {
|
||||||
onSubmitSuccess(true)
|
onSubmitSuccess(true)
|
||||||
onClose() // Close the modal after submission
|
onClose() // Close the modal after submission
|
||||||
setFormData({
|
setFormData({
|
||||||
|
|||||||
@ -116,7 +116,9 @@ const Niveau = () => {
|
|||||||
|
|
||||||
const deleteButton = async (id) => {
|
const deleteButton = async (id) => {
|
||||||
let response = await window.niveaus.deleteNiveaus({ id })
|
let response = await window.niveaus.deleteNiveaus({ id })
|
||||||
if (response.changes) {
|
console.log(response);
|
||||||
|
|
||||||
|
if (response.success) {
|
||||||
const updatedNiveaus = niveaus.filter((niveau) => niveau.id !== id)
|
const updatedNiveaus = niveaus.filter((niveau) => niveau.id !== id)
|
||||||
setNiveau(updatedNiveaus)
|
setNiveau(updatedNiveaus)
|
||||||
setIsDeleted(true)
|
setIsDeleted(true)
|
||||||
|
|||||||
@ -66,7 +66,7 @@ const ParcourMatiere = ({ open, onClose, matiere_id }) => {
|
|||||||
const formSubmit = async (e) => {
|
const formSubmit = async (e) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
let response = await window.notesysteme.parcourMatiere(formData)
|
let response = await window.notesysteme.parcourMatiere(formData)
|
||||||
if (response.changes) {
|
if (response.success) {
|
||||||
onClose()
|
onClose()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import React, { useEffect, useRef, useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
import classe from '../assets/AllStyleComponents.module.css'
|
import classe from '../assets/AllStyleComponents.module.css'
|
||||||
import classeHome from '../assets/Home.module.css'
|
import classeHome from '../assets/Home.module.css'
|
||||||
import Paper from '@mui/material/Paper'
|
import Paper from '@mui/material/Paper'
|
||||||
@ -9,6 +9,7 @@ import { FaCalendarAlt } from 'react-icons/fa'
|
|||||||
import svgError from '../assets/error.svg'
|
import svgError from '../assets/error.svg'
|
||||||
import svgSuccess from '../assets/success.svg'
|
import svgSuccess from '../assets/success.svg'
|
||||||
import { BsCalendar2Date } from 'react-icons/bs'
|
import { BsCalendar2Date } from 'react-icons/bs'
|
||||||
|
import dayjs from 'dayjs'
|
||||||
|
|
||||||
const SingleAnneeScolaire = () => {
|
const SingleAnneeScolaire = () => {
|
||||||
const { id } = useParams()
|
const { id } = useParams()
|
||||||
@ -33,8 +34,8 @@ const SingleAnneeScolaire = () => {
|
|||||||
setFormData((prev) => ({
|
setFormData((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
code: scolaire.code,
|
code: scolaire.code,
|
||||||
debut: scolaire.debut,
|
debut: dayjs(scolaire.debut).format('YYYY-MM-DD'),
|
||||||
fin: scolaire.fin,
|
fin: dayjs(scolaire.fin).format('YYYY-MM-DD'),
|
||||||
id: scolaire.id
|
id: scolaire.id
|
||||||
}))
|
}))
|
||||||
}, [scolaire])
|
}, [scolaire])
|
||||||
@ -56,7 +57,7 @@ const SingleAnneeScolaire = () => {
|
|||||||
|
|
||||||
let response = await window.anneescolaire.updateAnneeScolaire(formData)
|
let response = await window.anneescolaire.updateAnneeScolaire(formData)
|
||||||
|
|
||||||
if (response.changes) {
|
if (response.success) {
|
||||||
setOpen(true)
|
setOpen(true)
|
||||||
setStatus(200)
|
setStatus(200)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -80,10 +80,10 @@ const SingleMatiere = () => {
|
|||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
const response = await window.matieres.updateMatiere(formData)
|
const response = await window.matieres.updateMatiere(formData)
|
||||||
console.log(response)
|
console.log(response)
|
||||||
if (response.changes) {
|
if (response.success) {
|
||||||
setStatus(200)
|
setStatus(200)
|
||||||
setMessage('Modification a été effectuée avec succès')
|
setMessage('Modification a été effectuée avec succès')
|
||||||
} else if (response.code) {
|
} else {
|
||||||
setStatus(400)
|
setStatus(400)
|
||||||
setMessage('La matière existe déjà dans la base !')
|
setMessage('La matière existe déjà dans la base !')
|
||||||
}
|
}
|
||||||
|
|||||||
@ -53,19 +53,20 @@ const SingleNiveau = () => {
|
|||||||
allNiveau.map((niv) => {
|
allNiveau.map((niv) => {
|
||||||
niveauNom.push(niv.nom)
|
niveauNom.push(niv.nom)
|
||||||
})
|
})
|
||||||
let validation = validationSingleNiveau(nomRef.current, errorRef.current, niveauNom)
|
// let validation = validationSingleNiveau(nomRef.current, errorRef.current, niveauNom)
|
||||||
|
|
||||||
if (validation) {
|
// if (validation) {
|
||||||
let response = await window.niveaus.updateSingleNiveau(formData)
|
let response = await window.niveaus.updateSingleNiveau(formData)
|
||||||
|
console.log(response)
|
||||||
|
|
||||||
if (response.changes == 1) {
|
if (response.success) {
|
||||||
setOpen(true)
|
setOpen(true)
|
||||||
}
|
|
||||||
|
|
||||||
if (response.code) {
|
|
||||||
nomError.current.textContent = `${formData.nom} existe déjà`
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!response.success) {
|
||||||
|
errorRef.current.textContent = `${formData.nom} existe déjà`
|
||||||
|
}
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -81,7 +81,7 @@ const SinleMention = () => {
|
|||||||
try {
|
try {
|
||||||
let response = await window.mention.updateMention(formData)
|
let response = await window.mention.updateMention(formData)
|
||||||
|
|
||||||
if (response.changes) {
|
if (response.success) {
|
||||||
setOpen(true)
|
setOpen(true)
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@ -52,7 +52,7 @@ const UpdateModalProf = ({ open, onClose, matiere_id, onSubmitSuccess }) => {
|
|||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
let response = await window.matieres.updateProf(formData)
|
let response = await window.matieres.updateProf(formData)
|
||||||
|
|
||||||
if (response.changes) {
|
if (response.success) {
|
||||||
onSubmitSuccess(true)
|
onSubmitSuccess(true)
|
||||||
onClose() // Close the modal after submission
|
onClose() // Close the modal after submission
|
||||||
}
|
}
|
||||||
|
|||||||
@ -59,7 +59,7 @@ const AddParcours = ({ open, onClose, onSubmitSuccess, id }) => {
|
|||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
let response = await window.notesysteme.updateParcours(formData)
|
let response = await window.notesysteme.updateParcours(formData)
|
||||||
|
|
||||||
if (response.changes) {
|
if (response.success) {
|
||||||
onSubmitSuccess(true)
|
onSubmitSuccess(true)
|
||||||
onClose() // Close the modal after submission
|
onClose() // Close the modal after submission
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,6 +45,6 @@ export const ValidationLogin = (userNameRef, password, userNameError, passwordEr
|
|||||||
*
|
*
|
||||||
* @param {any} userNameError
|
* @param {any} userNameError
|
||||||
*/
|
*/
|
||||||
export const invalidCredential = (userNameError) => {
|
export const invalidCredential = (userNameError, textC) => {
|
||||||
userNameError.textContent = "Nom d'utilisateur ou Mot de passe incorrect"
|
userNameError.textContent = textC
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user