diff --git a/app/controllers/AdminController.ts b/app/controllers/AdminController.ts index c8fc7dd..a751ce8 100644 --- a/app/controllers/AdminController.ts +++ b/app/controllers/AdminController.ts @@ -7,6 +7,8 @@ import {loggedInNoRedirection} from "../passport/passportFunctions"; import {Alert} from "../utils/Alert"; import {OrganisationRepository} from "../repository/OrganisationRepository"; import {Organisation} from "../entity/Organisation"; +import {FicheDePoste} from "../entity/FicheDePoste"; +import {FicheDePosteRepository} from "../repository/FicheDePosteRepository"; export class AdminController { static index(req: express.Request, res: express.Response) { @@ -140,5 +142,90 @@ export class AdminController { res.render("admin/offre", {title: "Offre", offer: offer, userLogged: loggedInNoRedirection(req, res)}); }) } + + static async modifierOffre(req: express.Request, res: express.Response) { + if (req.method === "POST") { + const alerts: Alert[] = []; + + let idOffre = req.body.idOffre; + let listePieces: string[] = []; + if (req.body.pieces && Array.isArray(req.body.pieces)) { + listePieces = req.body.pieces; + } + let nb_piece = listePieces.length + let listePiecesConcat = listePieces.join(","); + let date = req.body.dateValidite.split('/'); + let dateformat = `${date[2]}-${date[1]}-${date[0]}`; + let dateSQL = new Date(dateformat); + + let ficheDePoste = new FicheDePoste( + req.body.idFiche, + req.body.status, + req.body.responsable, + req.body.typeMetier, + req.body.lieu, + req.body.teletravail, + Number.parseInt(req.body.nbHeures), + req.body.salaire, + req.body.description, + "", + ) + + let offreDePoste = new OffreDePoste( + req.body.idFiche, + req.body.etatPublication, + dateSQL, + nb_piece, + listePiecesConcat, + ficheDePoste + ) + + await FicheDePosteRepository.update(ficheDePoste).then((fiche: FicheDePoste) => { + let alert = new Alert("success", "La fiche a été modifié"); + alerts.push(alert); + }).catch((err) => { + console.log(err); + let alert = new Alert("danger", "La fiche n'a pas été modifié"); + alerts.push(alert); + }); + + await OfferRepository.update(offreDePoste).then((offre: OffreDePoste) => { + let alert = new Alert("success", "L'offre a été modifié"); + alerts.push(alert); + }).catch((err) => { + console.log(err); + let alert = new Alert("danger", "L'offre n'a pas été modifié"); + alerts.push(alert); + }); + + OfferRepository.getById(Number.parseInt(idOffre)).then((offer: OffreDePoste) => { + console.log(offer); + res.render("admin/offre", {title: "Offre", offer: offer, alerts: alerts, userLogged: loggedInNoRedirection(req, res)}); + }) + }else{ + let numero = req.params.numero; + OfferRepository.getById(Number.parseInt(numero)).then((offer: OffreDePoste) => { + res.render("admin/modifierOffre", {title: "Modifier une offre", offer: offer, userLogged: loggedInNoRedirection(req, res)}); + }) + } + } + + static async supprimerOffre(req: express.Request, res: express.Response) { + const alerts: Alert[] = []; + let numero = req.params.numero; + await OfferRepository.supprimer(Number.parseInt(numero)).then((suppression: boolean) => { + console.log(suppression); + let alert = new Alert("success", "L'offre a été supprimée"); + alerts.push(alert); + }).catch((err) => { + console.log(err); + let alert = new Alert("danger", "L'offre n'a été supprimée"); + alerts.push(alert); + }); + OfferRepository.getAll().then((offers: OffreDePoste[]) => { + console.log(offers); + res.render("admin/offres", {title: "Offres", alerts: alerts, offers: offers, userLogged: loggedInNoRedirection(req, res)}); + }); + } } diff --git a/app/package-lock.json b/app/package-lock.json index c6a5fd9..99da544 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -12,10 +12,12 @@ "bcrypt": "^5.1.0", "body-parser": "^1.20.2", "cors": "^2.8.5", + "date-fns": "^2.30.0", "dotenv": "^16.0.3", "ejs": "^3.1.9", "express": "^4.18.2", "express-session": "^1.17.3", + "moment": "^2.29.4", "multer": "^1.4.5-lts.1", "mysql": "^2.18.1", "passport": "^0.6.0", @@ -35,6 +37,17 @@ "typescript": "^4.9.5" } }, + "node_modules/@babel/runtime": { + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.22.5.tgz", + "integrity": "sha512-ecjvYlnAaZ/KVneE/OdKYBYfgXV3Ptu6zQWmgEF7vwKhQnvVS6bjMD2XYgj+SNvQ1GfK/pjgokfPkC/2CO8CuA==", + "dependencies": { + "regenerator-runtime": "^0.13.11" + }, + "engines": { + "node": ">=6.9.0" + } + }, "node_modules/@mapbox/node-pre-gyp": { "version": "1.0.10", "resolved": "https://registry.npmjs.org/@mapbox/node-pre-gyp/-/node-pre-gyp-1.0.10.tgz", @@ -656,10 +669,12 @@ } }, "node_modules/date-fns": { - "version": "2.29.3", - "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.29.3.tgz", - "integrity": "sha512-dDCnyH2WnnKusqvZZ6+jA1O51Ibt8ZMRNkDZdyAyK4YfbDwa/cEmuztzG5pk6hqlp9aSBPYcjOlktquahGwGeA==", - "dev": true, + "version": "2.30.0", + "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.30.0.tgz", + "integrity": "sha512-fnULvOpxnC5/Vg3NCiWelDsLiUc9bRwAPs/+LfTLNvetFCtCTN+yQz15C/fs4AwX1R9K5GLtLfn8QW+dWisaAw==", + "dependencies": { + "@babel/runtime": "^7.21.0" + }, "engines": { "node": ">=0.11" }, @@ -1462,6 +1477,14 @@ "mkdirp": "bin/cmd.js" } }, + "node_modules/moment": { + "version": "2.29.4", + "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz", + "integrity": "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==", + "engines": { + "node": "*" + } + }, "node_modules/ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", @@ -1849,6 +1872,11 @@ "node": ">=8.10.0" } }, + "node_modules/regenerator-runtime": { + "version": "0.13.11", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.11.tgz", + "integrity": "sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg==" + }, "node_modules/require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", diff --git a/app/package.json b/app/package.json index 790fe14..385ded8 100644 --- a/app/package.json +++ b/app/package.json @@ -23,10 +23,12 @@ "bcrypt": "^5.1.0", "body-parser": "^1.20.2", "cors": "^2.8.5", + "date-fns": "^2.30.0", "dotenv": "^16.0.3", "ejs": "^3.1.9", "express": "^4.18.2", "express-session": "^1.17.3", + "moment": "^2.29.4", "multer": "^1.4.5-lts.1", "mysql": "^2.18.1", "passport": "^0.6.0", diff --git a/app/passport/passportFunctions.ts b/app/passport/passportFunctions.ts index 0bb7423..6e7f6de 100644 --- a/app/passport/passportFunctions.ts +++ b/app/passport/passportFunctions.ts @@ -110,6 +110,23 @@ export function loggedInNoRedirection(req:any, res:any) { } } +// Middleware pour vérifier la connexion + le rôle de l'utilisateur pouvant être de 2 profils différents +function checkRoleTwoProfile(role:any, role2:any) { + return function (req:any, res:any, next:any) { + if (req.isAuthenticated() && (req.user.role === role || req.user.role === role2)) { + return next(); + } + let message; + if (!(req.isAuthenticated())) { + message ="Vous n'êtes pas connecté"; + } + else if (!(req.user.role === role || req.user.role === role2)) { + message = "Vous n'avez pas les accès nécéssaires pour cet onglet"; + } + res.redirect(`/login?message=${message}`); + + }; +} // Middleware pour vérifier la connexion + le rôle de l'utilisateur function checkRole(role:any) { @@ -133,5 +150,6 @@ module.exports = { passport, loggedIn, checkRole, - loggedInNoRedirection + loggedInNoRedirection, + checkRoleTwoProfile }; diff --git a/app/repository/FicheDePosteRepository.ts b/app/repository/FicheDePosteRepository.ts index f6fedd4..8171e48 100644 --- a/app/repository/FicheDePosteRepository.ts +++ b/app/repository/FicheDePosteRepository.ts @@ -95,8 +95,25 @@ export class FicheDePosteRepository { }); } - update(id: number, entity: FicheDePoste): Promise { - throw new Error("Method not implemented."); + static update(fiche: FicheDePoste): Promise { + const query = `UPDATE FicheDePoste + SET status = ?, + responsable = ?, + type_metier = ?, + lieu = ?, + teletravail = ?, + nb_heures = ?, + salaire = ?, + description = ? + WHERE numero = ?`; + return new Promise((resolve, reject) => { + pool.query(query, [fiche.status, fiche.responsable, fiche.typeMetier, fiche.lieu, fiche.teletravail, fiche.nbHeures, fiche.salaire, fiche.description, fiche.id], (err, result) => { + if (err) { + return reject(err); + } + return resolve(result); + }); + }); } } diff --git a/app/repository/OfferRepository.ts b/app/repository/OfferRepository.ts index eb40c4b..387c40f 100644 --- a/app/repository/OfferRepository.ts +++ b/app/repository/OfferRepository.ts @@ -71,8 +71,10 @@ export class OfferRepository { if (result.length == 0 || err) { return reject("Not found"); } + result[0].date_validite = new Date(result[0].date_validite).toLocaleDateString('fr-FR') + let organisation = new Organisation(result[0].siren, result[0].nom, result[0].type, result[0].siege); - let ficheDePoste = new FicheDePoste(result[0].fiche, result[0].status, result[0].responsable, result[0].type_metier, result[0].lieu, result[0].teletravail, result[0].nbheure, result[0].salaire, result[0].description, result[0].siren, organisation); + let ficheDePoste = new FicheDePoste(result[0].fiche, result[0].status, result[0].responsable, result[0].type_metier, result[0].lieu, result[0].teletravail, result[0].nb_heures, result[0].salaire, result[0].description, result[0].siren, organisation); let offer = new OffreDePoste(result[0].numero, result[0].etat, result[0].date_validite, result[0].nb_piece, result[0].liste_piece, ficheDePoste); return resolve(offer); } @@ -121,12 +123,36 @@ export class OfferRepository { } - update(id: number, entity: OffreDePoste): Promise { - throw new Error("Method not implemented."); + static update(offre: OffreDePoste): Promise { + const query = `UPDATE OffreDePoste + SET etat = ?, + date_validite = ?, + nb_piece = ?, + liste_piece = ? + WHERE numero = ?`; + return new Promise( + (resolve, reject) => { + pool.query(query, [offre.etat, offre.dateValidite, offre.nbPiece, offre.listePiece, offre.numero], (err, result) => { + if (err) { + return reject(err); + } + return resolve(result); + }); + }); } - delete(id: number): Promise { - throw new Error("Method not implemented."); + static supprimer(id: number): Promise { + const query = `DELETE FROM OffreDePoste + WHERE numero = ?`; + return new Promise( + (resolve, reject) => { + pool.query(query, [id], (err, result) => { + if (err) { + return reject(err); + } + return resolve(result); + }); + }); } } diff --git a/app/routes/AdminRouter.ts b/app/routes/AdminRouter.ts index c246de2..77ec0dd 100644 --- a/app/routes/AdminRouter.ts +++ b/app/routes/AdminRouter.ts @@ -23,5 +23,8 @@ adminRouter.get("/accepterDemande/:email", AdminController.accepterDemande); adminRouter.get("/refuserDemande/:email", AdminController.refuserDemande); adminRouter.get("/offres", AdminController.offres); adminRouter.get("/offre/:numero", AdminController.offre); +adminRouter.get("/modifierOffre/:numero", AdminController.modifierOffre); +adminRouter.post("/modifierOffre/:numero", AdminController.modifierOffre); +adminRouter.get("/supprimerOffre/:numero", AdminController.supprimerOffre); diff --git a/app/routes/MainRouter.ts b/app/routes/MainRouter.ts index 796adee..99aecf4 100644 --- a/app/routes/MainRouter.ts +++ b/app/routes/MainRouter.ts @@ -76,17 +76,7 @@ defaultRouter.post( return res.redirect(`/login?message=${info.message}`); } req.login(user, async () => { - let role = user.role; - let url; - if (role == "Administrateur") { - url = "admin"; - } else if (role == "Recruteur") { - url = "recruteur"; - } else { - url = ""; - } - - return res.redirect(`/${url}`); + return res.redirect(`/`); }); })(req, res, next); } diff --git a/app/views/admin/modifierOffre.ejs b/app/views/admin/modifierOffre.ejs new file mode 100644 index 0000000..1cd5f7e --- /dev/null +++ b/app/views/admin/modifierOffre.ejs @@ -0,0 +1,160 @@ +<%- include('../partials/adminHeader.ejs') %> + +
+
+
+ Image création d'entreprise +
+

Offre : <%= offer.ficheDePoste.typeMetier %>

+
+
+
+

Description

+ +
+ +
+

Offre

+
+
+
+
+ + +
+
+
+
+
+
+ + +
+
+
+
+
+

Organisation

+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+
+

Pièces à déposer

+ +
+ <% var list = offer.listePiece.split(',') %> + <% list.forEach((element) => {%> +
+ + +
+ <% })%> +
+ + +
+
+ +
+ +

Fiche de poste

+ +
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ + + + +
+ +
+ +
+ Retour + +
+ +
+
+
+
+
+ + + + + diff --git a/app/views/admin/offre.ejs b/app/views/admin/offre.ejs index 11b106b..c38529c 100644 --- a/app/views/admin/offre.ejs +++ b/app/views/admin/offre.ejs @@ -1,29 +1,53 @@ - -<%- include('../partials/adminHeader.ejs') %>. +<%- include('../partials/adminHeader.ejs') %>
Image création d'entreprise
-

Offre

+

Offre : <%= offer.ficheDePoste.typeMetier %>

-
- -

<%= offer.ficheDePoste.typeMetier %>

+
+

Description

+

<%= offer.ficheDePoste.description %>

+
+
+

Offre

+
+ + +
+
+ +
-
+
+

Organisation

+
-

<%= offer.ficheDePoste.organisation.nom %>

+ +
+ +
+ + +
+ +
+ +
- -

<%= offer.ficheDePoste.organisation.siege %>

+ +
+ + +

Pièces à déposer

@@ -38,52 +62,72 @@
-

Publication

-

<%= offer.dateValidite %>

- -
-

Fiche de poste

-
- -

<%= offer.ficheDePoste.typeMetier %>

+
+ +
-
- -

<%= offer.ficheDePoste.organisation.nom %>

+
+ +
-
- -

<%= offer.ficheDePoste.organisation.siege %>

+
+ +
- -

<%= offer.ficheDePoste.organisation.siege %>

+ +
- -

<%= offer.ficheDePoste.organisation.siege %>

+ + +
+
+ + +
+
+ +

+
diff --git a/app/views/admin/offres.ejs b/app/views/admin/offres.ejs index 2b6617a..ac75a22 100644 --- a/app/views/admin/offres.ejs +++ b/app/views/admin/offres.ejs @@ -32,13 +32,9 @@

<%= offer.ficheDePoste.description %>

Organisation : <%= offer.ficheDePoste.siren %>

Détail - Modifier - Supprimer
<% }) %>
- -
diff --git a/app/views/admin/utilisateur.ejs b/app/views/admin/utilisateur.ejs index b9691e8..a78acbe 100644 --- a/app/views/admin/utilisateur.ejs +++ b/app/views/admin/utilisateur.ejs @@ -1,51 +1,66 @@ -<%- include('../partials/adminHeader.ejs') %>. +<%- include('../partials/adminHeader.ejs') %>
- Image création d'entreprise

