Skip to content

Commit

Permalink
Fix:
Browse files Browse the repository at this point in the history
- un recruteur peut modifier et supprimer une offre
- fix header
- ajout fake data
  • Loading branch information
BaptisteBuvron committed Jun 22, 2023
1 parent adf4efd commit a9f418d
Show file tree
Hide file tree
Showing 11 changed files with 269 additions and 54 deletions.
90 changes: 75 additions & 15 deletions app/controllers/AdminController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,37 @@ export class AdminController {
static index(req: express.Request, res: express.Response) {
FicheDePosteRepository.getDistinctRegion().then((regions: string[]) => {
OfferRepository.getAll().then((offers: OffreDePoste[]) => {
res.render("admin/index", {title: "Home", offers: offers, regions: regions, userLogged: loggedInNoRedirection(req, res)});
res.render("admin/index", {
title: "Home",
offers: offers,
regions: regions,
userLogged: loggedInNoRedirection(req, res)
});
});
});
}

static utilisateurs(req: express.Request, res: express.Response) {
UserRepository.getAll().then((users: User[]) => {
OrganisationRepository.getAll().then((organisations : Organisation[]) => {
res.render("admin/utilisateurs", { title: "Utilisateurs", organisations: organisations, users, userLogged: loggedInNoRedirection(req, res)});
OrganisationRepository.getAll().then((organisations: Organisation[]) => {
res.render("admin/utilisateurs", {
title: "Utilisateurs",
organisations: organisations,
users,
userLogged: loggedInNoRedirection(req, res)
});
});
});
}

static utilisateur(req: express.Request, res: express.Response) {
let email = req.params.email;
UserRepository.getById(email).then((user: User) => {
res.render("admin/utilisateur", {title: "Utilisateur", user: user, userLogged: loggedInNoRedirection(req, res)});
res.render("admin/utilisateur", {
title: "Utilisateur",
user: user,
userLogged: loggedInNoRedirection(req, res)
});
})
}

Expand Down Expand Up @@ -61,9 +75,14 @@ export class AdminController {
console.log(err);
});
UserRepository.getById(req.body.email).then((user: User) => {
res.render("admin/utilisateur", {title: "Utilisateur", user: user, alerts: alerts, userLogged: loggedInNoRedirection(req, res)});
res.render("admin/utilisateur", {
title: "Utilisateur",
user: user,
alerts: alerts,
userLogged: loggedInNoRedirection(req, res)
});
})
}else{
} else {
let email = req.params.email;
UserRepository.getById(email).then((user: User) => {
res.render("admin/modifierUtilisateur", {
Expand All @@ -90,15 +109,26 @@ export class AdminController {
});

UserRepository.getAll().then((users: User[]) => {
res.render("admin/utilisateurs", { title: "Utilisateurs", users, alerts: alerts, userLogged: loggedInNoRedirection(req, res)});
res.render("admin/utilisateurs", {
title: "Utilisateurs",
users,
alerts: alerts,
userLogged: loggedInNoRedirection(req, res)
});
});
}

static demandes(req: express.Request, res: express.Response) {
UserRepository.getNewRecruiterDemand().then((users: User[]) => {
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)});
OrganisationRepository.getAll().then((organisations: Organisation[]) => {
res.render("admin/demandes", {
title: "Demandes",
users: users,
organisations: organisations,
oldUsers: oldUsers,
userLogged: loggedInNoRedirection(req, res)
});
});
});
});
Expand All @@ -115,7 +145,11 @@ export class AdminController {
let email = req.params.email;
UserRepository.getById(email).then((user: User) => {
console.log(user);
res.render("admin/ancienneDemande", {title: "Demande", user: user, userLogged: loggedInNoRedirection(req, res)});
res.render("admin/ancienneDemande", {
title: "Demande",
user: user,
userLogged: loggedInNoRedirection(req, res)
});
})
}

Expand All @@ -136,7 +170,12 @@ export class AdminController {
static offres(req: express.Request, res: express.Response) {
FicheDePosteRepository.getDistinctRegion().then((regions: string[]) => {
OfferRepository.getAll().then((offers: OffreDePoste[]) => {
res.render("admin/offres", {title: "Offres", offers: offers, regions: regions, userLogged: loggedInNoRedirection(req, res)});
res.render("admin/offres", {
title: "Offres",
offers: offers,
regions: regions,
userLogged: loggedInNoRedirection(req, res)
});
});
});
}
Expand Down Expand Up @@ -204,12 +243,29 @@ export class AdminController {
});

