Browse Source

model users transformed to mysql

master
fabriceBJHost 5 months ago
parent
commit
290f5747fb
  1. 149
      database/Models/Users.backup.js
  2. 242
      database/Models/Users.js
  3. 444
      database/database.backup.js
  4. 717
      database/database.js
  5. 307
      database/database2.js
  6. 15
      jsconfig.json
  7. 2
      package.json
  8. 801
      src/main/backup.js
  9. 1207
      src/main/index.js
  10. 210
      src/preload/index.backup.js
  11. 4
      src/preload/index.js

149
database/Models/Users.backup.js

@ -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
}

242
database/Models/Users.js

@ -1,149 +1,177 @@
const { database } = require('../database')
const { pool } = require('../database')
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) {
const saltRounds = 10
const saltRound = 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
const hashedPassword = await bcrypt.hash(password, saltRound)
const sql = `
INSERT INTO users (username, email, password, roles) VALUES (?, ?, ?, ?)
`
const [result] = await pool.query(sql, [username, email, hashedPassword, roles])
// result.insertId contains the new user ID
return {
success: true,
id: result.insertId
}
} catch (error) {
return { success: false, error: error }
}
}
// Function to fetch all users from the database
/**
* function to get all users
* @returns {Array}
*/
async function getAllUsers() {
const getUsersQuery = database.prepare('SELECT * FROM users')
let response = await getUsersQuery.all()
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])
return response
if (rows.length > 0) {
return rows[0]
} else {
return null
}
}
// 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) = ?')
/**
* 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 {
// 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')
const [rows] = pool.query(sql, username)
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' }
}
} catch (err) {
console.error('Error during login:', err)
// delete the key password before return a user object
delete user.password
return { success: true, user }
} catch (error) {
return { error: 'erreur lors du login' }
}
}
/**
* function to use in forgit password
*
* @param {*} email
* @param {*} password
* @param {*} passwordConfirmation
* @returns
* function to update users
* @param {String} username
* @param {String} email
* @param {String} password
* @param {String} roles
* @param {Number} id
* @returns {Object}
*/
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)
async function updateUser(username, email, password, roles, id) {
let sql, params
if (user) {
const updateQuery = database.prepare('UPDATE users SET password = ? WHERE email = ?')
const hashedPassword = await bcrypt.hash(password, saltRounds)
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 {
await updateQuery.run(hashedPassword, email)
try {
const [result] = await pool.query(sql, params)
return { message: 'Mot de passe modifier avec succes', status: 200 }
} catch (error) {
console.error('Error updating password:', error)
if (result.affectedRows === 0) {
return {
success: false,
message: 'Utilisateur non trouvé ou aucune modification effectuée.'
}
} else {
return { message: 'Email non trouver', status: 404 }
}
} else {
return { message: 'Mot de passe ne correspond pas', status: 401 }
return {
success: true,
message: 'Utilisateur mis à jour avec succès.'
}
} catch (error) {
return { success: false, error: 'Erreur veullez réeseyer' }
}
}
/**
* function to use when updatign the users
*
* @param {*} username
* @param {*} email
* @param {*} password
* @param {*} id
* @returns promise
* function to delete users
* @param {Number} id
* @returns {Object}
*/
async function updateUser(username, email, password, id) {
const saltRounds = 10
async function deleteUser(id) {
const sql = `DELETE FROM users WHERE id = ?`
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)
const [result] = await pool.query(sql, [id])
if (result.affectedRows === 0) {
return {
success: false,
message: 'Utilisateur non trouvé.'
}
} 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
return {
success: true,
message: 'Utilisateur supprimé avec succès.'
}
} catch (error) {
console.error('Error updating user:', error)
throw error // Throw error to handle it in calling function if needed
console.error(error)
return {
success: false,
error: 'Erreur lors de la suppression, veuillez réessayer.'
}
}
}
module.exports = {
getAllUsers,
insertUser,
loginUser,
forgotPassword,
updateUser
getAllUsers,
getUserById,
loginUsers,
updateUser,
deleteUser
}

444
database/database.backup.js

@ -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
}

717
database/database.js

