dernier mise a jour university
This commit is contained in:
parent
eb7d02e472
commit
82b5e6a68e
@ -77,22 +77,22 @@ const createEtudiantsTableQuery = `
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
nom VARCHAR(250) DEFAULT NULL,
|
||||
prenom VARCHAR(250) DEFAULT NULL,
|
||||
photos TEXT NOT NULL,
|
||||
date_de_naissances DATE NOT 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 NOT NULL,
|
||||
status INTEGER DEFAULT NULL,
|
||||
mention_id INTEGER NOT NULL, -- Clé étrangère vers mentions
|
||||
num_inscription TEXT NOT NULL UNIQUE,
|
||||
sexe VARCHAR(20) NOT NULL,
|
||||
num_inscription TEXT NOT NULL,
|
||||
sexe VARCHAR(20) DEFAULT NULL,
|
||||
cin VARCHAR(250) DEFAULT NULL,
|
||||
date_delivrance DEFAULT NULL,
|
||||
nationalite DATE NOT NULL,
|
||||
annee_bacc DATE NOT NULL,
|
||||
serie VARCHAR(20) NOT NULL,
|
||||
nationalite DATE DEFAULT NULL,
|
||||
annee_bacc DATE DEFAULT NULL,
|
||||
serie VARCHAR(20) DEFAULT NULL,
|
||||
boursier BOOLEAN DEFAULT FALSE,
|
||||
domaine VARCHAR(250) NOT NULL,
|
||||
contact VARCHAR(20) NOT NULL,
|
||||
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,
|
||||
|
||||
@ -3,12 +3,13 @@ const path = require('path')
|
||||
const XLSX = require('xlsx')
|
||||
const { getCompressedDefaultImage } = require('../function/GetImageDefaault')
|
||||
const { parse } = require('csv-parse/sync')
|
||||
const { insertEtudiant, updateEtudiant } = require('../Models/Etudiants')
|
||||
const { insertEtudiant } = require('../Models/Etudiants')
|
||||
const { database } = require('../database')
|
||||
const { getMentions } = require('../Models/Mentions')
|
||||
const dayjs = require('dayjs')
|
||||
const { getStatusMention } = require('../function/Helper')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
// const customParseFormatt = require('dayjs/plu')
|
||||
dayjs.extend(customParseFormat)
|
||||
|
||||
// Function to convert any date format to 'YYYY-MM-DD'
|
||||
@ -21,7 +22,8 @@ function convertToISODate(input) {
|
||||
'DD-MM-YYYY',
|
||||
'MM-DD-YYYY',
|
||||
'DD/MM/YY',
|
||||
'MM/DD/YY'
|
||||
'MM/DD/YY',
|
||||
'DD-MMM-YY'
|
||||
]
|
||||
const parsedDate = dayjs(input, formats, true) // Strict parsing to ensure formats are matched correctly
|
||||
|
||||
@ -30,6 +32,12 @@ function convertToISODate(input) {
|
||||
return parsedDate.format('YYYY-MM-DD')
|
||||
}
|
||||
|
||||
// Handle cases like "Vers 2000"
|
||||
const versMatch = typeof input === 'string' && input.match(/vers\s*(\d{4})/i);
|
||||
if (versMatch) {
|
||||
return `${versMatch[1]}-01-01`; // Return in ISO format
|
||||
}
|
||||
|
||||
function excelDateToJSDate(serial) {
|
||||
const utc_days = Math.floor(serial - 25569); // days from Jan 1, 1970
|
||||
const utc_value = utc_days * 86400; // seconds in a day
|
||||
@ -75,11 +83,17 @@ async function importFileToDatabase(filePath) {
|
||||
return
|
||||
}
|
||||
|
||||
// ✅ Count number of data rows
|
||||
const numberOfLines = records.length;
|
||||
console.log(`Number of data rows: ${numberOfLines}`);
|
||||
|
||||
try {
|
||||
let error = true
|
||||
let message = ''
|
||||
|
||||
// Vérifier les données en une seule boucle
|
||||
let ar = [];
|
||||
let oldNum = '';
|
||||
for (const row of records) {
|
||||
if (
|
||||
!row.nom ||
|
||||
@ -97,8 +111,9 @@ async function importFileToDatabase(filePath) {
|
||||
!row.serie ||
|
||||
!row.code_redoublement ||
|
||||
!row.boursier ||
|
||||
!row.domaine ||
|
||||
!row.contact
|
||||
!row.domaine
|
||||
// ||
|
||||
// !row.contact
|
||||
) {
|
||||
if (!row.nom) {
|
||||
message = "Le champ 'nom' est inconnu"
|
||||
@ -136,9 +151,10 @@ async function importFileToDatabase(filePath) {
|
||||
message = "Le champ 'boursier' est inconnu"
|
||||
} else if (!row.domaine) {
|
||||
message = "Le champ 'domaine' est inconnu"
|
||||
} else if (!row.contact) {
|
||||
message = "Le champ 'contact' est inconnu"
|
||||
}
|
||||
// else if (!row.contact) {
|
||||
// message = "Le champ 'contact' est inconnu"
|
||||
// }
|
||||
error = false
|
||||
break
|
||||
}
|
||||
@ -153,7 +169,7 @@ async function importFileToDatabase(filePath) {
|
||||
// Si aucune erreur, insérer les données en batch
|
||||
if (error !== false) {
|
||||
// Utiliser transaction pour éviter une latence si l'insertion dépasse 100
|
||||
database.transaction(async () => {
|
||||
database.transaction(() => {
|
||||
for (const row of records) {
|
||||
// Convert row.mention to uppercase and compare with ListMention.nom and ListMention.uniter (also converted to uppercase)
|
||||
const matchedMention = ListMention.find(
|
||||
@ -166,62 +182,43 @@ async function importFileToDatabase(filePath) {
|
||||
if (matchedMention) {
|
||||
row.mention = matchedMention.id
|
||||
}
|
||||
row.num_inscription = row.num_inscription.toString()
|
||||
|
||||
const inscription = database.prepare(
|
||||
'SELECT id FROM etudiants WHERE num_inscription = ?'
|
||||
).get(row.num_inscription)
|
||||
|
||||
// Check if the student already exists in the database
|
||||
if (inscription) {
|
||||
|
||||
updateEtudiant(
|
||||
row.nom,
|
||||
row.prenom,
|
||||
getCompressedDefaultImage(),
|
||||
convertToISODate(row.date_naissance),
|
||||
row.niveau,
|
||||
row.annee_scolaire,
|
||||
getStatusMention(row.code_redoublement),
|
||||
row.mention,
|
||||
row.num_inscription,
|
||||
inscription.id, // Assuming 'id' is the primary key of the student
|
||||
row.sexe,
|
||||
row.nationaliter,
|
||||
row.cin,
|
||||
row.date_de_delivrance ? convertToISODate(row.date_de_delivrance) : null,
|
||||
row.annee_baccalaureat,
|
||||
row.serie,
|
||||
row.boursier,
|
||||
row.domaine,
|
||||
row.contact,
|
||||
null
|
||||
ar.push(row)
|
||||
console.log(ar.length, 'create');
|
||||
try {
|
||||
let compare = row.num_inscription;
|
||||
if (compare == oldNum) {
|
||||
row.num_inscription = Number(row.num_inscription + 1);
|
||||
}
|
||||
console.log(
|
||||
insertEtudiant(
|
||||
row.nom,
|
||||
row.prenom,
|
||||
getCompressedDefaultImage(),
|
||||
convertToISODate(row.date_naissance),
|
||||
row.niveau,
|
||||
row.annee_scolaire,
|
||||
getStatusMention(row.code_redoublement),
|
||||
row.num_inscription,
|
||||
row.mention,
|
||||
row.sexe,
|
||||
row.nationaliter,
|
||||
row.cin,
|
||||
row.date_de_delivrance,
|
||||
row.annee_baccalaureat,
|
||||
row.serie,
|
||||
row.boursier,
|
||||
row.domaine,
|
||||
row.contact,
|
||||
null
|
||||
)
|
||||
);
|
||||
oldNum = compare
|
||||
|
||||
console.log(inscription)
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
|
||||
} else {
|
||||
|
||||
// Insert the student data with the updated mention ID
|
||||
insertEtudiant(
|
||||
row.nom,
|
||||
row.prenom,
|
||||
getCompressedDefaultImage(),
|
||||
convertToISODate(row.date_naissance),
|
||||
row.niveau,
|
||||
row.annee_scolaire,
|
||||
getStatusMention(row.code_redoublement),
|
||||
row.num_inscription,
|
||||
row.mention,
|
||||
row.sexe,
|
||||
row.nationaliter,
|
||||
row.cin,
|
||||
row.date_de_delivrance,
|
||||
row.annee_baccalaureat,
|
||||
row.serie,
|
||||
row.boursier,
|
||||
row.domaine,
|
||||
row.contact
|
||||
)
|
||||
}
|
||||
}
|
||||
})()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user