Skip to content

Commit

Permalink
release 1.14.0 (#659)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminDNUM authored Dec 16, 2024
2 parents 859764c + 5b43073 commit ef80a27
Show file tree
Hide file tree
Showing 134 changed files with 5,314 additions and 1,007 deletions.
2 changes: 1 addition & 1 deletion .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ fileignoreconfig:
- filename: packages/backend/src/services/DemandeSejour.js
checksum: 8a3761a96a2775987fea844c5e0d47c7c6f83ea2dfddfd878c30a90f7d9775cc
- filename: packages/backend/src/services/Document.js
checksum: 59b5abe13b265c61dc6df8bbb92a3f989199dafaef0170d361f49e760d2ac385
checksum: 1fbeae31395935da7b8daef1d3872151b793d433d1cde968d0607b4628ba50a8
- filename: packages/backend/src/services/User.js
checksum: 78ddae12d185c4111aa837a178b75e6bda4083d06783ee6382503262298eefbc
- filename: packages/backend/src/services/geo/Commune.js
Expand Down
1 change: 0 additions & 1 deletion packages/backend/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ app.use(`/hebergement`, routes.hebergement);
app.use(`/siret`, routes.siret);
app.use(`/documents`, routes.documents);
app.use(`/geo`, routes.geo);
// TODO(eig): unhide when ok
//app.use(`/eig`, routes.eig);
app.use(`/message`, routes.message);
app.use(`/territoire`, routes.territoire);
Expand Down
48 changes: 42 additions & 6 deletions packages/backend/src/controllers/authentication/email/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const config = require("../../../config");
const User = require("../../../services/User");

const AppError = require("../../../utils/error");
const MailUtils = require("../../../utils/mail");
const Send = require("../../../services/mail").mailService.send;

const logger = require("../../../utils/logger");

Expand All @@ -19,15 +21,13 @@ module.exports = async (req, res, next) => {
}),
);
}