OfferRepository.getById(Number.parseInt(idOffre)).then((offer: OffreDePoste) => {
res.render("admin/offre", {title: "Offre", offer: offer, alerts: alerts, userLogged: loggedInNoRedirection(req, res)});
if (req.user.role == 'Administrateur') {
res.render("admin/offre", {
title: "Offre",
offer: offer,
alerts: alerts,
userLogged: loggedInNoRedirection(req, res)
});
} else {
res.render("offre/offre", {
title: "Offre",
offer: offer,
userLogged: loggedInNoRedirection(req, res)
});
}
})
}else{
} 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)});
res.render("admin/modifierOffre", {
title: "Modifier une offre",
offer: offer,
userLogged: loggedInNoRedirection(req, res)
});
})
}
}
Expand All @@ -225,7 +281,11 @@ export class AdminController {
let alert = new Alert("danger", "L'offre n'a été supprimée");
alerts.push(alert);
});
res.redirect("/admin/offres");
if (req.user.role == "Administrateur") {
res.redirect("/admin/offres");
} else {
res.redirect("/recruteur/offres");
}
}
}

3 changes: 1 addition & 2 deletions app/controllers/OfferController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ export class OfferController {
return res.render("offre/offre", {
title: "Offre",
offer: offer,
userLogged: loggedInNoRedirection(req, res),
csrfToken: req.session.csrfSecret
userLogged: loggedInNoRedirection(req, res)
});
}).catch((err) => {
console.log(err);
Expand Down
28 changes: 23 additions & 5 deletions app/controllers/RecruteurController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {CandidatureRepository} from "../repository/CandidatureRepository";
import {Alert} from "../utils/Alert";
import {loggedInNoRedirection} from "../passport/passportFunctions";
import {OfferRepository} from "../repository/OfferRepository";
import {User} from "../entity/User";

export class RecruteurController {
static index(req: express.Request, res: express.Response) {
Expand All @@ -12,22 +13,39 @@ export class RecruteurController {

static candidatures(req: express.Request, res: express.Response) {
//TODO get siren from user
let siren = '123456';
let alerts: Alert[] = [];
let user: User = req.user as User;
let siren = user.organisation?.siren;

let alerts: Alert[] = [];
if (siren === undefined) {
siren = String();
}
CandidatureRepository.getBySiren(siren).then((candidatures) => {
res.render("recruteur/candidatures", {title: "Candidatures", candidatures: candidatures, userLogged: loggedInNoRedirection(req, res)});
res.render("recruteur/candidatures", {
title: "Candidatures",
candidatures: candidatures,
userLogged: loggedInNoRedirection(req, res)
});
}).catch((err) => {
alerts.push(new Alert("danger", "Erreur lors de la récupération des candidatures"));
res.redirect("/recruteur");
});

}

static offres(req: express.Request, res: express.Response) {
let siren = '123456';
let user: User = req.user as User;
let siren = user.organisation?.siren;
let alerts: Alert[] = [];
if (siren === undefined) {
siren = String();
}
OfferRepository.getBySiren(siren).then((offers) => {
res.render("recruteur/offres", {title: "Offres", offers: offers, userLogged: loggedInNoRedirection(req, res)});
res.render("recruteur/offres", {
title: "Offres",
offers: offers,
userLogged: loggedInNoRedirection(req, res)
});
});
}
}
8 changes: 6 additions & 2 deletions app/routes/RecruterRouter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import express from "express";
import {RecruteurController} from "../controllers/RecruteurController";
import {offerRouter} from "./OfferRouter";
const { passport, loggedIn, checkRole } = require("../passport/passportFunctions");
import {AdminController} from "../controllers/AdminController";

const {passport, checkRole} = require("../passport/passportFunctions");

export const recruterRouter = express.Router();
recruterRouter.use(passport.initialize());
Expand All @@ -10,4 +11,7 @@ recruterRouter.use(passport.session());
recruterRouter.get("/", checkRole("Recruteur"), RecruteurController.index);
recruterRouter.get("/candidatures", checkRole("Recruteur"), RecruteurController.candidatures);
recruterRouter.get("/offres", RecruteurController.offres);
recruterRouter.get("/modifierOffre/:numero", AdminController.modifierOffre);
recruterRouter.post("/modifierOffre/:numero", AdminController.modifierOffre);
recruterRouter.get("/supprimerOffre/:numero", AdminController.supprimerOffre);

Loading

0 comments on commit a9f418d

Please sign in to comment.