@ -1,444 +1,307 @@
const sqlite = require('better-sqlite3')
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
})
// Construct the database path using the detected IP
let dbPath = `./base/data.db`;
async function createTables() {
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)
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()
}
}
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;
`)
async function insertDefaultAdmin() {
const conn = await pool.getConnection()
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])
}
})()
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) {
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()
} 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
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()
}
}
// 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
pool,
createTables,
insertDefaultAdmin,
insertStatusesIfNotExist
}

307
database/database2.js

@ -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
}

15
jsconfig.json

@ -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/*"
]
}

2
package.json

@ -36,6 +36,7 @@
"@emotion/styled": "^11.13.0",
"@mui/material": "^6.1.1",
"@mui/x-data-grid": "^7.18.0",
"@tanstack/react-query": "^5.83.0",
"ag-psd": "^22.0.2",
"axios": "^1.9.0",
"bcryptjs": "^2.4.3",
@ -52,6 +53,7 @@
"html2canvas": "^1.4.1",
"jspdf": "^2.5.2",
"jspdf-autotable": "^5.0.2",
"mysql2": "^3.14.2",
"papaparse": "^5.4.1",
"pdf-lib": "^1.17.1",
"qrcode": "^1.5.4",

801
src/main/backup.js

@ -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'
const path = require('path')
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 {
insertEtudiant,
getSingleEtudiant,
FilterDataByNiveau,
updateEtudiant
updateEtudiant,
changePDP,
updateParcours,
createTranche,
getTranche,
updateTranche,
deleteTranche,
getSingleTranche
} = require('../../database/Models/Etudiants')
const { insertNiveau } = require('../../database/Models/Niveau')
const { insertNote } = require('../../database/Models/Notes')
// declare mainWindow in the global scope
const {
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 and tray in the global scope
let mainWindow
let tray = null
updateCurrentYears()
updateStudents()
autoUpdater.setFeedURL({
provider: 'generic',
url: `${URL}/latest` // Ensure this points to the folder containing latest.yml
})
function createWindow() {
// Create the browser window.
mainWindow = new BrowserWindow({
width: 1000,
minWidth: 1000,
height: 670,
minHeight: 670,
width: 1375,
minWidth: 1375,
height: 740,
minHeight: 740,
show: false,
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 } : {}),
webPreferences: {
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.maximize() // Maximiser la fenêtre
mainWindow.show()
})
@ -44,44 +142,134 @@ function createWindow() {
return { action: 'deny' }
})
// HMR for renderer base on electron-vite cli.
// Load the remote URL for development or the local html file for production.
// Load the appropriate URL based on environment
if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
mainWindow.loadURL(process.env['ELECTRON_RENDERER_URL'])
} else {
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()
}
})
}
// Function to create the system tray
function createTray() {
const iconPath = icon // Use your icon path here
tray = new Tray(iconPath)
// 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()
})
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.whenReady().then(() => {
// Set app user model id for windows
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) => {
optimizer.watchWindowShortcuts(window)
})
// IPC test
ipcMain.on('pingpong', () => console.log('pongsss'))
createWindow()
createTray() // Create the tray icon
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()
})
})
// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
// When an update is available
autoUpdater.on('update-available', () => {
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', () => {
if (process.platform !== 'darwin') {
app.quit()
@ -126,9 +314,9 @@ ipcMain.handle('forgotPassword', async (event, credentials) => {
// event for updating users
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
})
@ -147,8 +335,27 @@ ipcMain.handle('minimize', async () => {
// event for insert etudiants
ipcMain.handle('insertEtudiant', async (event, credentials) => {
const { nom, prenom, photos, date_de_naissances, niveau, annee_scolaire, num_inscription } =
credentials
const {
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(
nom,
@ -157,7 +364,19 @@ ipcMain.handle('insertEtudiant', async (event, credentials) => {
date_de_naissances,
niveau,
annee_scolaire,
num_inscription
status,
num_inscription,
mention_id,
sexe,
nationaliter,
cin,
date_delivrence,
annee_bacc,
serie,
boursier,
domaine,
contact,
parcours
)
return insert
@ -192,8 +411,28 @@ ipcMain.handle('insertNiveau', async (event, credentials) => {
// event for updating etudiants
ipcMain.handle('updateETudiants', async (event, credentials) => {
const { nom, prenom, photos, date_de_naissances, niveau, annee_scolaire, num_inscription, id } =
credentials
const {
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(
nom,
@ -202,54 +441,472 @@ ipcMain.handle('updateETudiants', async (event, credentials) => {
date_de_naissances,
niveau,
annee_scolaire,
status,
mention_id,
num_inscription,
id
id,
sexe,
nationalite,
cin,
date_delivrance,
annee_bacc,
serie,
boursier,
domaine,
contact,
parcours
)
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
ipcMain.handle('insertNote', async (event, credentials) => {
const {
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 { etudiant_id, etudiant_niveau, mention_id, formData, annee_scolaire } = credentials
const insert = await insertNote(
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
etudiant_niveau,
mention_id,
formData,
annee_scolaire
)
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
})

1207
src/main/index.js

File diff suppressed because it is too large

210
src/preload/index.backup.js

@ -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
}

4
src/preload/index.js

@ -5,10 +5,6 @@ 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')

Loading…
Cancel
Save