let email = null;
try {
const { email } = await jwt.verify(validationToken, config.tokenSecret, {
const result = await jwt.verify(validationToken, config.tokenSecret, {
algorithm: "ES512",
});
log.d({ email });
const user = await User.activate(email);
log.d({ user });
log.i("DONE");
return res.status(200).json({ user });
email = result.email;
} catch (error) {
log.w("DONE with error");
if (error instanceof jwt.TokenExpiredError) {
Expand All @@ -40,4 +40,40 @@ module.exports = async (req, res, next) => {
}
return next(error);
}

if (!email) {
return next(
new AppError("Token invalide", {
name: "InvalidToken",
statusCode: 401,
}),
);
}

let user = null;
try {
user = await User.activate(email);
} catch (error) {
return next(error);
}
if (!user) {
return next(
new AppError("Token invalide", {
name: "InvalidToken",
statusCode: 401,
}),
);
}
try {
await Send(MailUtils.usagers.authentication.sendAccountValided(email));
} catch (error) {
return next(
new AppError("Erreur lors de l'envoi du mail", {
cause: error,
name: "MailError",
statusCode: 500,
}),
);
}
return res.status(200).json({ user });
};
2 changes: 1 addition & 1 deletion packages/backend/src/controllers/demandeSejour/depose.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const dayjs = require("dayjs");
const yup = require("yup");

const DemandeSejour = require("../../services/DemandeSejour");
const Hebergement = require("../../services/Hebergement");
const Hebergement = require("../../services/hebergement/Hebergement");
const Send = require("../../services/mail").mailService.send;
const PdfDeclaration2Mois = require("../../services/pdf/declaration2mois/generate");
const PdfDeclaration8jours = require("../../services/pdf/declaration8jours/generate");
Expand Down
1 change: 0 additions & 1 deletion packages/backend/src/controllers/demandeSejour/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ module.exports = async function get(req, res, next) {
total: demandes.total,
});
} catch (error) {
console.log(error);
log.w("DONE with error");
return next(error);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const yup = require("yup");

const DemandeSejour = require("../../services/DemandeSejour");
const Organisme = require("../../services/Organisme");
const logger = require("../../utils/logger");
const ValidationAppError = require("../../utils/validation-error");
const Sentry = require("@sentry/node");
Expand Down Expand Up @@ -57,6 +58,20 @@ async function getByDepartementCodes(req, res, next) {
} catch (error) {
return next(new ValidationAppError(error));
}
// Si c'est l'organisme siège social alors on recherche sur le siren, sinon on recherchera sur le siret
// On ajoute alors un param dans le search
if (params.search?.organismeId) {
const organisme = await Organisme.getOne({
id: params.search.organismeId,
});
if (organisme?.personneMorale) {
if (organisme?.personneMorale?.siegeSocial) {
params.search.siren = organisme.personneMorale.siren;
} else {
params.search.siret = organisme.personneMorale.siret;
}
}
}
const demandesWithPagination = await DemandeSejour.getByDepartementCodes(
params,
territoireCode,
Expand Down
12 changes: 11 additions & 1 deletion packages/backend/src/controllers/demandeSejour/getById.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { number } = require("yup");
const DemandeSejour = require("../../services/DemandeSejour");

const AppError = require("../../utils/error");
const logger = require("../../utils/logger");
const ValidationAppError = require("../../utils/validation-error");

Expand All @@ -10,6 +10,16 @@ module.exports = async function get(req, res, next) {
log.i("IN");
let { declarationId } = req.params;

if (!declarationId) {
log.w("missing or invalid parameter");

return next(
new AppError("Paramètre incorrect", {
statusCode: 400,
}),
);
}

try {
declarationId = await number().required().validate(declarationId);
} catch (error) {
Expand Down
38 changes: 0 additions & 38 deletions packages/backend/src/controllers/demandeSejour/getHebergement.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ module.exports = async function get(req, res) {
sort: titleSorted ?? "nom",
},
);

return res.status(200).json({
count: data.total_count,
hebergements: data.hebergements || [],
Expand Down
1 change: 0 additions & 1 deletion packages/backend/src/controllers/demandeSejour/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module.exports.getDeprecated = require("./getDeprecated");
module.exports.getAdminStats = require("./getAdminStats");
module.exports.getExtract = require("./getExtract");
module.exports.getExtractHebergement = require("./getExtractHebergement");
module.exports.getHebergement = require("./getHebergement");
module.exports.getHebergementsByDepartementCodes = require("./getHebergementsByDepartementCodes");
module.exports.getById = require("./getById");
module.exports.getByIdBo = require("./getByIdBo");
Expand Down
2 changes: 0 additions & 2 deletions packages/backend/src/controllers/demandeSejour/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ module.exports = async function post(req, res, next) {
}),
);
}

try {
declarationId = await number().required().validate(declarationId);
parametre = await object().json().required().validate(parametre);
} catch (error) {
return next(new ValidationAppError(error));
}

try {
const updatedDeclarationId = await DemandeSejour.update(
type,
Expand Down
2 changes: 2 additions & 0 deletions packages/backend/src/controllers/documents/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const log = logger(module.filename);
module.exports = async (req, res, next) => {
log.i("IN");
const { category } = req.body;
const { decoded } = req;
const file = req.file;
if (!category || !file) {
log.w("DONE with error");
Expand Down Expand Up @@ -49,6 +50,7 @@ module.exports = async (req, res, next) => {
category,
mimetype,
data,
decoded.id,
);
log.d("DONE", uuid);
return res.json({ uuid });
Expand Down
47 changes: 47 additions & 0 deletions packages/backend/src/controllers/eig/available-ds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const logger = require("../../utils/logger");
const eigService = require("../../services/eig");
const Organisme = require("../../services/Organisme");

const log = logger(module.filename);

module.exports = async function getAvailableDs(req, res, next) {
log.i("IN");
const { decoded } = req;
const { id: userId } = decoded;
log.d("userId", { userId });

let organismesId;

try {
const organisme = await Organisme.getOne({
use_id: userId,
});
if (organisme.personneMorale?.porteurAgrement) {
const organismes = await Organisme.getBySiren(
organisme.personneMorale.siren,
);
organismesId = organismes.map((o) => o.organismeId);
} else {
organismesId = [organisme.organismeId];
}
} catch (error) {
log.w("DONE with error");
return next(error);
}

const { search } = req.query;

if (!search || search === "") {
return res.status(200).json([]);
}

try {
const ds = await eigService.getAvailableDs(organismesId, search);
return res.status(200).json(ds);
} catch (error) {
log.w("DONE with error");
return next(error);
} finally {
log.i("OUT");
}
};
46 changes: 32 additions & 14 deletions packages/backend/src/controllers/eig/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { selectionSejourSchema } = require("../../schemas/eig");
const ValidationAppError = require("../../utils/validation-error");
const eigService = require("../../services/eig");
const DemandeSejour = require("../../services/DemandeSejour");
const { idDeclarationeligibleToEig } = require("../../helpers/eig");
const { isDeclarationligibleToEig } = require("../../helpers/eig");

const log = logger(module.filename);

Expand All @@ -13,30 +13,48 @@ module.exports = async (req, res, next) => {
log.i("IN", { body: req.body });
const { parametre } = req.body;

let eig;
if (!parametre?.declarationId) {
return res.status(400).send({
errors: "Le champs declarationId est obligatoire",
name: "UnexpectedError",
});
}

let ds;

try {
eig = await yup.object(selectionSejourSchema).validate(parametre, {
abortEarly: false,
stripUnknown: true,
ds = await DemandeSejour.getOne({ "ds.id": parametre.declarationId });
if (!ds) {
return res
.status(404)
.send({ errors: "Aucune déclaration trouvée", name: "Not found" });
}
} catch (err) {
return res.status(500).send({ errors: err.errors, name: err.name });
}

if (!isDeclarationligibleToEig(ds)) {
return res.status(400).send({
message: "La déclaration n'est pas éligible à la création d'un EIG",
});
} catch (error) {
return next(new ValidationAppError(error));
}

let eig;

try {
const ds = await DemandeSejour.getOne({ "ds.id": eig.declarationId });
if (!idDeclarationeligibleToEig(ds)) {
return res.status(400).send({
message: "La déclaration n'est pas éligible à la création d'un EIG",
eig = await yup
.object(selectionSejourSchema(ds.dateDebut, ds.dateFin))
.validate(parametre, {
abortEarly: false,
stripUnknown: true,
});
}
} catch (err) {
return res.status(400).send({ errors: err.errors, name: err.name });
} catch (error) {
return next(new ValidationAppError(error));
}

try {
const eigId = await eigService.create({
date: eig.date,
declarationId: eig.declarationId,
departement: eig.departement,
userId,
Expand Down
Loading

0 comments on commit ef80a27

Please sign in to comment.