From 7e9873bd7eea7b5ff3ec6b84d37bb8c5c5ec1b44 Mon Sep 17 00:00:00 2001 From: Yohann Gablowski Date: Tue, 29 Oct 2024 09:15:35 +0100 Subject: [PATCH 1/5] feat(formations&etablissements): use data form formations for campagnes filters --- .../controllers/etablissements.controller.ts | 10 ------ .../src/controllers/formations.controller.ts | 6 ++-- server/src/dao/etablissements.dao.ts | 15 ++------- server/src/routes/etablissements.routes.ts | 5 --- server/src/routes/formations.routes.ts | 6 ++-- server/src/services/etablissements.service.ts | 10 ------ server/src/services/formations.service.ts | 33 +++++++++++++++++-- .../CampagnesSelector/CampagnesSelector.js | 22 +++++++------ .../useFetchDiplomesWithCampagnesCount.js | 12 +++---- ...seFetchEtablissementsWithCampagnesCount.js | 19 ----------- ui/src/queries/formations.js | 6 ++-- 11 files changed, 60 insertions(+), 84 deletions(-) delete mode 100644 ui/src/hooks/useFetchEtablissementsWithCampagnesCount.js diff --git a/server/src/controllers/etablissements.controller.ts b/server/src/controllers/etablissements.controller.ts index b16a5fa6..b754d440 100644 --- a/server/src/controllers/etablissements.controller.ts +++ b/server/src/controllers/etablissements.controller.ts @@ -72,13 +72,3 @@ export const getEtablissementsPublicStatistics = tryCatch(async (_req: any, res: return res.status(200).json(body); }); - -export const getEtablissementsWithCampagnesCount = tryCatch(async (req: any, res: any) => { - const userSiret = req.user?.etablissements?.map((etablissement) => etablissement.siret); - - const { success, body } = await etablissementsService.getEtablissementsWithCampagnesCount({ userSiret }); - - if (!success) throw new BasicError(); - - return res.status(200).json(body); -}); diff --git a/server/src/controllers/formations.controller.ts b/server/src/controllers/formations.controller.ts index 97547c64..609e92c4 100644 --- a/server/src/controllers/formations.controller.ts +++ b/server/src/controllers/formations.controller.ts @@ -60,10 +60,12 @@ export const updateFormation = tryCatch(async (req: any, res: any) => { return res.status(200).json(body); }); -export const getFormationsDiplomesWithCampagnes = tryCatch(async (req: any, res: any) => { +export const getFormationsEtablissementsDiplomesWithCampagnesCount = tryCatch(async (req: any, res: any) => { const userSiret = req.user?.etablissements?.map((etablissement) => etablissement.siret); - const { success, body } = await formationsService.getFormationsDiplomesWithCampagnes({ userSiret }); + const { success, body } = await formationsService.getFormationsEtablissementsDiplomesWithCampagnesCount({ + userSiret, + }); if (!success) throw new BasicError(); diff --git a/server/src/dao/etablissements.dao.ts b/server/src/dao/etablissements.dao.ts index 581a1a2f..5bd51c8d 100644 --- a/server/src/dao/etablissements.dao.ts +++ b/server/src/dao/etablissements.dao.ts @@ -110,9 +110,7 @@ export const update = async (id: string, updatedEtablissement: Partial => { - let baseQuery = getKbdClient() + const baseQuery = getKbdClient() .selectFrom("etablissements") .select([ "etablissements.id", @@ -150,15 +148,6 @@ export const findAllEtablissementWithCounts = async ( .groupBy("etablissements.id") .orderBy("campagnesCount", "desc"); - if (siret?.length) { - baseQuery = baseQuery.where((qb) => - qb.or([ - qb("formations.etablissement_gestionnaire_siret", "in", siret), - qb("formations.etablissement_formateur_siret", "in", siret), - ]) - ); - } - return baseQuery.execute(); }; diff --git a/server/src/routes/etablissements.routes.ts b/server/src/routes/etablissements.routes.ts index b34fa594..84e96ebf 100644 --- a/server/src/routes/etablissements.routes.ts +++ b/server/src/routes/etablissements.routes.ts @@ -9,7 +9,6 @@ import { getEtablissements, getEtablissementsPublicStatistics, getEtablissementsSuivi, - getEtablissementsWithCampagnesCount, getEtablissementsWithTemoignageCount, updateEtablissement, } from "../controllers/etablissements.controller"; @@ -35,10 +34,6 @@ export const etablissements = () => { } ); - router.get("/api/etablissements/with-campagnes-count", verifyUser, (req, res, next) => { - getEtablissementsWithCampagnesCount(req, res, next); - }); - router.get("/api/etablissements/temoignage-count", (req, res, next) => { getEtablissementsWithTemoignageCount(req, res, next); }); diff --git a/server/src/routes/formations.routes.ts b/server/src/routes/formations.routes.ts index a55f108b..bfddc0c6 100644 --- a/server/src/routes/formations.routes.ts +++ b/server/src/routes/formations.routes.ts @@ -6,7 +6,7 @@ import { createFormation, deleteFormation, getFormations, - getFormationsDiplomesWithCampagnes, + getFormationsEtablissementsDiplomesWithCampagnesCount, getFormationsWithTemoignageCount, updateFormation, } from "../controllers/formations.controller"; @@ -60,8 +60,8 @@ export const formations = () => { } ); - router.get("/api/formations/diplomes-with-campagnes", verifyUser, (req, res, next) => { - getFormationsDiplomesWithCampagnes(req, res, next); + router.get("/api/formations/diplomes-and-etablissements-filters", verifyUser, (req, res, next) => { + getFormationsEtablissementsDiplomesWithCampagnesCount(req, res, next); }); return router; diff --git a/server/src/services/etablissements.service.ts b/server/src/services/etablissements.service.ts index 324c8598..14d84716 100644 --- a/server/src/services/etablissements.service.ts +++ b/server/src/services/etablissements.service.ts @@ -156,13 +156,3 @@ export const getEtablissementsPublicStatistics = async () => { return { success: false, body: error }; } }; - -export const getEtablissementsWithCampagnesCount = async ({ userSiret }) => { - try { - const etablissements = await etablissementsDao.findAllEtablissementWithCounts(userSiret); - - return { success: true, body: etablissements }; - } catch (error) { - return { success: false, body: error }; - } -}; diff --git a/server/src/services/formations.service.ts b/server/src/services/formations.service.ts index 13ccaf4e..138ab451 100644 --- a/server/src/services/formations.service.ts +++ b/server/src/services/formations.service.ts @@ -82,7 +82,7 @@ export const updateFormation = async (id, updatedFormation) => { } }; -export const getFormationsDiplomesWithCampagnes = async ({ userSiret }) => { +export const getFormationsEtablissementsDiplomesWithCampagnesCount = async ({ userSiret }) => { try { const formations = await formationsDao.findAllWithCampagnesCount(userSiret); @@ -98,14 +98,41 @@ export const getFormationsDiplomesWithCampagnes = async ({ userSiret }) => { return acc; }, {}); - const result = Object.keys(formattedByDiplome) + const formattedByEtablissement = formations.reduce((acc, formation) => { + const etablissementFormateurSiret = formation.etablissementFormateurSiret || "N/A"; + + if (!acc[etablissementFormateurSiret]) { + acc[etablissementFormateurSiret] = { + campagnesCount: 0, + etablissementFormateurEnseigne: formation.etablissementFormateurEnseigne, + etablissementFormateurEntrepriseRaisonSociale: formation.etablissementFormateurEntrepriseRaisonSociale, + etablissementFormateurSiret: formation.etablissementFormateurSiret, + }; + } + + acc[etablissementFormateurSiret].campagnesCount += formation.campagnesCount; + + return acc; + }, {}); + + const diplomes = Object.keys(formattedByDiplome) .map((diplome) => ({ intitule: diplome, campagnesCount: formattedByDiplome[diplome], })) .sort((a, b) => b.campagnesCount - a.campagnesCount); - return { success: true, body: result }; + const etablissements = Object.keys(formattedByEtablissement) + .map((etablissement) => ({ + etablissementFormateurSiret: etablissement, + etablissementFormateurEnseigne: formattedByEtablissement[etablissement].etablissementFormateurEnseigne, + etablissementFormateurEntrepriseRaisonSociale: + formattedByEtablissement[etablissement].etablissementFormateurEntrepriseRaisonSociale, + campagnesCount: formattedByEtablissement[etablissement].campagnesCount, + })) + .sort((a, b) => b.campagnesCount - a.campagnesCount); + + return { success: true, body: { diplomes, etablissements } }; } catch (error) { return { success: false, body: error }; } diff --git a/ui/src/campagnes/Shared/CampagnesSelector/CampagnesSelector.js b/ui/src/campagnes/Shared/CampagnesSelector/CampagnesSelector.js index 8c52089e..83b7ff97 100644 --- a/ui/src/campagnes/Shared/CampagnesSelector/CampagnesSelector.js +++ b/ui/src/campagnes/Shared/CampagnesSelector/CampagnesSelector.js @@ -15,8 +15,7 @@ import { import { UserContext } from "../../../context/UserContext"; import useFetchCampagnes from "../../../hooks/useFetchCampagnes"; import useFetchDiplomesWithCampagnesCount from "../../../hooks/useFetchDiplomesWithCampagnesCount"; -import useFetchEtablissementsWithCampagnes from "../../../hooks/useFetchEtablissementsWithCampagnesCount"; -import { etablissementLabelGetter } from "../../../utils/etablissement"; +import { etablissementLabelGetterFromFormation } from "../../../utils/etablissement"; import ActionButtons from "../../ManageCampagne/ActionButtons/ActionButtons"; import { ButtonContainer } from "../../styles/resultsCampagnes.style"; import { HeaderContainer, LoaderContainer } from "../../styles/shared.style"; @@ -58,9 +57,12 @@ const CampagnesSelector = ({ page: page, pageSize: 20, }); - const { etablissementsWithCampagnes, isSuccess: isSuccessEtablissementsWithCampagnes } = - useFetchEtablissementsWithCampagnes(); - const { diplomesWithCampagnes, isSuccess: isSuccessDiplomesWithCampagnes } = useFetchDiplomesWithCampagnesCount(); + + const { + diplomesFilter, + etablissementsFilter, + isSuccess: isSuccessDiplomesAndEtablissementsFilter, + } = useFetchDiplomesWithCampagnesCount(); const currentPageCampagneIds = campagnes?.map((campagne) => campagne.id); @@ -106,7 +108,7 @@ const CampagnesSelector = ({ severity="error" /> ) : null} - {isSuccessDiplomesWithCampagnes && isSuccessEtablissementsWithCampagnes && ( + {isSuccessDiplomesAndEtablissementsFilter && ( ({ - label: etablissementLabelGetter(etablissement), - value: etablissement.siret, + etablissementsOptions={etablissementsFilter?.map((etablissement) => ({ + label: etablissementLabelGetterFromFormation(etablissement), + value: etablissement.etablissementFormateurSiret, hintText: `${etablissement.campagnesCount} campagne${isPlural(etablissement.campagnesCount)}`, }))} - diplomesOptions={diplomesWithCampagnes?.map((diplome) => ({ + diplomesOptions={diplomesFilter?.map((diplome) => ({ label: DIPLOME_TYPE_MATCHER[diplome.intitule] || diplome.intitule, value: diplome.intitule, hintText: `${diplome.campagnesCount} campagne${isPlural(diplome.campagnesCount)}`, diff --git a/ui/src/hooks/useFetchDiplomesWithCampagnesCount.js b/ui/src/hooks/useFetchDiplomesWithCampagnesCount.js index 5479b2cc..8208070c 100644 --- a/ui/src/hooks/useFetchDiplomesWithCampagnesCount.js +++ b/ui/src/hooks/useFetchDiplomesWithCampagnesCount.js @@ -2,18 +2,18 @@ import { useQuery } from "@tanstack/react-query"; import { useContext } from "react"; import { UserContext } from "../context/UserContext"; -import { fetchDiplomesWithCampagnes } from "../queries/formations"; +import { fetchDiplomesAndEtablissementsFilter } from "../queries/formations"; -const useFetchDiplomesWithCampagnes = () => { +const useFetchDiplomesAndEtablissementsFilter = () => { const [userContext] = useContext(UserContext); const { data, isSuccess, isError, isLoading } = useQuery({ - queryKey: ["diplomes-with-campagnes"], - queryFn: () => fetchDiplomesWithCampagnes({ token: userContext.token }), + queryKey: ["diplomes-and-etablissements-filters"], + queryFn: () => fetchDiplomesAndEtablissementsFilter({ token: userContext.token }), enabled: !!userContext.token, }); - return { diplomesWithCampagnes: data, isSuccess, isError, isLoading }; + return { diplomesFilter: data?.diplomes, etablissementsFilter: data?.etablissements, isSuccess, isError, isLoading }; }; -export default useFetchDiplomesWithCampagnes; +export default useFetchDiplomesAndEtablissementsFilter; diff --git a/ui/src/hooks/useFetchEtablissementsWithCampagnesCount.js b/ui/src/hooks/useFetchEtablissementsWithCampagnesCount.js deleted file mode 100644 index a23251f8..00000000 --- a/ui/src/hooks/useFetchEtablissementsWithCampagnesCount.js +++ /dev/null @@ -1,19 +0,0 @@ -import { useQuery } from "@tanstack/react-query"; -import { useContext } from "react"; - -import { UserContext } from "../context/UserContext"; -import { fetchEtablissementsWithCampagnesCount } from "../queries/etablissements"; - -const useFetchEtablissementsWithCampagnesCount = () => { - const [userContext] = useContext(UserContext); - - const { data, isSuccess, isError, isLoading } = useQuery({ - queryKey: ["etablissements-with-campagnes-count"], - queryFn: () => fetchEtablissementsWithCampagnesCount({ token: userContext.token }), - enabled: !!userContext.token, - }); - - return { etablissementsWithCampagnes: data, isSuccess, isError, isLoading }; -}; - -export default useFetchEtablissementsWithCampagnesCount; diff --git a/ui/src/queries/formations.js b/ui/src/queries/formations.js index 90163249..9944bd4d 100644 --- a/ui/src/queries/formations.js +++ b/ui/src/queries/formations.js @@ -44,8 +44,8 @@ export const fetchLocalFormations = async ({ token, etablissementSiret, search } return response; }; -export const fetchDiplomesWithCampagnes = async ({ token }) => { - const url = `/api/formations/diplomes-with-campagnes`; +export const fetchDiplomesAndEtablissementsFilter = async ({ token }) => { + const url = `/api/formations/diplomes-and-etablissements-filters`; const response = await apiGet(url, { headers: { @@ -54,7 +54,7 @@ export const fetchDiplomesWithCampagnes = async ({ token }) => { }); if (response.error) { - throw new Error("Erreur dans le chargement des diplômes"); + throw new Error("Erreur dans le chargement des diplômes et établissements"); } return response; From dcf9d63105352d782fd54614bcac439a67718ac4 Mon Sep 17 00:00:00 2001 From: Yohann Gablowski Date: Tue, 29 Oct 2024 09:44:42 +0100 Subject: [PATCH 2/5] feat(campagnes): simplify campagnes fetching through filters --- .../src/controllers/campagnes.controller.ts | 10 ++--- server/src/dao/campagnes.dao.ts | 29 +++---------- server/src/services/campagnes.service.ts | 43 ++----------------- 3 files changed, 14 insertions(+), 68 deletions(-) diff --git a/server/src/controllers/campagnes.controller.ts b/server/src/controllers/campagnes.controller.ts index 28aa0eae..b990ab0b 100644 --- a/server/src/controllers/campagnes.controller.ts +++ b/server/src/controllers/campagnes.controller.ts @@ -5,16 +5,14 @@ import * as campagnesService from "../services/campagnes.service"; import tryCatch from "../utils/tryCatch.utils"; export const getCampagnes = tryCatch(async (req: any, res: any) => { - const isAdmin = req.user.role === USER_ROLES.ADMIN; const isObserver = req.user.role === USER_ROLES.OBSERVER; const scope = isObserver ? req.user.scope : null; - const userSiret = req.user?.etablissements?.map((etablissement) => etablissement.siret); const page = req.body.page || 1; const pageSize = req.body.pageSize || 10; const diplome = req.body.diplome; - const etablissementFormateurSiret = req.body.siret; + const siret = req.body.siret; const search = req.body.search; const departement = req.body.departement; @@ -24,8 +22,8 @@ export const getCampagnes = tryCatch(async (req: any, res: any) => { query.diplome = diplome; } - if (etablissementFormateurSiret) { - query.etablissementFormateurSiret = etablissementFormateurSiret; + if (siret) { + query.siret = siret; } if (departement) { @@ -33,9 +31,7 @@ export const getCampagnes = tryCatch(async (req: any, res: any) => { } const { success, body, ids, pagination } = await campagnesService.getCampagnes({ - isAdmin, isObserver, - userSiret, scope, page, pageSize, diff --git a/server/src/dao/campagnes.dao.ts b/server/src/dao/campagnes.dao.ts index e1271611..77f441fa 100644 --- a/server/src/dao/campagnes.dao.ts +++ b/server/src/dao/campagnes.dao.ts @@ -4,13 +4,11 @@ import { getKbdClient } from "../db/db"; import type { ObserverScope } from "../types"; export const getAllWithTemoignageCountAndTemplateName = async ({ - //siret, query, scope, allowEmptyFilter = false, }: { - //siret?: string[]; - query: { diplome?: string; etablissementFormateurSiret?: string; departement?: string; campagneIds: string[] }; + query: { diplome?: string[]; siret?: string[]; departement?: string; campagneIds: string[] }; scope?: ObserverScope; allowEmptyFilter?: boolean; }) => { @@ -78,7 +76,10 @@ export const getAllWithTemoignageCountAndTemplateName = async ({ .leftJoin("etablissements", "formations.etablissement_id", "etablissements.id") .where("campagnes.deleted_at", "is", null) .where("formations.deleted_at", "is", null) - .groupBy(["campagnes.id", "questionnaires.id", "formations.id", "etablissements.id"]); + .where("etablissements.deleted_at", "is", null) + .where("temoignages.deleted_at", "is", null) + .groupBy(["campagnes.id", "questionnaires.id", "formations.id", "etablissements.id"]) + .orderBy("campagnes.created_at", "desc"); if (scope && scope.field && scope.field !== "sirets" && scope.value) { baseQuery = baseQuery.where(`formations.${scope.field}`, "=", scope.value); @@ -95,30 +96,14 @@ export const getAllWithTemoignageCountAndTemplateName = async ({ baseQuery = baseQuery.where("formations.diplome", "in", ["INVALID_DIPLOME"]); } - if (query && query.etablissementFormateurSiret?.length) { - baseQuery = baseQuery.where("formations.etablissement_formateur_siret", "in", query.etablissementFormateurSiret); - } else if (!allowEmptyFilter) { - // Force query to return no results by adding a false condition - baseQuery = baseQuery.where("formations.etablissement_formateur_siret", "in", ["INVALID_SIRET"]); - } - if (query && query.departement) { baseQuery = baseQuery.where("formations.num_departement", "=", query.departement); } - if (query && query.campagneIds?.length) { - baseQuery = baseQuery.where("campagnes.id", "in", query.campagneIds); + if (query && query?.siret?.length) { + baseQuery = baseQuery.where("formations.etablissement_formateur_siret", "in", query.siret); } - /*if (siret) { - baseQuery = baseQuery.where((qb) => - qb.or([ - qb("formations.etablissement_gestionnaire_siret", "in", siret), - qb("formations.etablissement_formateur_siret", "in", siret), - ]) - ); - }*/ - return baseQuery.execute(); }; diff --git a/server/src/services/campagnes.service.ts b/server/src/services/campagnes.service.ts index c854b593..f34a02a2 100644 --- a/server/src/services/campagnes.service.ts +++ b/server/src/services/campagnes.service.ts @@ -1,6 +1,6 @@ // @ts-nocheck -- TODO -import { DIPLOME_TYPE_MATCHER, ETABLISSEMENT_NATURE, ETABLISSEMENT_RELATION_TYPE } from "../constants"; +import { DIPLOME_TYPE_MATCHER } from "../constants"; import * as campagnesDao from "../dao/campagnes.dao"; import * as etablissementsDao from "../dao/etablissements.dao"; import * as formationsDao from "../dao/formations.dao"; @@ -9,53 +9,18 @@ import * as temoignagesDao from "../dao/temoignages.dao"; import * as verbatimsDao from "../dao/verbatims.dao"; import * as catalogue from "../modules/catalogue"; import * as pdfExport from "../modules/pdfExport"; -import * as referentiel from "../modules/referentiel"; import * as xlsxExport from "../modules/xlsxExport"; import { appendDataWhenEmpty, getMedianDuration, getStatistics } from "../utils/campagnes.utils"; import { getChampsLibreField } from "../utils/verbatims.utils"; -export const getCampagnes = async ({ - isAdmin, - isObserver, - userSiret, - scope, - page = 1, - pageSize = 10, - query, - search, -}) => { +export const getCampagnes = async ({ isObserver, scope, page = 1, pageSize = 10, query, search }) => { try { let campagnes = []; - if (isAdmin) { - campagnes = await campagnesDao.getAllWithTemoignageCountAndTemplateName({ query }); - } else if (isObserver) { + if (isObserver) { campagnes = await campagnesDao.getAllWithTemoignageCountAndTemplateName({ scope, query }); } else { - const etablissementsFromReferentiel = await referentiel.getEtablissements(userSiret); - - const allSirets = []; - for (const siret of userSiret) { - const etablissement = etablissementsFromReferentiel.find((etablissement) => etablissement.siret === siret); - if (!etablissement) continue; - - const relatedSirets = [siret]; - if ( - [ETABLISSEMENT_NATURE.GESTIONNAIRE, ETABLISSEMENT_NATURE.GESTIONNAIRE_FORMATEUR].includes( - etablissement.nature - ) - ) { - relatedSirets.push( - ...etablissement.relations - .filter((relation) => relation.type === ETABLISSEMENT_RELATION_TYPE.RESPONSABLE_FORMATEUR) - .map((etablissement) => etablissement.siret) - ); - } - allSirets.push(...relatedSirets); - } - - query.etablissementFormateurSiret = allSirets; - campagnes = await campagnesDao.getAllWithTemoignageCountAndTemplateName({ siret: allSirets, query }); + campagnes = await campagnesDao.getAllWithTemoignageCountAndTemplateName({ query }); } const unpaginatedCampagnesIds = campagnes.map((campagne) => campagne.id); From 8f6593d6dfcdcb8d802bed08f3d2d0089885b767 Mon Sep 17 00:00:00 2001 From: Yohann Gablowski Date: Tue, 29 Oct 2024 10:07:21 +0100 Subject: [PATCH 3/5] feat(campagnes): add support for observer account --- server/src/controllers/formations.controller.ts | 4 ++++ server/src/dao/campagnes.dao.ts | 4 ++++ server/src/dao/formations.dao.ts | 15 +++++++++++++-- server/src/services/formations.service.ts | 4 ++-- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/server/src/controllers/formations.controller.ts b/server/src/controllers/formations.controller.ts index 609e92c4..dc763d22 100644 --- a/server/src/controllers/formations.controller.ts +++ b/server/src/controllers/formations.controller.ts @@ -1,5 +1,6 @@ // @ts-nocheck -- TODO +import { USER_ROLES } from "../constants"; import { BasicError, ErrorMessage, FormationAlreadyExistingError, FormationNotFoundError } from "../errors"; import * as formationsService from "../services/formations.service"; import tryCatch from "../utils/tryCatch.utils"; @@ -61,10 +62,13 @@ export const updateFormation = tryCatch(async (req: any, res: any) => { }); export const getFormationsEtablissementsDiplomesWithCampagnesCount = tryCatch(async (req: any, res: any) => { + const isObserver = req.user?.role === USER_ROLES.OBSERVER; + const scope = isObserver ? req.user?.scope : null; const userSiret = req.user?.etablissements?.map((etablissement) => etablissement.siret); const { success, body } = await formationsService.getFormationsEtablissementsDiplomesWithCampagnesCount({ userSiret, + scope, }); if (!success) throw new BasicError(); diff --git a/server/src/dao/campagnes.dao.ts b/server/src/dao/campagnes.dao.ts index 77f441fa..c468f196 100644 --- a/server/src/dao/campagnes.dao.ts +++ b/server/src/dao/campagnes.dao.ts @@ -96,6 +96,10 @@ export const getAllWithTemoignageCountAndTemplateName = async ({ baseQuery = baseQuery.where("formations.diplome", "in", ["INVALID_DIPLOME"]); } + if (query && query.campagneIds?.length) { + baseQuery = baseQuery.where("campagnes.id", "in", query.campagneIds); + } + if (query && query.departement) { baseQuery = baseQuery.where("formations.num_departement", "=", query.departement); } diff --git a/server/src/dao/formations.dao.ts b/server/src/dao/formations.dao.ts index 73ed664c..dc26476a 100644 --- a/server/src/dao/formations.dao.ts +++ b/server/src/dao/formations.dao.ts @@ -2,7 +2,7 @@ import type { DeleteResult } from "kysely"; import { sql } from "kysely"; import { getKbdClient } from "../db/db"; -import type { Formation } from "../types"; +import type { Formation, ObserverScope } from "../types"; export const create = async (formation: Formation): Promise<{ id: string } | undefined> => { return getKbdClient().insertInto("formations").values(formation).returning("id").executeTakeFirst(); @@ -293,7 +293,10 @@ export const findAllWithTemoignageCount = async (): Promise[] .execute(); }; -export const findAllWithCampagnesCount = async (siret: string[]): Promise[] | undefined> => { +export const findAllWithCampagnesCount = async ( + siret: string[], + scope?: ObserverScope +): Promise[] | undefined> => { let baseQuery = getKbdClient() .selectFrom("formations") .leftJoin("formations_campagnes", "formations.id", "formations_campagnes.formation_id") @@ -334,5 +337,13 @@ export const findAllWithCampagnesCount = async (siret: string[]): Promise { } }; -export const getFormationsEtablissementsDiplomesWithCampagnesCount = async ({ userSiret }) => { +export const getFormationsEtablissementsDiplomesWithCampagnesCount = async ({ userSiret, scope }) => { try { - const formations = await formationsDao.findAllWithCampagnesCount(userSiret); + const formations = await formationsDao.findAllWithCampagnesCount(userSiret, scope); const formattedByDiplome = formations.reduce((acc, formation) => { const diplome = formation.diplome || "N/A"; From 5b472b5830a7e8ae0671294ce625fd104861d651 Mon Sep 17 00:00:00 2001 From: Yohann Gablowski Date: Tue, 29 Oct 2024 10:16:41 +0100 Subject: [PATCH 4/5] feat(CampagnesTables): smaller font size --- .../Shared/CampagnesTable/campagnesTable.style.js | 12 +++++++++--- ui/src/campagnes/styles/shared.style.js | 4 ++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/ui/src/campagnes/Shared/CampagnesTable/campagnesTable.style.js b/ui/src/campagnes/Shared/CampagnesTable/campagnesTable.style.js index 914847cb..425f41f0 100644 --- a/ui/src/campagnes/Shared/CampagnesTable/campagnesTable.style.js +++ b/ui/src/campagnes/Shared/CampagnesTable/campagnesTable.style.js @@ -8,7 +8,7 @@ export const EtablissementLabelContainer = styled.div` margin-top: 0.5rem; & > p { - font-size: 14px; + font-size: 12px; line-height: 16px; } `; @@ -35,13 +35,19 @@ export const TableContainer = styled.div` & > .fr-table { margin-bottom: 0; } + + & > .fr-table > table td { + padding: 0.5rem 1rem; + } + & > .fr-table > table { padding-bottom: ${fr.spacing("3w")}; } `; export const DiplomeLabel = styled.p` - font-size: 14px; + font-size: 12px; + line-height: 20px; color: var(--text-disabled-grey); - margin-top: 10px; + margin-top: 8px; `; diff --git a/ui/src/campagnes/styles/shared.style.js b/ui/src/campagnes/styles/shared.style.js index 53fbf465..84b9f103 100644 --- a/ui/src/campagnes/styles/shared.style.js +++ b/ui/src/campagnes/styles/shared.style.js @@ -85,8 +85,8 @@ export const ButtonContainer = styled.div` export const IntituleFormation = styled.h6` color: var(--text-action-high-blue-france); font-weight: 700; - font-size: 16px; - line-height: 24px; + font-size: 14px; + line-height: 20px; margin: 10px 0; `; From bae2b1983f342dd8dad22d93638fbb5a35300789 Mon Sep 17 00:00:00 2001 From: Yohann Gablowski Date: Tue, 29 Oct 2024 10:31:09 +0100 Subject: [PATCH 5/5] feat(MultiSelect): add label --- ui/src/Components/MultiSelect/MultiSelect.js | 3 ++- ui/src/campagnes/CreateCampagnes/CampagneConfigurator.js | 4 ++-- ui/src/campagnes/CreateCampagnes/FormationsSelector.js | 4 ++-- .../Shared/CampagnesSelector/CampagnesSelector.js | 4 ++-- .../SortButtons.js => FilterButtons/FilterButtons.js} | 8 +++++--- .../FilterButtons.style.js} | 0 6 files changed, 13 insertions(+), 10 deletions(-) rename ui/src/campagnes/Shared/{SortButtons/SortButtons.js => FilterButtons/FilterButtons.js} (92%) rename ui/src/campagnes/Shared/{SortButtons/sortButtons.style.js => FilterButtons/FilterButtons.style.js} (100%) diff --git a/ui/src/Components/MultiSelect/MultiSelect.js b/ui/src/Components/MultiSelect/MultiSelect.js index c3a98449..db903c87 100644 --- a/ui/src/Components/MultiSelect/MultiSelect.js +++ b/ui/src/Components/MultiSelect/MultiSelect.js @@ -7,7 +7,7 @@ import { useEffect, useRef, useState } from "react"; import { isPlural } from "../../campagnes/utils"; import { InputContainer, MenuContainer, MultSelectContainer } from "./MultiSelect.style"; -const MultiSelect = ({ options, name, placeholder = "", selected, setSelected }) => { +const MultiSelect = ({ options, name, placeholder = "", label, selected, setSelected }) => { const [isOpen, setIsOpen] = useState(false); const [values, setValues] = useState(selected || []); const [search, setSearch] = useState(""); @@ -83,6 +83,7 @@ const MultiSelect = ({ options, name, placeholder = "", selected, setSelected }) <> - { <> {isSuccessFormations && ( <> - ) : null} {isSuccessDiplomesAndEtablissementsFilter && ( -