From adb458ae55c8ba3f77dc8ebbc62aa421b27a6ac0 Mon Sep 17 00:00:00 2001 From: l-scherer Date: Tue, 1 Oct 2024 18:27:29 +0200 Subject: [PATCH] fix(BO): correction liste message vide --- .../backend/src/services/DemandeSejour.js | 14 +++++++++++-- .../src/components/demandes-sejour/liste.vue | 21 +++++-------------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/packages/backend/src/services/DemandeSejour.js b/packages/backend/src/services/DemandeSejour.js index a0890f1da..c22c254da 100644 --- a/packages/backend/src/services/DemandeSejour.js +++ b/packages/backend/src/services/DemandeSejour.js @@ -284,11 +284,18 @@ SELECT COUNT(CASE WHEN statut = 'ABANDONNEE' THEN 1 END)::integer AS "abandonnee", COUNT(CASE WHEN statut = 'REFUSEE' THEN 1 END)::integer AS "refusee", COUNT(CASE WHEN statut = 'REFUSEE 8J' THEN 1 END)::integer AS "refuse8J", - COUNT(CASE WHEN statut <> 'BROUILLON' THEN 1 END)::integer AS "global" + COUNT(CASE WHEN statut <> 'BROUILLON' THEN 1 END)::integer AS "global", + COUNT(CASE WHEN (dsm.message is not null AND dsm.read_at IS NULL AND dsm.back_user_id IS NULL) THEN 1 END)::integer AS "nonlu", + COUNT(CASE WHEN (dsm.message is not null AND dsm.read_at IS NOT NULL AND dsm.back_user_id IS NULL) THEN 1 END)::integer AS "lu", + COUNT(CASE WHEN (dsm.message is not null AND dsm.front_user_id IS NULL) THEN 1 END)::integer AS "repondu" FROM front.demande_sejour ds JOIN front.organismes o ON o.id = ds.organisme_id LEFT JOIN front.agrements a ON a.organisme_id = ds.organisme_id + LEFT JOIN front.demande_sejour_message dsm ON dsm.declaration_id = ds.id AND dsm.id = ( + SELECT MAX(dsmax.id) + FROM front.demande_sejour_message dsmax + WHERE dsmax.declaration_id = ds.id) WHERE jsonb_path_query_array(hebergement, '$.hebergements[*].coordonnees.adresse.departement') ?| ($1)::text[] OR a.region_obtention = '${territoireCode}' @@ -345,6 +352,7 @@ SELECT COUNT(DISTINCT ds.id) FROM front.demande_sejour ds JOIN front.organismes o ON o.id = ds.organisme_id LEFT JOIN front.agrements a ON a.organisme_id = ds.organisme_id +LEFT JOIN front.demande_sejour_message dsm ON dsm.declaration_id = ds.id WHERE statut <> 'BROUILLON' AND ((${departementQuery}) @@ -961,6 +969,9 @@ module.exports.getByDepartementCodes = async ( `statut in ('${dsStatus.statuts.EN_COURS}', '${dsStatus.statuts.EN_COURS_8J}', '${dsStatus.statuts.TRANSMISE}', '${dsStatus.statuts.TRANSMISE_8J}')`, ); } + if (search?.message) { + searchQuery.push(`dsm.message is not null`); + } /* * Cette Partie du code soit toujours etre appelé juste avant la fonction query.getByDepartementCodes @@ -975,7 +986,6 @@ module.exports.getByDepartementCodes = async ( departementQuery, params, ); - const stats = await pool.query( ...query.getAdminStats(departementCodes, territoireCode), ); diff --git a/packages/frontend-bo/src/components/demandes-sejour/liste.vue b/packages/frontend-bo/src/components/demandes-sejour/liste.vue index 563807c27..d15401dba 100644 --- a/packages/frontend-bo/src/components/demandes-sejour/liste.vue +++ b/packages/frontend-bo/src/components/demandes-sejour/liste.vue @@ -33,21 +33,15 @@ :values="[ { title: 'Messages non lus', - value: filteredDemandes.filter( - (d) => d.messageEtat === messageEtat.etat.NON_LU, - ).length, + value: sejourStore.stats?.nonlu || 0, }, { title: 'Messages lus', - value: filteredDemandes.filter( - (d) => d.messageEtat === messageEtat.etat.LU, - ).length, + value: sejourStore.stats?.lu || 0, }, { title: 'Messages répondus', - value: filteredDemandes.filter( - (d) => d.messageEtat === messageEtat.etat.REPONDU, - ).length, + value: sejourStore.stats?.repondu || 0, }, ]" /> @@ -162,7 +156,7 @@ - props.display === displayType.Messagerie - ? sejourStore.demandes.filter((d) => d.message) - : sejourStore.demandes, -); const defaultSort = []; const defaultLimit = 10; const defaultOffset = 0; @@ -267,6 +255,7 @@ const searchState = reactive({ .filter((statut) => Object.values(status.value).includes(statut)) : null, action: parseBoolean(route.query.action), + message: props.display === displayType.Messagerie, }); watch(