From 1b03e95b6089b55486bd9aab56a5a77bede13d70 Mon Sep 17 00:00:00 2001 From: soudarsane Date: Tue, 20 Jun 2023 10:29:44 +0200 Subject: [PATCH] =?UTF-8?q?partie=20admin=20onglets=20utilisateurs=20et=20?= =?UTF-8?q?demandes=20termin=C3=A9s=20(reste=20l'onglet=20accueil=20et=20o?= =?UTF-8?q?ffres=20+=20rediriger=20vers=20page=20candidat=20et=20afficher?= =?UTF-8?q?=20bouton=20administrer)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/AdminController.ts | 35 ++++- app/repository/UserRepository.ts | 47 +++++- app/routes/AdminRouter.ts | 1 + app/table.sql | 2 +- app/views/admin/demandes.ejs | 182 +++++++++++++++--------- app/views/admin/modifierUtilisateur.ejs | 4 +- app/views/admin/utilisateur.ejs | 19 ++- app/views/admin/utilisateurs.ejs | 8 +- 8 files changed, 210 insertions(+), 88 deletions(-) diff --git a/app/controllers/AdminController.ts b/app/controllers/AdminController.ts index 965325f..c8fc7dd 100644 --- a/app/controllers/AdminController.ts +++ b/app/controllers/AdminController.ts @@ -4,8 +4,9 @@ import {OffreDePoste} from "../entity/OffreDePoste"; import {UserRepository} from "../repository/UserRepository"; import {User} from "../entity/User"; import {loggedInNoRedirection} from "../passport/passportFunctions"; -import {OrganisationRepository} from "../repository/OrganisationRepository"; import {Alert} from "../utils/Alert"; +import {OrganisationRepository} from "../repository/OrganisationRepository"; +import {Organisation} from "../entity/Organisation"; export class AdminController { static index(req: express.Request, res: express.Response) { @@ -14,8 +15,10 @@ export class AdminController { static utilisateurs(req: express.Request, res: express.Response) { UserRepository.getAll().then((users: User[]) => { - console.log(users); - res.render("admin/utilisateurs", { title: "Utilisateurs", users, userLogged: loggedInNoRedirection(req, res)}); + OrganisationRepository.getAll().then((organisations : Organisation[]) => { + console.log(users); + res.render("admin/utilisateurs", { title: "Utilisateurs", organisations: organisations, users, userLogged: loggedInNoRedirection(req, res)}); + }); }); } @@ -70,10 +73,32 @@ export class AdminController { } } + static async supprimerUtilisateur(req: express.Request, res: express.Response) { + let email = req.params.email; + const alerts: Alert[] = []; + + await UserRepository.supprimerUtilisateur(email).then((user: User) => { + let alert = new Alert("success", "L'utilisateur a bien été supprimé"); + alerts.push(alert); + }) + .catch((err) => { + let alert = new Alert("danger", "L'utilisateur n'a pas été supprimé"); + alerts.push(alert); + console.log(err); + }); + + UserRepository.getAll().then((users: User[]) => { + res.render("admin/utilisateurs", { title: "Utilisateurs", users, alerts: alerts, userLogged: loggedInNoRedirection(req, res)}); + }); + } + static demandes(req: express.Request, res: express.Response) { UserRepository.getRecruiterDemand().then((users: User[]) => { - //console.log(users); - res.render("admin/demandes", {title: "Demandes", users: users, userLogged: loggedInNoRedirection(req, res)}); + UserRepository.getOldRecruiterDemand().then((oldUsers: User[]) => { + OrganisationRepository.getAll().then((organisations : Organisation[]) => { + res.render("admin/demandes", {title: "Demandes", users: users, organisations: organisations, oldUsers: oldUsers, userLogged: loggedInNoRedirection(req, res)}); + }); + }); }); } diff --git a/app/repository/UserRepository.ts b/app/repository/UserRepository.ts index 4dc84b8..1cd1629 100644 --- a/app/repository/UserRepository.ts +++ b/app/repository/UserRepository.ts @@ -122,16 +122,52 @@ export class UserRepository { ); } - delete(id: number): Promise { - throw new Error("Method not implemented."); + static supprimerUtilisateur(email:string): Promise { + const query = `DELETE FROM ${UserRepository.tableName} + WHERE email = ?`; + return new Promise( + (resolve, reject) => + pool.query(query, [email], (err, result) => { + if (err) { + return reject(err); + } + return resolve(result); + } + ) + ); } - static getRecruiterDemand(): Promise<[User]> { const query = `SELECT u.email, u.nom, u.prenom, o.siren, o.nom as organisation, o.type, o.siege FROM ${UserRepository.tableName} u INNER JOIN ${OrganisationRepository.tableName} o using (siren) - WHERE u.demande_organisation = 'En cours'`; + WHERE u.demande_organisation = 'En cours' + OR u.demande_organisation = 'refus' + OR u.demande_organisation = 'acceptation'`; + return new Promise<[User]>( + (resolve, reject) => + pool.query(query, (err, result) => { + if (err) { + return reject(err); + } + if(result[0]){ + console.log(result[0]); + let organisation = new Organisation(result[0].siren, result[0].organisation, result[0].type, result[0].siege); + result[0].organisation = organisation; + console.log(result); + } + return resolve(result); + } + ) + ); + } + + static getOldRecruiterDemand(): Promise<[User]> { + const query = `SELECT u.email, u.nom, u.prenom, u.demande_organisation, o.siren, o.nom as organisation, o.type, o.siege + FROM ${UserRepository.tableName} u + INNER JOIN ${OrganisationRepository.tableName} o using (siren) + WHERE u.demande_organisation = 'refus' + OR u.demande_organisation = 'acceptation'`; return new Promise<[User]>( (resolve, reject) => pool.query(query, (err, result) => { @@ -170,8 +206,7 @@ export class UserRepository { static setDemandRefused(email: string): Promise<[User]> { const query = `UPDATE ${UserRepository.tableName} SET demande_organisation = 'refus', - role='Candidat', - siren=null + role='Candidat' WHERE email = ?`; return new Promise<[User]>( (resolve, reject) => diff --git a/app/routes/AdminRouter.ts b/app/routes/AdminRouter.ts index 10d62b4..9789869 100644 --- a/app/routes/AdminRouter.ts +++ b/app/routes/AdminRouter.ts @@ -17,6 +17,7 @@ adminRouter.get("/utilisateurs", AdminController.utilisateurs); adminRouter.get("/utilisateur/:email", AdminController.utilisateur); adminRouter.get("/modifierUtilisateur/:email", AdminController.modifierUtilisateur); adminRouter.post("/modifierUtilisateur/:email", AdminController.modifierUtilisateur); +adminRouter.get("/supprimerUtilisateur/:email", AdminController.supprimerUtilisateur); adminRouter.get("/demandes", AdminController.demandes); adminRouter.get("/demande/:email", AdminController.demande); diff --git a/app/table.sql b/app/table.sql index 693507a..bfdd177 100644 --- a/app/table.sql +++ b/app/table.sql @@ -97,7 +97,7 @@ CREATE TABLE `Utilisateur` ((demande_organisation = 'En cours' OR demande_organisation = 'acceptation' OR role = 'Recruteur') AND siren IS NOT NULL) OR - ((demande_organisation = 'refus' OR role = 'Administrateur' OR role = 'Candidat') AND siren IS NULL) + ((demande_organisation = 'refus' OR role = 'Administrateur' OR role = 'Candidat')) ) ); diff --git a/app/views/admin/demandes.ejs b/app/views/admin/demandes.ejs index b685d1b..6398d08 100644 --- a/app/views/admin/demandes.ejs +++ b/app/views/admin/demandes.ejs @@ -1,16 +1,3 @@ - - - - - Demandes - - - - - <%- include('../partials/adminHeader.ejs') %>.
@@ -21,66 +8,123 @@
Entreprise
- - - - - - - - - - - - - <% users.forEach((user) => { %> - - - - - - - - - <% }) %> - -
idNomPrénomEntrepriseDétailsStatut
<%= user.email %><%= user.nom %><%= user.prenom %><%= user.organisation.nom %> - Détails - - Refuser - Accepter -
-
- - - - + row.style.display = shouldShowRow ? "table-row" : "none"; + }); + } - - + const entrepriseFilter = document.querySelector("#entrepriseFilter"); + entrepriseFilter.addEventListener("change", filterDemandes); + + + + diff --git a/app/views/admin/modifierUtilisateur.ejs b/app/views/admin/modifierUtilisateur.ejs index c60175e..0ffd356 100644 --- a/app/views/admin/modifierUtilisateur.ejs +++ b/app/views/admin/modifierUtilisateur.ejs @@ -53,7 +53,7 @@
- +
@@ -86,7 +86,7 @@
- Retour + Retour
diff --git a/app/views/admin/utilisateur.ejs b/app/views/admin/utilisateur.ejs index ec5ceae..b9691e8 100644 --- a/app/views/admin/utilisateur.ejs +++ b/app/views/admin/utilisateur.ejs @@ -81,12 +81,29 @@
Retour Modifier - Supprimer +
+ diff --git a/app/views/admin/utilisateurs.ejs b/app/views/admin/utilisateurs.ejs index 72dc433..cf60056 100644 --- a/app/views/admin/utilisateurs.ejs +++ b/app/views/admin/utilisateurs.ejs @@ -20,10 +20,10 @@
Entreprise
Profil