Skip to content

Commit

Permalink
lint: Lint all (#325)
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-carcel authored Jul 18, 2024
2 parents eb81912 + f3e8d96 commit 3fb9bfe
Show file tree
Hide file tree
Showing 23 changed files with 234 additions and 178 deletions.
3 changes: 2 additions & 1 deletion packages/backend/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ module.exports = {
request: {
notify: {
cron: process.env.BACKEND_CRON_REQUEST_DS8J15J_NOTIFY_CRON,
deadlineRemind: process.env.BACKEND_CRON_REQUEST_DS8J15J_DEADLINE_REMIND,
deadlineRemind:
process.env.BACKEND_CRON_REQUEST_DS8J15J_DEADLINE_REMIND,
name: "REQUEST_DS8J15J",
},
update: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ module.exports = async function login(req, res, next) {
);
}

user.serviceCompetent = (user.territoireCode === "FRA") ? 'NAT' : (/^[0-9]+$/.test(user.territoireCode)) ? 'DEP' : 'REG';
user.serviceCompetent =
user.territoireCode === "FRA"
? "NAT"
: /^[0-9]+$/.test(user.territoireCode)
? "DEP"
: "REG";

try {
const accessToken = jwt.sign(buildAccessToken(user), config.tokenSecret, {
Expand Down
28 changes: 19 additions & 9 deletions packages/backend/src/controllers/bo-user/service-competence.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
const logger = require("../../utils/logger");
const { competence } = require("../../helpers/bo-competence")
const { competence } = require("../../helpers/bo-competence");

const log = logger(module.filename);

module.exports = async function serviceCompetence(territoireCode) {
try {
log.i("IN"),territoireCode;
log.i("IN"), territoireCode;
log.i("DONE");
return (territoireCode === "FRA") ? 'NAT' : (/^[0-9]+$/.test(territoireCode)) ? 'DEP' : 'REG';
return territoireCode === "FRA"
? "NAT"
: /^[0-9]+$/.test(territoireCode)
? "DEP"
: "REG";
} catch (error) {
log.w("DONE with error");
return error;
}
};

module.exports = async function verifyCompetence(serviceCompetentUserConnected,serviceCompetentUtilisateurCreateOrUpdate) {
return (serviceCompetentUserConnected === competence.NATIONALE || (serviceCompetentUtilisateurCreateOrUpdate != competence.NATIONALE && serviceCompetentUserConnected === competence.REGIONALE) || (serviceCompetentUtilisateurCreateOrUpdate === competence.DEPARTEMENTALE && serviceCompetentUserConnected === competence.DEPARTEMENTALE))
};



module.exports = async function verifyCompetence(
serviceCompetentUserConnected,
serviceCompetentUtilisateurCreateOrUpdate,
) {
return (
serviceCompetentUserConnected === competence.NATIONALE ||
(serviceCompetentUtilisateurCreateOrUpdate != competence.NATIONALE &&
serviceCompetentUserConnected === competence.REGIONALE) ||
(serviceCompetentUtilisateurCreateOrUpdate === competence.DEPARTEMENTALE &&
serviceCompetentUserConnected === competence.DEPARTEMENTALE)
);
};
25 changes: 17 additions & 8 deletions packages/backend/src/controllers/bo-user/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,28 @@ module.exports = async function update(req, res, next) {
log.w(error);
return next(new ValidationAppError(error));
}
const serviceCompetentUserConnected = await serviceCompetence(req.decoded.territoireCode);
const serviceCompetentUtilisateurUpdate = await serviceCompetence(user.territoireCode);
const serviceCompetentUserConnected = await serviceCompetence(
req.decoded.territoireCode,
);
const serviceCompetentUtilisateurUpdate = await serviceCompetence(
user.territoireCode,
);

if (verifyCompetence(serviceCompetentUserConnected,serviceCompetentUtilisateurUpdate))
{
if (
verifyCompetence(
serviceCompetentUserConnected,
serviceCompetentUtilisateurUpdate,
)
) {
try {
await BoUser.update(userId, user);
return res.status(200).json({ message: "Utilisateur mis à jour" });
} catch (error) {
log.w("DONE with error");
return next(error);
}
}
else
return res.status(403).json({ message: "Permission refusée. Privilèges insuffisants" });
};
} else
return res
.status(403)
.json({ message: "Permission refusée. Privilèges insuffisants" });
};
84 changes: 41 additions & 43 deletions packages/backend/src/controllers/demandeSejour/cancel.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ module.exports = async function cancel(req, res, next) {
const { id: userId } = req.decoded;

log.i("IN", { demandeSejourId });
let declaration
let canceletedRows
let declaration;
let canceletedRows;
try {
declaration = await DemandeSejour.getOne({
"ds.id": demandeSejourId,
Expand All @@ -35,45 +35,44 @@ module.exports = async function cancel(req, res, next) {
statuts.ATTENTE_8_JOUR,
statuts.TRANSMISE_8J,
statuts.EN_COURS_8J,
statuts.A_MODIFIER_8J
statuts.A_MODIFIER_8J,
];

if (!statutsCancellable.includes(declaration.statut)) {
log.w("DONE with error");
return next(
new AppError(
"Impossible d'annuler une demande qui n'est pas au bon statut",
{
statusCode: 400,
},
),
);
}
canceletedRows = await DemandeSejour.cancel(declaration.id, userId);
if (canceletedRows !== 1) {
log.w(`DONE with error, ${canceletedRows} rows were updated, expected one `);
return next(
new AppError(
"Erreur de l'annulation, trop de lignes mises à jour ou pas assez",
{
statusCode: 400,
},
),
);
}
else
{
await DemandeSejour.insertEvent(
"Organisateur",
declaration.id,
userId,
null,
"declaration_sejour",
"Annulation de la déclaration",
declaration,
);
}

if (!statutsCancellable.includes(declaration.statut)) {
log.w("DONE with error");
return next(
new AppError(
"Impossible d'annuler une demande qui n'est pas au bon statut",
{
statusCode: 400,
},
),
);
}
canceletedRows = await DemandeSejour.cancel(declaration.id, userId);
if (canceletedRows !== 1) {
log.w(
`DONE with error, ${canceletedRows} rows were updated, expected one `,
);
return next(
new AppError(
"Erreur de l'annulation, trop de lignes mises à jour ou pas assez",
{
statusCode: 400,
},
),
);
} else {
await DemandeSejour.insertEvent(
"Organisateur",
declaration.id,
userId,
null,
"declaration_sejour",
"Annulation de la déclaration",
declaration,
);
}
} catch (err) {
log.w(err);
return next(
Expand All @@ -91,7 +90,7 @@ module.exports = async function cancel(req, res, next) {
const departements = declaration.hebergement.hebergements.map(
(h) => h.coordonnees.adresse.departement,
);
if (destinatairesBack.length>0) {
if (destinatairesBack.length > 0) {
await Send(
MailUtils.bo.declarationSejour.sendDeclarationCanceled({
declaration,
Expand All @@ -103,7 +102,6 @@ module.exports = async function cancel(req, res, next) {
}),
);
}

}
} catch (error) {
log.w(error);
Expand Down Expand Up @@ -134,5 +132,5 @@ module.exports = async function cancel(req, res, next) {
} catch (error) {
log.w("DONE with error");
return next(error);
}
};
}
};
6 changes: 3 additions & 3 deletions packages/backend/src/controllers/demandeSejour/copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ module.exports = async function post(req, res, next) {
if (
sourceDeclaration.statut !== statuts.BROUILLON &&
sourceDeclaration.statut !== statuts.TRANSMISE &&
sourceDeclaration.statut !== statuts.EN_COURS &&
sourceDeclaration.statut !== statuts.EN_COURS &&
sourceDeclaration.statut !== statuts.ANNULEE &&
sourceDeclaration.statut !== statuts.ABANDONNEE
sourceDeclaration.statut !== statuts.ABANDONNEE
) {
log.w("DONE with error");
return next(
Expand Down Expand Up @@ -75,4 +75,4 @@ module.exports = async function post(req, res, next) {
} catch (err) {
log.w(err);
}
};
};
2 changes: 1 addition & 1 deletion packages/backend/src/controllers/demandeSejour/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ module.exports = async function post(req, res, next) {
}),
);
}
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,23 @@ module.exports = async function post(req, res, next) {
);
}

if (declaration.statut !== statuts.EN_COURS && declaration.statut !== statuts.EN_COURS_8J) {
if (
declaration.statut !== statuts.EN_COURS &&
declaration.statut !== statuts.EN_COURS_8J
) {
log.w("Delaration should be in statut EN COURS");
return res.status(400).json({
message: "Statut non compatible",
});
}

const AModifierType = declaration.statut === statuts.EN_COURS ? statuts.A_MODIFIER : statuts.A_MODIFIER_8J
const textTypePrecision = "Demande de compléments " + (declaration.statut === statuts.EN_COURS ? " 2 mois" : " 8 jours");
const AModifierType =
declaration.statut === statuts.EN_COURS
? statuts.A_MODIFIER
: statuts.A_MODIFIER_8J;
const textTypePrecision =
"Demande de compléments " +
(declaration.statut === statuts.EN_COURS ? " 2 mois" : " 8 jours");
try {
const destinataires = await DemandeSejour.getEmailToList(
declaration.organismeId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,21 @@ module.exports = async function post(req, res, next) {
userId: null,
},
() =>
(declaration.statut === statuts.EN_COURS ?
Send(
MailUtils.usagers.declarationSejour.sendAccuseReception2MoisMail({
declaration,
destinataires,
})) :
Send(
MailUtils.usagers.declarationSejour.sendAccuseReception8JoursMail({
declaration,
destinataires,
}))
),
declaration.statut === statuts.EN_COURS
? Send(
MailUtils.usagers.declarationSejour.sendAccuseReception2MoisMail({
declaration,
destinataires,
}),
)
: Send(
MailUtils.usagers.declarationSejour.sendAccuseReception8JoursMail(
{
declaration,
destinataires,
},
),
),
);

if (declaration.statut === statuts.EN_COURS)
Expand Down
16 changes: 12 additions & 4 deletions packages/backend/src/controllers/demandeSejour/prendEnCharge.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,25 @@ module.exports = async function post(req, res, next) {
);
}

if (declaration.statut !== statuts.TRANSMISE && declaration.statut !== statuts.TRANSMISE_8J) {
if (
declaration.statut !== statuts.TRANSMISE &&
declaration.statut !== statuts.TRANSMISE_8J
) {
log.w("Delaration is already at least in progress");
return next(
new AppError("Statut incompatible", {
statusCode: 400,
}),
);
}
const enCoursTypeStatut = declaration.statut === statuts.TRANSMISE ? statuts.EN_COURS : statuts.EN_COURS_8J;
const textTypePrecision = "Prise en charge de la déclaration " + (declaration.statut === statuts.TRANSMISE ? " 2 mois" : " 8 jours");

const enCoursTypeStatut =
declaration.statut === statuts.TRANSMISE
? statuts.EN_COURS
: statuts.EN_COURS_8J;
const textTypePrecision =
"Prise en charge de la déclaration " +
(declaration.statut === statuts.TRANSMISE ? " 2 mois" : " 8 jours");

try {
await DemandeSejour.updateStatut(declarationId, enCoursTypeStatut, {
boUserId: userId,
Expand Down
14 changes: 11 additions & 3 deletions packages/backend/src/controllers/demandeSejour/refus.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ module.exports = async function post(req, res, next) {
);
}

if (declaration.statut !== statuts.EN_COURS && declaration.statut !== statuts.EN_COURS_8J) {
if (
declaration.statut !== statuts.EN_COURS &&
declaration.statut !== statuts.EN_COURS_8J
) {
log.w("Delaration should be in statut EN COURS");
return next(
new AppError("Statut incompatible", {
Expand All @@ -58,8 +61,13 @@ module.exports = async function post(req, res, next) {
);
}

const RefuseType = declaration.statut === statuts.EN_COURS ? statuts.REFUSEE : statuts.REFUSEE_8J;
const textTypePrecision = "Refus de la demande " + (declaration.statut === statuts.EN_COURS ? " 2 mois" : " 8 jours");
const RefuseType =
declaration.statut === statuts.EN_COURS
? statuts.REFUSEE
: statuts.REFUSEE_8J;
const textTypePrecision =
"Refus de la demande " +
(declaration.statut === statuts.EN_COURS ? " 2 mois" : " 8 jours");
try {
const destinataires = await DemandeSejour.getEmailToList(
declaration.organismeId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ const sendTemplate = require("../../helpers/mail");

const { senderEmail } = require("../../config");

const { name, cron, deadlineRemind } = require("../../config").crons.request.notify;
const { name, cron, deadlineRemind } =
require("../../config").crons.request.notify;

const log = logger(module.filename);

// Interval 8 Jours avant le début du séjour + 15 jours avant l'échéance de déclaration soit 23 jours avant le début
// date_debut, (date_debut - (23 * interval '1 day'))::date, now()::date>=(date_debut - (23 * interval '1 day'))::date
// date_debut, (date_debut - (23 * interval '1 day'))::date, now()::date>=(date_debut - (23 * interval '1 day'))::date
// (ds.date_debut - (8 * interval '1 day'))::date as datelimite,rappel_ds_compl
const query = {
fetchRappelDeclarationSejour8j15j: `
Expand Down Expand Up @@ -102,4 +103,4 @@ async function sendNotificationMail({ date_debut_alerte, email, titre }) {
const job = new CronJob(cron, run(name, action));

module.exports.job = job;
module.exports.action = action;
module.exports.action = action;
Loading

0 comments on commit 3fb9bfe

Please sign in to comment.