Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: #24

Merged
merged 1 commit into from
Jun 21, 2023
Merged

Fix: #24

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions app/controllers/AdminController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,7 @@ export class AdminController {
let alert = new Alert("danger", "L'offre n'a été supprimée");
alerts.push(alert);
});
OfferRepository.getAll().then((offers: OffreDePoste[]) => {
res.render("admin/offres", {title: "Offres", alerts: alerts, offers: offers, userLogged: loggedInNoRedirection(req, res)});
});
res.redirect("/admin/offres");
}
}

1 change: 1 addition & 0 deletions app/passport/passportFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ passport.use(
})
.catch((err) => {
console.log(err);
return done(null, false, {message: "Erreur lors de la connexion"});
});
} catch (error) {
return done(error);
Expand Down
227 changes: 133 additions & 94 deletions app/repository/UserRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,86 +8,117 @@ const db = pool;
export class UserRepository {
static tableName = "Utilisateur";

static getById(email:string): Promise<User> {
const query = `SELECT u.email, u.nom, u.prenom, u.telephone, DATE_FORMAT(u.date_creation, '%d-%m-%Y') as date_creation, u.statut, u.password, u.role, u.demande_organisation, o.siren, o.nom as organisation, o.type, o.siege
FROM ${UserRepository.tableName} u LEFT JOIN ${OrganisationRepository.tableName} o using (siren)
static getById(email: string): Promise<User> {
const query = `SELECT u.email,
u.nom,
u.prenom,
u.telephone,
DATE_FORMAT(u.date_creation, '%d-%m-%Y') as date_creation,
u.statut,
u.password,
u.role,
u.demande_organisation,
o.siren,
o.nom as organisation,
o.type,
o.siege
FROM ${UserRepository.tableName} u
LEFT JOIN ${OrganisationRepository.tableName} o using (siren)
WHERE u.email = ?`;
return new Promise<User>(
(resolve, reject) =>
pool.query(query,[email], (err, result) => {
if (err) {
return reject(err);
}
let organisation = new Organisation(
result[0].siren,
result[0].organisation,
result[0].type,
result[0].siege
);
let user = new User(
result[0].email,
result[0].nom,
result[0].prenom,
result[0].telephone,
result[0].date_creation,
result[0].statut,
result[0].password,
result[0].role,
result[0].demande_organisation,
organisation,
undefined
);

return resolve(user);
pool.query(query, [email], (err, result) => {
if (err) {
return reject(err);
}
if (result.length === 0) {
return reject(new Error("User not found"));
}
let organisation = new Organisation(
result[0].siren,
result[0].organisation,
result[0].type,
result[0].siege
);
let user = new User(
result[0].email,
result[0].nom,
result[0].prenom,
result[0].telephone,
result[0].date_creation,
result[0].statut,
result[0].password,
result[0].role,
result[0].demande_organisation,
organisation,
undefined
);

return resolve(user);
}
)
);
}

static getAll(): Promise<[User]> {
const query = `SELECT u.email, u.nom, u.prenom, u.telephone, DATE_FORMAT(u.date_creation, '%d-%m-%Y') as date_creation, u.statut, u.password, u.role, u.demande_organisation, o.siren, o.nom as organisation, o.type, o.siege
FROM ${UserRepository.tableName} u LEFT JOIN ${OrganisationRepository.tableName} o using (siren)`;
const query = `SELECT u.email,
u.nom,
u.prenom,
u.telephone,
DATE_FORMAT(u.date_creation, '%d-%m-%Y') as date_creation,
u.statut,
u.password,
u.role,
u.demande_organisation,
o.siren,
o.nom as organisation,
o.type,
o.siege
FROM ${UserRepository.tableName} u
LEFT JOIN ${OrganisationRepository.tableName} o using (siren)`;

return new Promise<[User]>(
(resolve, reject) =>
pool.query(query, (err, result) => {
if (err) {
return reject(err);
}
if (err) {
return reject(err);
}

let organisation;
let user;
for (let i = 0; i < result.length; i++) {
organisation = new Organisation(
result[i].siren,
result[i].organisation,
result[i].type,
result[i].siege
);
user = new User(
result[i].email,
result[i].nom,
result[i].prenom,
result[i].telephone,
result[i].date_creation,
result[i].statut,
result[i].password,
result[i].role,
result[i].demande_organisation,
organisation,
undefined
);
result[i] = user;
}
let organisation;
let user;
for (let i = 0; i < result.length; i++) {
organisation = new Organisation(
result[i].siren,
result[i].organisation,
result[i].type,
result[i].siege
);
user = new User(
result[i].email,
result[i].nom,
result[i].prenom,
result[i].telephone,
result[i].date_creation,
result[i].statut,
result[i].password,
result[i].role,
result[i].demande_organisation,
organisation,
undefined
);
result[i] = user;
}

return resolve(result);
return resolve(result);
}
)
);
}

static create(entity: User): Promise<User> {
const query = `INSERT INTO ${UserRepository.tableName} (email, nom, prenom, telephone, date_creation, statut, password, role, demande_organisation, siren) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`;
const query = `INSERT INTO ${UserRepository.tableName} (email, nom, prenom, telephone, date_creation, statut,
password, role, demande_organisation, siren)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`;
return new Promise<User>((resolve, reject) => {
pool.query(query, [entity.email, entity.nom, entity.prenom, entity.telephone, entity.dateCreation, entity.statut, entity.passwordHash, entity.role, entity.demande_organisation, entity.organisation?.siren], (err, result) => {
if (err) {
Expand All @@ -98,13 +129,13 @@ export class UserRepository {
});
}

static update(user : User): Promise<User> {
static update(user: User): Promise<User> {
const query = `UPDATE ${UserRepository.tableName}
SET nom = ?,
prenom = ?,
SET nom = ?,
prenom = ?,
telephone = ?,
statut = ?,
role = ?
statut = ?,
role = ?
WHERE email = ?`;
return new Promise<User>(
(resolve, reject) =>
Expand All @@ -118,8 +149,9 @@ export class UserRepository {
);
}

static supprimerUtilisateur(email:string): Promise<User> {
const query = `DELETE FROM ${UserRepository.tableName}
static supprimerUtilisateur(email: string): Promise<User> {
const query = `DELETE
FROM ${UserRepository.tableName}
WHERE email = ?`;
return new Promise<User>(
(resolve, reject) =>
Expand All @@ -141,15 +173,15 @@ export class UserRepository {
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);
}
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);
}
)
Expand All @@ -160,41 +192,48 @@ export class UserRepository {
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'
OR u.demande_organisation = 'refus'
OR u.demande_organisation = 'acceptation'`;
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]){
let organisation = new Organisation(result[0].siren, result[0].organisation, result[0].type, result[0].siege);
result[0].organisation = organisation;
}
if (err) {
return reject(err);
}
if (result[0]) {
let organisation = new Organisation(result[0].siren, result[0].organisation, result[0].type, result[0].siege);
result[0].organisation = organisation;
}
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
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'`;
OR u.demande_organisation = 'acceptation'`;
return new Promise<[User]>(
(resolve, reject) =>
pool.query(query, (err, result) => {
if (err) {
return reject(err);
}
if(result[0]){
let organisation = new Organisation(result[0].siren, result[0].organisation, result[0].type, result[0].siege);
result[0].organisation = organisation;
}
if (err) {
return reject(err);
}
if (result[0]) {
let organisation = new Organisation(result[0].siren, result[0].organisation, result[0].type, result[0].siege);
result[0].organisation = organisation;
}
return resolve(result);
}
)
Expand Down
14 changes: 7 additions & 7 deletions app/table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ CREATE TABLE `FicheDePoste`
`salaire` int(11) NOT NULL,
`description` text NOT NULL,
`siren` varchar(11) NOT NULL,
FOREIGN KEY (siren) REFERENCES Organisation (siren),
FOREIGN KEY (siren) REFERENCES Organisation (siren) ON DELETE CASCADE,
PRIMARY KEY (numero)
);

Expand All @@ -66,7 +66,7 @@ CREATE TABLE `OffreDePoste`
`nb_piece` int(11) NOT NULL,
`liste_piece` text NOT NULL,
`fiche` int(11) NOT NULL,
FOREIGN KEY (fiche) REFERENCES FicheDePoste (numero),
FOREIGN KEY (fiche) REFERENCES FicheDePoste (numero) ON DELETE CASCADE,
PRIMARY KEY (numero)
);

Expand Down Expand Up @@ -125,9 +125,11 @@ CREATE TABLE `Candidature`
`offre` int(11) NOT NULL,
`statut` ENUM ('En analyse', 'Acceptée', 'Refusée', 'En attente'),
`motivation` text NOT NULL,
FOREIGN KEY (candidat) REFERENCES Utilisateur (email),
FOREIGN KEY (offre) REFERENCES OffreDePoste (numero),
FOREIGN KEY (candidat) REFERENCES Utilisateur (email) ON DELETE CASCADE,
FOREIGN KEY (offre) REFERENCES OffreDePoste (numero) ON DELETE CASCADE,
PRIMARY KEY (candidat, offre)
##cascade delete for candidat and offre

);


Expand All @@ -145,16 +147,14 @@ CREATE TABLE `Piece`
`url` varchar(128) NOT NULL,
`candidat` varchar(128) NOT NULL,
`offre` int(11) NOT NULL,
FOREIGN KEY (candidat, offre) REFERENCES Candidature (candidat, offre),
FOREIGN KEY (candidat, offre) REFERENCES Candidature (candidat, offre) ON DELETE CASCADE,
PRIMARY KEY (id)
);

--
-- Déchargement des données de la table `Piece`
--



-- --------------------------------------------------------
#Insertion des données

Expand Down
2 changes: 1 addition & 1 deletion app/views/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</div>
<div class="col-lg-6">
<h1 class="display-5 fw-bold lh-1 mb-3">Site de recrutement</h1>
<% if(typeof userLogged === 'undefined'){ %>
<% if (!user) { %>
<div class="d-grid gap-2 d-md-flex justify-content-md-start">
<a type="button" class="btn btn-primary btn-lg px-4 me-md-2" href="/login">Se connecter pour voir
les offres</a>
Expand Down