Skip to content

Commit

Permalink
fix(instructeurs): corrige boug sur affichage des déclarations pour p…
Browse files Browse the repository at this point in the history
…ersonne physique
  • Loading branch information
gweill-guigops committed Apr 25, 2024
1 parent f09d111 commit 1b0f601
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 24 deletions.
11 changes: 4 additions & 7 deletions packages/backend/src/controllers/demandeSejour/depose.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,10 @@ module.exports = async function post(req, res, next) {
const { attestation } = req.body;
log.i("IN", { demandeSejourId });

if (!demandeSejourId) {
log.w("missing parameter");
return next(
new AppError("Paramètre incorrect", {
statusCode: 400,
}),
);
try {
await yup.number().required().validate(demandeSejourId);
} catch (error) {
return next(new ValidationAppError(error));
}

if (!attestation) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const DemandeSejour = require("../../services/DemandeSejour");
const yup = require("yup");

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

const log = logger(module.filename);

Expand All @@ -12,15 +14,33 @@ module.exports = async function getByDepartementCodes(req, res, next) {

try {
const { limit, offset, sortBy, sortDirection, search } = req.query;
const params = {
limit,
offset,
search: JSON.parse(search ?? "{}"),
sortBy,
sortDirection,
};

try {
await yup
.object({
limit: yup.number().nullable(),
offset: yup.number().nullable(),
search: yup.object().json(),
sortBy: yup.string().nullable(),
sortDirection: yup.string().oneOf(["ASC", "DESC"]).nullable(),
})
.validate(params, {
abortEarly: false,
stripUnknown: true,
});
} catch (error) {
return next(new ValidationAppError(error));
}

const demandesWithPagination = await DemandeSejour.getByDepartementCodes(
{
limit,
offset,
search: JSON.parse(search ?? "{}"),
sortBy,
sortDirection,
},
params,
req.departements.map((d) => d.value),
);
log.d(demandesWithPagination);
Expand Down
2 changes: 0 additions & 2 deletions packages/backend/src/controllers/demandeSejour/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ module.exports = async function post(req, res, next) {
duree,
periode,
responsableSejour,
organisme.protocoleTransport,
organisme.protocoleSanitaire,
organisme,
);

Expand Down
11 changes: 10 additions & 1 deletion packages/backend/src/controllers/demandeSejour/update.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
const yup = require("yup");

const DemandeSejour = require("../../services/DemandeSejour");
const AppError = require("../../utils/error");

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

const log = logger(module.filename);

Expand All @@ -10,7 +13,7 @@ module.exports = async function post(req, res, next) {
const { type, parametre } = req.body;
log.i("IN", { demandeSejourId, parametre, type });

if (!type || !demandeSejourId || !parametre) {
if (!type || !parametre) {
log.w("missing parameter");
return next(
new AppError("Paramètre incorrect", {
Expand All @@ -19,6 +22,12 @@ module.exports = async function post(req, res, next) {
);
}

try {
await yup.number().required().validate(demandeSejourId);
} catch (error) {
return next(new ValidationAppError(error));
}

try {
const demandeId = await DemandeSejour.update(
type,
Expand Down
6 changes: 2 additions & 4 deletions packages/backend/src/services/DemandeSejour.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,6 @@ module.exports.create = async (
duree,
periode,
responsableSejour,
protocoleTransport,
protocoleSanitaire,
organisme,
) => {
log.i("create - IN");
Expand All @@ -436,8 +434,8 @@ module.exports.create = async (
duree,
periode,
responsableSejour,
protocoleTransport,
protocoleSanitaire,
organisme.protocoleTransport,
organisme.protocoleSanitaire,
organisme,
),
);
Expand Down
3 changes: 1 addition & 2 deletions packages/frontend-usagers/src/pages/demande-sejour/liste.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<h1>Liste des déclarations de séjour</h1>
</div>
</div>

<template v-if="demandeSejourStore.demandes.length">
<div class="fr-grid-row">
<div class="fr-col">
Expand Down Expand Up @@ -207,7 +206,7 @@ const idOptions = computed(() => {
const siretOptions = computed(() => {
return demandeSejourStore.demandes
.map((d) => d.siret)
.filter((v, i, a) => a.indexOf(v) === i);
.filter((v, i, a) => v !== null && a.indexOf(v) === i);
});
const idFonctionnellesOptions = computed(() => {
Expand Down

0 comments on commit 1b0f601

Please sign in to comment.