Informations Utilisateur

- -

<%= user.nom %>

+
+ + +
- -

<%= user.prenom %>

+
+ + +
- -

<%= user.email %>

+
+ + +
- -

<%= user.telephone %>

+
+ + +
- -

<%= user.dateCreation %>

+
+ + +
- -

<%= user.statut === 1 ? 'Actif' : 'Inactif' %>

+
+ + +
- -

<%= user.role %>

+
+ + +
- -

<%= user.demande_organisation ? user.demande_organisation : 'Aucune' %>

+
+ + +
@@ -54,26 +69,33 @@

Organisation

- -

<%= user.organisation.nom %>

+
+ + +
-
+
+
-

<%= user.organisation.siege %>

+
+
-
+
+
-

<%= user.organisation.type %>

+
+
-
+
+
-

<%= user.organisation.siren %>

+
+
- <% } %>
@@ -87,23 +109,24 @@
+ - +
<%- include('alert.ejs') %> diff --git a/app/views/partials/header.ejs b/app/views/partials/header.ejs index 20efe05..a5b9b3f 100644 --- a/app/views/partials/header.ejs +++ b/app/views/partials/header.ejs @@ -23,21 +23,36 @@ - - + <% if(typeof userLogged !== 'undefined' && userLogged && userLogged.role === 'Candidat'){ %> + + + <% } %>
+ <%- include('alert.ejs') %> diff --git a/app/views/partials/recruteurHeader.ejs b/app/views/partials/recruteurHeader.ejs index d017b28..ce9d938 100644 --- a/app/views/partials/recruteurHeader.ejs +++ b/app/views/partials/recruteurHeader.ejs @@ -36,8 +36,15 @@