diff --git a/.eslintrc.json b/.eslintrc.json index f2ed6902e1..ca73ac10bd 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -12,9 +12,15 @@ "enforceBuildableLibDependency": true, "allowCircularSelfDependency": true, "banTransitiveDependencies": true, - // Exception due to issue in tailwind alias import with Nx structure - // https://github.com/tailwindlabs/tailwindcss/issues/11097 - "allow": ["../ui/src/tailwind-preset"], + "allow": [ + // Exception due to issue in tailwind alias import with Nx structure + // https://github.com/tailwindlabs/tailwindcss/issues/11097 + "../ui/src/tailwind-preset", + + // `@/domain` imports are used as a library but exists inside the `backend` application. + // We explicitely allow our front apps to be allowed to reference it. + "@/domain" + ], "depConstraints": [ { "sourceTag": "*", diff --git a/.gitignore b/.gitignore index 74e53c1044..cece4bc63a 100644 --- a/.gitignore +++ b/.gitignore @@ -61,4 +61,4 @@ storybook-static **/package.json # gcloud credentials -backend/src/common/services/keyfile.json +keyfile.json diff --git a/Earthfile b/Earthfile index 7676214184..3f84268fbe 100644 --- a/Earthfile +++ b/Earthfile @@ -302,8 +302,7 @@ node-alpine-with-all-deps: # Copy shared libraries COPY $API_DIR $API_DIR COPY $UI_DIR $UI_DIR - # Temporarily consider the Backend as a shared library. - # The app build needs it to resolve the import of the trpc AppRouter. + # Backend is also used as a shared library COPY $BACKEND_DIR $BACKEND_DIR @@ -347,6 +346,8 @@ front-deps: # Copy only shared libraries COPY $API_DIR $API_DIR COPY $UI_DIR $UI_DIR + # Backend is also used as a shared library + COPY $BACKEND_DIR $BACKEND_DIR front-deps-builder: LOCALLY @@ -398,11 +399,11 @@ backend-test: tools-automation-api-docker: BUILD --pass-args ./apps/tools-automation-api+docker - + tools-automation-api-deploy: ARG --required KOYEB_API_KEY BUILD --pass-args ./apps/tools-automation-api+deploy - + tools-automation-api-test: BUILD --pass-args ./apps/tools-automation-api+test @@ -465,11 +466,9 @@ app-test-build: ## construit une image pour exécuter les tests unitaires de l'a FROM +front-deps ENV NEXT_PUBLIC_SUPABASE_URL ENV NEXT_PUBLIC_SUPABASE_ANON_KEY + # copie les sources du module à tester COPY $APP_DIR $APP_DIR - COPY $API_DIR $API_DIR - COPY $UI_DIR $UI_DIR - COPY ./vitest.workspace.ts ./ # la commande utilisée pour lancer les tests CMD pnpm run test:app @@ -490,8 +489,7 @@ package-api-test-build: ## construit une image pour exécuter les tests d'intég ENV SUPABASE_URL ENV SUPABASE_ANON_KEY ENV SUPABASE_SERVICE_ROLE_KEY - # copie les sources du module à tester - COPY $API_DIR $API_DIR + # la commande utilisée pour lancer les tests CMD pnpm run test:api SAVE IMAGE package-api-test:latest @@ -530,8 +528,7 @@ auth-build: ## construit l'image du module d'authentification EXPOSE $PORT # copie les sources des modules à construire COPY $AUTH_DIR $AUTH_DIR - COPY $UI_DIR $UI_DIR - COPY $API_DIR $API_DIR + RUN pnpm run build:auth CMD ["dumb-init", "./node_modules/.bin/next", "start", "./packages/auth/"] SAVE IMAGE --cache-from=$AUTH_IMG_NAME --push $AUTH_IMG_NAME diff --git a/app.territoiresentransitions.react/src/app/pages/collectivite/Indicateurs/Indicateur/detail/useIndicateurServices.ts b/app.territoiresentransitions.react/src/app/pages/collectivite/Indicateurs/Indicateur/detail/useIndicateurServices.ts index dbef59a5f8..b400f62f33 100644 --- a/app.territoiresentransitions.react/src/app/pages/collectivite/Indicateurs/Indicateur/detail/useIndicateurServices.ts +++ b/app.territoiresentransitions.react/src/app/pages/collectivite/Indicateurs/Indicateur/detail/useIndicateurServices.ts @@ -1,6 +1,7 @@ -import { Indicateurs, SharedDomain } from '@/api'; +import { Indicateurs } from '@/api'; import { supabaseClient } from '@/app/core-logic/api/supabase'; import { useCollectiviteId } from '@/app/core-logic/hooks/params'; +import { Tag } from '@/domain/collectivites'; import { useMutation, useQuery, useQueryClient } from 'react-query'; /** Met à jour les services pilotes d'un indicateur */ @@ -10,7 +11,7 @@ export const useUpsertIndicateurServices = (indicateurId: number) => { return useMutation({ mutationKey: 'upsert_indicateur_services', - mutationFn: async (services: SharedDomain.Tag[]) => { + mutationFn: async (services: Tag[]) => { if (!collectiviteId) return; return Indicateurs.save.upsertServices( supabaseClient, @@ -19,7 +20,7 @@ export const useUpsertIndicateurServices = (indicateurId: number) => { services ); }, - onSuccess: (data, variables) => { + onSuccess: () => { // recharge les infos complémentaires associées à l'indicateur queryClient.invalidateQueries([ 'indicateur_services', diff --git a/app.territoiresentransitions.react/src/app/pages/collectivite/Indicateurs/IndicateurPersoNouveau.tsx b/app.territoiresentransitions.react/src/app/pages/collectivite/Indicateurs/IndicateurPersoNouveau.tsx index c71cd37b91..b5f6dcd4eb 100644 --- a/app.territoiresentransitions.react/src/app/pages/collectivite/Indicateurs/IndicateurPersoNouveau.tsx +++ b/app.territoiresentransitions.react/src/app/pages/collectivite/Indicateurs/IndicateurPersoNouveau.tsx @@ -1,5 +1,4 @@ import { FicheAction } from '@/api/plan-actions'; -import { Thematique } from '@/api/shared/domain'; import { TIndicateurPersoDefinitionWrite, useInsertIndicateurPersoDefinition, @@ -8,6 +7,7 @@ import { makeCollectiviteIndicateursUrl } from '@/app/app/paths'; import { useCollectiviteId } from '@/app/core-logic/hooks/params'; import ThematiquesDropdown from '@/app/ui/dropdownLists/ThematiquesDropdown/ThematiquesDropdown'; import FormikInput from '@/app/ui/shared/form/formik/FormikInput'; +import { Thematique } from '@/domain/shared'; import { Alert, Button, Checkbox, Field, FormSectionGrid } from '@/ui'; import { Form, Formik } from 'formik'; import { useRouter } from 'next/navigation'; diff --git a/app.territoiresentransitions.react/src/app/pages/collectivite/Indicateurs/lists/IndicateurCard/IndicateurCardEdit/IndicateurCardEditModal.tsx b/app.territoiresentransitions.react/src/app/pages/collectivite/Indicateurs/lists/IndicateurCard/IndicateurCardEdit/IndicateurCardEditModal.tsx index d452ec4d15..d56245a498 100644 --- a/app.territoiresentransitions.react/src/app/pages/collectivite/Indicateurs/lists/IndicateurCard/IndicateurCardEdit/IndicateurCardEditModal.tsx +++ b/app.territoiresentransitions.react/src/app/pages/collectivite/Indicateurs/lists/IndicateurCard/IndicateurCardEdit/IndicateurCardEditModal.tsx @@ -1,9 +1,10 @@ -import { SharedDomain } from '@/api'; import { Personne } from '@/api/collectivites'; import { useUpdateIndicateurCard } from '@/app/app/pages/collectivite/Indicateurs/lists/IndicateurCard/IndicateurCardEdit/useUpdateIndicateurCard'; import PersonnesDropdown from '@/app/ui/dropdownLists/PersonnesDropdown/PersonnesDropdown'; import ServicesPilotesDropdown from '@/app/ui/dropdownLists/ServicesPilotesDropdown/ServicesPilotesDropdown'; import ThematiquesDropdown from '@/app/ui/dropdownLists/ThematiquesDropdown/ThematiquesDropdown'; +import { Tag } from '@/domain/collectivites'; +import { Thematique } from '@/domain/shared'; import { Field, Modal, ModalFooterOKCancel } from '@/ui'; import { OpenState } from '@/ui/utils/types'; import { useEffect, useState } from 'react'; @@ -37,8 +38,8 @@ const IndicateurCardEditModal = ({ const [state, setState] = useState<{ pilotes: Personne[]; - services: SharedDomain.Tag[]; - thematiques: SharedDomain.Thematique[]; + services: Tag[]; + thematiques: Thematique[]; }>(initialState); useEffect(() => { diff --git a/app.territoiresentransitions.react/src/app/pages/collectivite/Indicateurs/lists/IndicateurCard/IndicateurCardEdit/useUpdateIndicateurCard.ts b/app.territoiresentransitions.react/src/app/pages/collectivite/Indicateurs/lists/IndicateurCard/IndicateurCardEdit/useUpdateIndicateurCard.ts index d6eb733ca7..7ff880d756 100644 --- a/app.territoiresentransitions.react/src/app/pages/collectivite/Indicateurs/lists/IndicateurCard/IndicateurCardEdit/useUpdateIndicateurCard.ts +++ b/app.territoiresentransitions.react/src/app/pages/collectivite/Indicateurs/lists/IndicateurCard/IndicateurCardEdit/useUpdateIndicateurCard.ts @@ -1,10 +1,10 @@ -import { useMutation } from 'react-query'; - import { Indicateurs } from '@/api'; import { Personne } from '@/api/collectivites'; -import { Tag, Thematique } from '@/api/shared/domain'; import { supabaseClient } from '@/app/core-logic/api/supabase'; import { useCollectiviteId } from '@/app/core-logic/hooks/params'; +import { Tag } from '@/domain/collectivites'; +import { Thematique } from '@/domain/shared'; +import { useMutation } from 'react-query'; /** Met à jour les pilotes, les services pilotes, les thématique d'un indicateur */ export const useUpdateIndicateurCard = ( diff --git a/app.territoiresentransitions.react/src/app/pages/collectivite/Indicateurs/lists/useFilteredIndicateurDefinitions.ts b/app.territoiresentransitions.react/src/app/pages/collectivite/Indicateurs/lists/useFilteredIndicateurDefinitions.ts index 8a8a90ba9a..0c3f7b72da 100644 --- a/app.territoiresentransitions.react/src/app/pages/collectivite/Indicateurs/lists/useFilteredIndicateurDefinitions.ts +++ b/app.territoiresentransitions.react/src/app/pages/collectivite/Indicateurs/lists/useFilteredIndicateurDefinitions.ts @@ -27,7 +27,7 @@ export const useFilteredIndicateurDefinitions = ( delete options.filtre?.text; // Delete it, search is done locally for now due to backend reasons } - const { data, error, isLoading } = trpc.indicateurs.filtre.list.useQuery( + const { data, error, isLoading } = trpc.indicateurs.list.useQuery( { collectiviteId: collectiviteId!, filtre: options.filtre ?? {}, diff --git a/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/ActionsGroupees/EditionPriorite.tsx b/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/ActionsGroupees/EditionPriorite.tsx index d9599be7d0..9dec48e2bd 100644 --- a/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/ActionsGroupees/EditionPriorite.tsx +++ b/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/ActionsGroupees/EditionPriorite.tsx @@ -1,6 +1,6 @@ -import { NiveauPriorite } from '@/api/plan-actions'; import { useCollectiviteId } from '@/app/core-logic/hooks/params'; import PrioritesSelectDropdown from '@/app/ui/dropdownLists/ficheAction/priorites/PrioritesSelectDropdown'; +import { Priorite } from '@/domain/plans/fiches'; import { Button, Field, useEventTracker } from '@/ui'; import { OpenState } from '@/ui/utils/types'; import { useState } from 'react'; @@ -16,7 +16,7 @@ const ModaleEditionPriorite = ({ openState, selectedIds, }: ModaleEditionPrioriteProps) => { - const [priorite, setPriorite] = useState(); + const [priorite, setPriorite] = useState(); const collectiviteId = useCollectiviteId()!; const tracker = useEventTracker('app/actions-groupees-fiches-action'); diff --git a/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/ActionsGroupees/EditionTagsLibres.tsx b/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/ActionsGroupees/EditionTagsLibres.tsx index ea6c13cc18..d3a6e8bdcc 100644 --- a/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/ActionsGroupees/EditionTagsLibres.tsx +++ b/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/ActionsGroupees/EditionTagsLibres.tsx @@ -1,6 +1,6 @@ -import { LibreTag } from '@/api/typeUtils'; import { useCollectiviteId } from '@/app/core-logic/hooks/params'; import TagsSuiviPersoDropdown from '@/app/ui/dropdownLists/TagsSuiviPersoDropdown/TagsSuiviPersoDropdown'; +import { Tag } from '@/domain/collectivites'; import { Button, Field, useEventTracker } from '@/ui'; import { OpenState } from '@/ui/utils/types'; import { useState } from 'react'; @@ -16,7 +16,7 @@ const ModaleEditionTagsLibres = ({ openState, selectedIds, }: ModaleEditionTagsLibresProps) => { - const [tags, setTags] = useState(); + const [tags, setTags] = useState(); const collectiviteId = useCollectiviteId()!; const tracker = useEventTracker('app/actions-groupees-fiches-action'); @@ -35,14 +35,14 @@ const ModaleEditionTagsLibres = ({ mutation.mutate({ ficheIds: selectedIds, libreTags: { - add: tags?.map((t) => ({ id: t.id! })) ?? undefined, + add: tags?.map((t) => ({ id: t.id })) ?? undefined, }, }); }} > t.id!)} + values={tags?.map((t) => t.id)} onChange={({ libresTag }) => setTags(libresTag)} /> diff --git a/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/ExportPdf/FicheActionPdf/Description.tsx b/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/ExportPdf/FicheActionPdf/Description.tsx index e16bedb981..78696e193b 100644 --- a/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/ExportPdf/FicheActionPdf/Description.tsx +++ b/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/ExportPdf/FicheActionPdf/Description.tsx @@ -30,7 +30,7 @@ const Description = ({ fiche }: FicheActionPdfProps) => { {sousThematiques?.map((ssThematique) => ( ))} @@ -44,7 +44,7 @@ const Description = ({ fiche }: FicheActionPdfProps) => { {/* Description */} - Description de l'action : + {"Description de l'action :"} {description || 'Non renseigné'} diff --git a/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/FicheAction/Budget/BudgetTab.tsx b/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/FicheAction/Budget/BudgetTab.tsx index cb0856b2c4..72715b880a 100644 --- a/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/FicheAction/Budget/BudgetTab.tsx +++ b/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/FicheAction/Budget/BudgetTab.tsx @@ -60,7 +60,7 @@ const BudgetTab = ({ isReadonly, fiche, updateFiche }: BudgetTabProps) => { Budget prévisionnel total : - {!!budgetPrevisionnel ? ( + {budgetPrevisionnel ? ( ) : ( diff --git a/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/FicheAction/Budget/FinanceursInput.tsx b/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/FicheAction/Budget/FinanceursInput.tsx index 81dac55098..ce58bdcc98 100644 --- a/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/FicheAction/Budget/FinanceursInput.tsx +++ b/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/FicheAction/Budget/FinanceursInput.tsx @@ -1,10 +1,12 @@ -import { Financeur } from '@/api/plan-actions'; import FinanceursDropdown from '@/app/ui/dropdownLists/FinanceursDropdown/FinanceursDropdown'; +import { Financeur, FinanceurUpdate } from '@/domain/plans/fiches'; import { Button, Field, Input } from '@/ui'; +type FinanceurPartial = Omit; + type FinanceursInputProps = { - financeurs: Financeur[] | null | undefined; - onUpdate: (financeurs: Financeur[]) => void; + financeurs: FinanceurUpdate[] | null | undefined; + onUpdate: (financeurs: FinanceurUpdate[]) => void; }; const FinanceursInput = ({ financeurs, onUpdate }: FinanceursInputProps) => { @@ -24,7 +26,7 @@ const FinanceursInput = ({ financeurs, onUpdate }: FinanceursInputProps) => { : undefined } disabled={true} - onChange={() => {}} + onChange={() => ({})} /> @@ -80,7 +82,12 @@ const FinanceursInput = ({ financeurs, onUpdate }: FinanceursInputProps) => { selectedFinanceur && onUpdate([ ...(financeurs ?? []), - { financeurTag: selectedFinanceur, montantTtc: null }, + { + financeurTag: selectedFinanceur, + financeurTagId: selectedFinanceur.id, + ficheId: financeurs?.[0].ficheId ?? 0, + montantTtc: null, + }, ]) } /> diff --git a/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/FicheAction/Budget/FinanceursListe.tsx b/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/FicheAction/Budget/FinanceursListe.tsx index 8afbfc307b..0fe915fc0a 100644 --- a/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/FicheAction/Budget/FinanceursListe.tsx +++ b/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/FicheAction/Budget/FinanceursListe.tsx @@ -1,9 +1,9 @@ -import { Financeur } from '@/api/plan-actions'; import { getFormattedNumber } from '@/app/utils/formatUtils'; +import { FinanceurUpdate } from '@/domain/plans/fiches'; import { Badge } from '@/ui'; type FinanceursListeProps = { - financeurs?: Financeur[]; + financeurs?: FinanceurUpdate[]; }; const FinanceursListe = ({ financeurs }: FinanceursListeProps) => { diff --git a/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/FicheAction/FicheActionDescription/FicheActionDescription.tsx b/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/FicheAction/FicheActionDescription/FicheActionDescription.tsx index 03772fc2f5..fb2656eac6 100644 --- a/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/FicheAction/FicheActionDescription/FicheActionDescription.tsx +++ b/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/FicheAction/FicheActionDescription/FicheActionDescription.tsx @@ -76,7 +76,7 @@ const FicheActionDescription = ({ {sousThematiques?.map((ssThematique) => ( @@ -103,7 +103,7 @@ const FicheActionDescription = ({ {/* Description de l'action */}
- Description de l'action : + {"Description de l'action :"}
{description ? ( diff --git a/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/FicheAction/FicheActionDescription/ModaleDescription.tsx b/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/FicheAction/FicheActionDescription/ModaleDescription.tsx index e5a3a2d290..564b6f781c 100644 --- a/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/FicheAction/FicheActionDescription/ModaleDescription.tsx +++ b/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/FicheAction/FicheActionDescription/ModaleDescription.tsx @@ -1,10 +1,10 @@ import { FicheAction } from '@/api/plan-actions'; -import { Thematique } from '@/api/shared/domain'; import { useCurrentCollectivite } from '@/app/core-logic/hooks/useCurrentCollectivite'; import SousThematiquesDropdown from '@/app/ui/dropdownLists/SousThematiquesDropdown/SousThematiquesDropdown'; import TagsSuiviPersoDropdown from '@/app/ui/dropdownLists/TagsSuiviPersoDropdown/TagsSuiviPersoDropdown'; import ThematiquesDropdown from '@/app/ui/dropdownLists/ThematiquesDropdown/ThematiquesDropdown'; import { getMaxLengthMessage } from '@/app/utils/formatUtils'; +import { Thematique } from '@/domain/shared'; import { Button, Field, @@ -99,7 +99,7 @@ const ModaleDescription = ({ fiche, updateFiche }: ModaleDescriptionProps) => { {/* Dropdown tags personnalisés */} t.id!)} + values={editedFiche.libresTag?.map((t) => t.id)} onChange={({ libresTag }) => setEditedFiche((prevState) => ({ ...prevState, libresTag })) } diff --git a/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/FicheAction/Header/CheminsFiche.tsx b/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/FicheAction/Header/CheminsFiche.tsx index a5abbcf53b..66122bf7db 100644 --- a/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/FicheAction/Header/CheminsFiche.tsx +++ b/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/FicheAction/Header/CheminsFiche.tsx @@ -1,5 +1,5 @@ -import { Axe } from '@/api/plan-actions'; import { makeCollectiviteFichesNonClasseesUrl } from '@/app/app/paths'; +import { Axe } from '@/domain/plans/fiches'; import { Breadcrumbs, Button } from '@/ui'; import { useRouter } from 'next/navigation'; import { useState } from 'react'; @@ -77,9 +77,10 @@ const CheminsFiche = ({ titre, collectiviteId, axes }: CheminsFicheProps) => { {isOpen && (
{otherAxes.map( - (axe) => + (axe, index) => axe.id && ( { delete newFilters.sans_niveau; return { ...newFilters, - priorites: priorites as NiveauPriorite[], + priorites: priorites as Priorite[], }; } else { delete newFilters.priorites; @@ -34,7 +34,7 @@ const FiltrePriorites = ({ filters, setFilters }: TFiltreProps) => { } else { return { ...newFilters, - priorites: priorites as NiveauPriorite[], + priorites: priorites as Priorite[], }; } }; @@ -54,7 +54,7 @@ const FiltrePriorites = ({ filters, setFilters }: TFiltreProps) => { item.value === SANS_PRIORITE ? ( Non priorisé ) : ( - + ) } disabled={options.length === 0} diff --git a/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/PlanAction/PlanActionFiltres/FiltreStatuts.tsx b/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/PlanAction/PlanActionFiltres/FiltreStatuts.tsx index a34aa2d1f1..19f36785bb 100644 --- a/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/PlanAction/PlanActionFiltres/FiltreStatuts.tsx +++ b/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/PlanAction/PlanActionFiltres/FiltreStatuts.tsx @@ -1,6 +1,6 @@ -import { Statut } from '@/api/plan-actions'; import { TFicheActionStatuts } from '@/app/types/alias'; import { TOption } from '@/app/ui/shared/select/commons'; +import { Statut } from '@/domain/plans/fiches'; import { Field, OptionValue, SelectFilter } from '@/ui'; import { ficheActionStatutOptions } from '../../../../../../ui/dropdownLists/listesStatiques'; import BadgeStatut from '../../components/BadgeStatut'; diff --git a/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/PlanAction/list/card/PlanActionCard.tsx b/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/PlanAction/list/card/PlanActionCard.tsx index 7c385eb234..c7a688665d 100644 --- a/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/PlanAction/list/card/PlanActionCard.tsx +++ b/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/PlanAction/list/card/PlanActionCard.tsx @@ -1,8 +1,8 @@ -import { Axe } from '@/api/plan-actions/domain'; import { generateTitle } from '@/app/app/pages/collectivite/PlansActions/FicheAction/data/utils'; import Statuts from '@/app/app/pages/collectivite/PlansActions/PlanAction/list/card/Statuts'; import { useFichesActionStatuts } from '@/app/app/pages/collectivite/TableauDeBord/Collectivite/ModuleAvancementFichesAction/useFichesActionStatuts'; import { ModuleDisplay } from '@/app/app/pages/collectivite/TableauDeBord/components/Module'; +import { Axe } from '@/domain/plans/fiches'; import { Card } from '@/ui'; import classNames from 'classnames'; @@ -29,7 +29,10 @@ const PlanActionCard = ({ }); const axesCount = plan.axes?.reduce( - (acc: { axe: number; sousAxe: number }, axe: Axe) => { + ( + acc: { axe: number; sousAxe: number }, + axe: NonNullable[number] + ) => { if (axe.parent === plan.id) { acc.axe++; } else if (axe.parent) { diff --git a/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/PlanAction/list/card/Statuts.tsx b/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/PlanAction/list/card/Statuts.tsx index 3f68afad5f..a5c6ba14c5 100644 --- a/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/PlanAction/list/card/Statuts.tsx +++ b/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/PlanAction/list/card/Statuts.tsx @@ -1,8 +1,8 @@ -import { Statut } from '@/api/plan-actions'; import BadgeStatut from '@/app/app/pages/collectivite/PlansActions/components/BadgeStatut'; import { statutToColor } from '@/app/app/pages/collectivite/PlansActions/FicheAction/utils'; import { ModuleDisplay } from '@/app/app/pages/collectivite/TableauDeBord/components/Module'; import Chart from '@/app/ui/charts/Chart'; +import { Statut } from '@/domain/plans/fiches'; import { Tooltip } from '@/ui'; type Props = { diff --git a/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/Synthese/utils.ts b/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/Synthese/utils.ts index b308b6222a..bbbee167f0 100644 --- a/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/Synthese/utils.ts +++ b/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/Synthese/utils.ts @@ -1,6 +1,6 @@ -import { Statut } from '@/api/plan-actions'; import { statutToColor } from '@/app/app/pages/collectivite/PlansActions/FicheAction/utils'; import { DonutData } from '@/app/ui/charts/Donut/DonutChart'; +import { Statut } from '@/domain/plans/fiches'; import { FiltersKeys } from '../FicheAction/data/filters'; import { TPlanActionTableauDeBord } from './data/usePlanActionTableauDeBord'; diff --git a/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/components/BadgeStatut.tsx b/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/components/BadgeStatut.tsx index 27f80a38bc..c573dd1f5a 100644 --- a/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/components/BadgeStatut.tsx +++ b/app.territoiresentransitions.react/src/app/pages/collectivite/PlansActions/components/BadgeStatut.tsx @@ -1,11 +1,8 @@ -import { Statut as PlanActionStatut } from '@/api/plan-actions/domain'; +import { Statut } from '@/domain/plans/fiches'; import { Badge, BadgeState } from '@/ui'; import classNames from 'classnames'; -export const statusToState: Record< - PlanActionStatut | 'Sans statut', - BadgeState -> = { +export const statusToState: Record = { 'À venir': 'standard', 'En cours': 'info', Réalisé: 'success', @@ -20,7 +17,7 @@ export const statusToState: Record< type Props = { className?: string; count?: number; - statut: PlanActionStatut | 'Sans statut'; + statut: Statut | 'Sans statut'; // Rend une version plus petite du composant size?: 'sm' | 'md'; }; diff --git a/app.territoiresentransitions.react/src/app/pages/collectivite/TableauDeBord/Collectivite/ModuleAvancementFichesAction/ModalAvancementFichesAction.tsx b/app.territoiresentransitions.react/src/app/pages/collectivite/TableauDeBord/Collectivite/ModuleAvancementFichesAction/ModalAvancementFichesAction.tsx index 98ad9e93dd..a8cfd14bbe 100644 --- a/app.territoiresentransitions.react/src/app/pages/collectivite/TableauDeBord/Collectivite/ModuleAvancementFichesAction/ModalAvancementFichesAction.tsx +++ b/app.territoiresentransitions.react/src/app/pages/collectivite/TableauDeBord/Collectivite/ModuleAvancementFichesAction/ModalAvancementFichesAction.tsx @@ -14,7 +14,6 @@ import { Filtre } from '@/api/plan-actions/dashboards/collectivite-dashboard/dom import { ModuleFicheActionCountByStatusSelect } from '@/api/plan-actions/dashboards/collectivite-dashboard/domain/module.schema'; import { ModuleDisplaySettings } from '@/app/app/pages/collectivite/TableauDeBord/components/Module'; import { supabaseClient } from '@/app/core-logic/api/supabase'; -import { TFicheActionCibles } from '@/app/types/alias'; import CiblesDropdown from '@/app/ui/dropdownLists/ficheAction/CiblesDropdown/CiblesDropdown'; import PartenairesDropdown from '@/app/ui/dropdownLists/PartenairesDropdown/PartenairesDropdown'; import PersonnesDropdown from '@/app/ui/dropdownLists/PersonnesDropdown/PersonnesDropdown'; @@ -24,6 +23,7 @@ import { } from '@/app/ui/dropdownLists/PersonnesDropdown/utils'; import PlansActionDropdown from '@/app/ui/dropdownLists/PlansActionDropdown'; import ServicesPilotesDropdown from '@/app/ui/dropdownLists/ServicesPilotesDropdown/ServicesPilotesDropdown'; +import { Cible } from '@/domain/plans/fiches'; type Props = ModalProps & { module: ModuleFicheActionCountByStatusSelect; @@ -101,7 +101,7 @@ const ModalAvancementFichesAction = ({ setFiltreState({ ...filtreState, cibles }) } diff --git a/app.territoiresentransitions.react/src/app/pages/collectivite/TableauDeBord/Collectivite/ModuleAvancementFichesAction/ModuleAvancementFichesAction.tsx b/app.territoiresentransitions.react/src/app/pages/collectivite/TableauDeBord/Collectivite/ModuleAvancementFichesAction/ModuleAvancementFichesAction.tsx index f66e6b24cc..caf4bdb667 100644 --- a/app.territoiresentransitions.react/src/app/pages/collectivite/TableauDeBord/Collectivite/ModuleAvancementFichesAction/ModuleAvancementFichesAction.tsx +++ b/app.territoiresentransitions.react/src/app/pages/collectivite/TableauDeBord/Collectivite/ModuleAvancementFichesAction/ModuleAvancementFichesAction.tsx @@ -1,4 +1,3 @@ -import { Statut } from '@/api/plan-actions'; import { ModuleFicheActionCountByStatusSelect } from '@/api/plan-actions/dashboards/collectivite-dashboard/domain/module.schema'; import BadgeStatut from '@/app/app/pages/collectivite/PlansActions/components/BadgeStatut'; import { statutToColor } from '@/app/app/pages/collectivite/PlansActions/FicheAction/utils'; @@ -13,6 +12,7 @@ import { TDBViewParam } from '@/app/app/paths'; import { useCurrentCollectivite } from '@/app/core-logic/hooks/useCurrentCollectivite'; import Chart from '@/app/ui/charts/Chart'; import PictoDocument from '@/app/ui/pictogrammes/PictoDocument'; +import { Statut } from '@/domain/plans/fiches'; import { useEventTracker } from '@/ui'; import Link from 'next/link'; import { useRouter } from 'next/navigation'; diff --git a/app.territoiresentransitions.react/src/app/pages/collectivite/TableauDeBord/Collectivite/ModuleAvancementFichesAction/utils.ts b/app.territoiresentransitions.react/src/app/pages/collectivite/TableauDeBord/Collectivite/ModuleAvancementFichesAction/utils.ts index 1d7b64ab26..3d5d314d84 100644 --- a/app.territoiresentransitions.react/src/app/pages/collectivite/TableauDeBord/Collectivite/ModuleAvancementFichesAction/utils.ts +++ b/app.territoiresentransitions.react/src/app/pages/collectivite/TableauDeBord/Collectivite/ModuleAvancementFichesAction/utils.ts @@ -1,7 +1,7 @@ -import { Statut } from '@/api/plan-actions'; import { Filtre } from '@/api/plan-actions/dashboards/collectivite-dashboard/domain/fiches-synthese.schema'; import { FicheActionParam } from '@/app/app/pages/collectivite/PlansActions/ToutesLesFichesAction/ToutesLesFichesAction'; import { makeCollectiviteToutesLesFichesUrl } from '@/app/app/paths'; +import { Statut } from '@/domain/plans/fiches'; /** Permet de transformer les filtres de modules fiches action en paramètres d'URL */ export const makeFichesActionUrlWithParams = ( diff --git a/app.territoiresentransitions.react/src/types/alias.ts b/app.territoiresentransitions.react/src/types/alias.ts index 2c949f8868..ecac91c0c6 100644 --- a/app.territoiresentransitions.react/src/types/alias.ts +++ b/app.territoiresentransitions.react/src/types/alias.ts @@ -7,7 +7,6 @@ import { TablesUpdate, Views, } from '@/api'; -import { Cible } from '@/api/plan-actions'; export type TFlatAxe = NonNullableFields>; @@ -63,8 +62,6 @@ export type TPersonne = CompositeTypes<'personne'>; export type TFinanceurMontant = CompositeTypes<'financeur_montant'>; -export type TFicheActionCibles = Cible; - export type TFicheActionNiveauxPriorite = Enums<'fiche_action_niveaux_priorite'>; export type TFicheActionPiliersECI = Enums<'fiche_action_piliers_eci'>; diff --git a/app.territoiresentransitions.react/src/ui/dropdownLists/FichesActionsDropdown/FichesActionsDropdown.tsx b/app.territoiresentransitions.react/src/ui/dropdownLists/FichesActionsDropdown/FichesActionsDropdown.tsx index 1035851b44..fb6c74b882 100644 --- a/app.territoiresentransitions.react/src/ui/dropdownLists/FichesActionsDropdown/FichesActionsDropdown.tsx +++ b/app.territoiresentransitions.react/src/ui/dropdownLists/FichesActionsDropdown/FichesActionsDropdown.tsx @@ -1,7 +1,8 @@ -import { AxeInsert, FicheResume } from '@/api/plan-actions'; +import { FicheResume } from '@/api/plan-actions'; import { useFicheResumesFetch } from '@/app/app/pages/collectivite/PlansActions/FicheAction/data/useFicheResumesFetch'; import { generateTitle } from '@/app/app/pages/collectivite/PlansActions/FicheAction/data/utils'; import { naturalSort } from '@/app/utils/naturalSort'; +import { CreateAxeType } from '@/domain/plans/fiches'; import { Option, OptionValue, @@ -56,7 +57,7 @@ const FichesActionsDropdown = ({ /* Récupère tous les plans liés aux fiches */ const plans = fichesDisponiblesListe?.reduce< - Array> + Array> >((acc, fiche) => { acc.push( fiche.plans?.[0] ?? { diff --git a/app.territoiresentransitions.react/src/ui/dropdownLists/FinanceursDropdown/FinanceursDropdown.tsx b/app.territoiresentransitions.react/src/ui/dropdownLists/FinanceursDropdown/FinanceursDropdown.tsx index 52d3a71d24..3973598590 100644 --- a/app.territoiresentransitions.react/src/ui/dropdownLists/FinanceursDropdown/FinanceursDropdown.tsx +++ b/app.territoiresentransitions.react/src/ui/dropdownLists/FinanceursDropdown/FinanceursDropdown.tsx @@ -1,4 +1,4 @@ -import { Tag } from '@/api/shared/domain'; +import { Tag } from '@/domain/collectivites'; import { SelectMultipleProps } from '@/ui'; import SelectTags from '../tags/SelectTags'; import { useFinanceursListe } from './useFinanceursListe'; diff --git a/app.territoiresentransitions.react/src/ui/dropdownLists/FinanceursDropdown/useFinanceursListe.ts b/app.territoiresentransitions.react/src/ui/dropdownLists/FinanceursDropdown/useFinanceursListe.ts index 3b906d5a62..f44b016863 100644 --- a/app.territoiresentransitions.react/src/ui/dropdownLists/FinanceursDropdown/useFinanceursListe.ts +++ b/app.territoiresentransitions.react/src/ui/dropdownLists/FinanceursDropdown/useFinanceursListe.ts @@ -1,6 +1,6 @@ -import { Tag } from '@/api/shared/domain'; import { supabaseClient } from '@/app/core-logic/api/supabase'; import { useCollectiviteId } from '@/app/core-logic/hooks/params'; +import { Tag } from '@/domain/collectivites'; import { useQuery } from 'react-query'; import { objectToCamel } from 'ts-case-convert'; diff --git a/app.territoiresentransitions.react/src/ui/dropdownLists/PartenairesDropdown/PartenairesDropdown.tsx b/app.territoiresentransitions.react/src/ui/dropdownLists/PartenairesDropdown/PartenairesDropdown.tsx index 51600ee7c6..bd9d5affb4 100644 --- a/app.territoiresentransitions.react/src/ui/dropdownLists/PartenairesDropdown/PartenairesDropdown.tsx +++ b/app.territoiresentransitions.react/src/ui/dropdownLists/PartenairesDropdown/PartenairesDropdown.tsx @@ -1,4 +1,4 @@ -import { Tag } from '@/api/shared/domain'; +import { Tag } from '@/domain/collectivites'; import { SelectMultipleProps } from '@/ui'; import SelectTags from '../tags/SelectTags'; import { usePartenairesListe } from './usePartenairesListe'; diff --git a/app.territoiresentransitions.react/src/ui/dropdownLists/PartenairesDropdown/usePartenairesListe.ts b/app.territoiresentransitions.react/src/ui/dropdownLists/PartenairesDropdown/usePartenairesListe.ts index 2ca2672bba..3dc46bf18a 100644 --- a/app.territoiresentransitions.react/src/ui/dropdownLists/PartenairesDropdown/usePartenairesListe.ts +++ b/app.territoiresentransitions.react/src/ui/dropdownLists/PartenairesDropdown/usePartenairesListe.ts @@ -1,6 +1,6 @@ -import { Tag } from '@/api/shared/domain'; import { supabaseClient } from '@/app/core-logic/api/supabase'; import { useCollectiviteId } from '@/app/core-logic/hooks/params'; +import { Tag } from '@/domain/collectivites'; import { useQuery } from 'react-query'; import { objectToCamel } from 'ts-case-convert'; diff --git a/app.territoiresentransitions.react/src/ui/dropdownLists/ServicesPilotesDropdown/ServicesPilotesDropdown.tsx b/app.territoiresentransitions.react/src/ui/dropdownLists/ServicesPilotesDropdown/ServicesPilotesDropdown.tsx index 251959dd90..1b191dcb10 100644 --- a/app.territoiresentransitions.react/src/ui/dropdownLists/ServicesPilotesDropdown/ServicesPilotesDropdown.tsx +++ b/app.territoiresentransitions.react/src/ui/dropdownLists/ServicesPilotesDropdown/ServicesPilotesDropdown.tsx @@ -1,4 +1,4 @@ -import { Tag } from '@/api/shared/domain'; +import { Tag } from '@/domain/collectivites'; import { SelectMultipleProps } from '@/ui'; import SelectTags from '../tags/SelectTags'; import { useServicesPilotesListe } from './useServicesPilotesListe'; diff --git a/app.territoiresentransitions.react/src/ui/dropdownLists/ServicesPilotesDropdown/useServicesPilotesListe.ts b/app.territoiresentransitions.react/src/ui/dropdownLists/ServicesPilotesDropdown/useServicesPilotesListe.ts index 9dc7b28ff2..6fa252c30b 100644 --- a/app.territoiresentransitions.react/src/ui/dropdownLists/ServicesPilotesDropdown/useServicesPilotesListe.ts +++ b/app.territoiresentransitions.react/src/ui/dropdownLists/ServicesPilotesDropdown/useServicesPilotesListe.ts @@ -1,6 +1,6 @@ -import { Tag } from '@/api/shared/domain'; import { supabaseClient } from '@/app/core-logic/api/supabase'; import { useCollectiviteId } from '@/app/core-logic/hooks/params'; +import { Tag } from '@/domain/collectivites'; import { useQuery } from 'react-query'; import { objectToCamel } from 'ts-case-convert'; diff --git a/app.territoiresentransitions.react/src/ui/dropdownLists/SousThematiquesDropdown/SousThematiquesDropdown.tsx b/app.territoiresentransitions.react/src/ui/dropdownLists/SousThematiquesDropdown/SousThematiquesDropdown.tsx index 1970dbe910..1319d79357 100644 --- a/app.territoiresentransitions.react/src/ui/dropdownLists/SousThematiquesDropdown/SousThematiquesDropdown.tsx +++ b/app.territoiresentransitions.react/src/ui/dropdownLists/SousThematiquesDropdown/SousThematiquesDropdown.tsx @@ -1,17 +1,17 @@ -import { SousThematiqueId } from '@/api/shared/domain'; +import { SousThematique } from '@/domain/shared'; import { Option, OptionValue, SelectFilter, SelectMultipleProps } from '@/ui'; import { useEffect } from 'react'; import { useSousThematiqueListe } from './useSousThematiqueListe'; type Props = Omit & { thematiques: number[]; - sousThematiques: SousThematiqueId[] | null | undefined; + sousThematiques: SousThematique[] | null | undefined; onChange: ({ sousThematiques, selectedSousThematique, }: { - sousThematiques: SousThematiqueId[]; - selectedSousThematique: SousThematiqueId; + sousThematiques: SousThematique[]; + selectedSousThematique: SousThematique; }) => void; }; @@ -27,7 +27,7 @@ const SousThematiquesDropdown = ({ .filter((st) => thematiques.some((t) => st.thematiqueId === t)) .map((st) => ({ value: st.id, - label: st.sousThematique, + label: st.nom, })); const getSelectedSousThematiques = (values?: OptionValue[]) => diff --git a/app.territoiresentransitions.react/src/ui/dropdownLists/SousThematiquesDropdown/useSousThematiqueListe.ts b/app.territoiresentransitions.react/src/ui/dropdownLists/SousThematiquesDropdown/useSousThematiqueListe.ts index 6de1ecaad2..cd1bdc4fe9 100644 --- a/app.territoiresentransitions.react/src/ui/dropdownLists/SousThematiquesDropdown/useSousThematiqueListe.ts +++ b/app.territoiresentransitions.react/src/ui/dropdownLists/SousThematiquesDropdown/useSousThematiqueListe.ts @@ -1,10 +1,9 @@ -import { useQuery } from 'react-query'; - -import { SousThematiqueId } from '@/api/shared/domain'; import { supabaseClient } from '@/app/core-logic/api/supabase'; +import { SousThematique } from '@/domain/shared'; +import { useQuery } from 'react-query'; import { objectToCamel } from 'ts-case-convert'; -type TFetchedData = SousThematiqueId[]; +type TFetchedData = SousThematique[]; const fetchSousThematiqueListe = async (): Promise => { const query = supabaseClient.from('sous_thematique').select(); @@ -15,7 +14,10 @@ const fetchSousThematiqueListe = async (): Promise => { throw new Error(error.message); } - return objectToCamel(data); + return objectToCamel(data).map((t) => ({ + ...t, + nom: t.sousThematique, + })); }; export const useSousThematiqueListe = () => { diff --git a/app.territoiresentransitions.react/src/ui/dropdownLists/StructuresDropdown/StructuresDropdown.tsx b/app.territoiresentransitions.react/src/ui/dropdownLists/StructuresDropdown/StructuresDropdown.tsx index c4fcdb85bf..91e42c3fe6 100644 --- a/app.territoiresentransitions.react/src/ui/dropdownLists/StructuresDropdown/StructuresDropdown.tsx +++ b/app.territoiresentransitions.react/src/ui/dropdownLists/StructuresDropdown/StructuresDropdown.tsx @@ -1,4 +1,4 @@ -import { Tag } from '@/api/shared/domain'; +import { Tag } from '@/domain/collectivites'; import { SelectMultipleProps } from '@/ui'; import SelectTags from '../tags/SelectTags'; import { useStructuresListe } from './useStructuresListe'; diff --git a/app.territoiresentransitions.react/src/ui/dropdownLists/StructuresDropdown/useStructuresListe.ts b/app.territoiresentransitions.react/src/ui/dropdownLists/StructuresDropdown/useStructuresListe.ts index 1f5e1ee58c..29bfa7df95 100644 --- a/app.territoiresentransitions.react/src/ui/dropdownLists/StructuresDropdown/useStructuresListe.ts +++ b/app.territoiresentransitions.react/src/ui/dropdownLists/StructuresDropdown/useStructuresListe.ts @@ -1,6 +1,6 @@ -import { Tag } from '@/api/shared/domain'; import { supabaseClient } from '@/app/core-logic/api/supabase'; import { useCollectiviteId } from '@/app/core-logic/hooks/params'; +import { Tag } from '@/domain/collectivites'; import { useQuery } from 'react-query'; import { objectToCamel } from 'ts-case-convert'; diff --git a/app.territoiresentransitions.react/src/ui/dropdownLists/TagsSuiviPersoDropdown/TagsSuiviPersoDropdown.tsx b/app.territoiresentransitions.react/src/ui/dropdownLists/TagsSuiviPersoDropdown/TagsSuiviPersoDropdown.tsx index 5aae47e374..b2e8752a43 100644 --- a/app.territoiresentransitions.react/src/ui/dropdownLists/TagsSuiviPersoDropdown/TagsSuiviPersoDropdown.tsx +++ b/app.territoiresentransitions.react/src/ui/dropdownLists/TagsSuiviPersoDropdown/TagsSuiviPersoDropdown.tsx @@ -1,4 +1,4 @@ -import { LibreTag } from '@/api/typeUtils'; +import { Tag } from '@/domain/collectivites'; import { SelectMultipleProps } from '@/ui'; import SelectTags from '../tags/SelectTags'; import { useTagsSuiviPersoListe } from './useTagsSuiviPersoListe'; @@ -12,8 +12,8 @@ type TagsSuiviPersoDropdownProps = Omit< libresTag, selectedLibreTag, }: { - libresTag: LibreTag[]; - selectedLibreTag: LibreTag; + libresTag: Tag[]; + selectedLibreTag: Tag; }) => void; }; diff --git a/app.territoiresentransitions.react/src/ui/dropdownLists/TagsSuiviPersoDropdown/useTagsSuiviPersoListe.ts b/app.territoiresentransitions.react/src/ui/dropdownLists/TagsSuiviPersoDropdown/useTagsSuiviPersoListe.ts index dbf0436149..3519772bd7 100644 --- a/app.territoiresentransitions.react/src/ui/dropdownLists/TagsSuiviPersoDropdown/useTagsSuiviPersoListe.ts +++ b/app.territoiresentransitions.react/src/ui/dropdownLists/TagsSuiviPersoDropdown/useTagsSuiviPersoListe.ts @@ -1,6 +1,6 @@ -import { Tag } from '@/api/shared/domain'; import { supabaseClient } from '@/app/core-logic/api/supabase'; import { useCollectiviteId } from '@/app/core-logic/hooks/params'; +import { Tag } from '@/domain/collectivites'; import { useQuery } from 'react-query'; import { objectToCamel } from 'ts-case-convert'; diff --git a/app.territoiresentransitions.react/src/ui/dropdownLists/ficheAction/CiblesDropdown/CiblesDropdown.tsx b/app.territoiresentransitions.react/src/ui/dropdownLists/ficheAction/CiblesDropdown/CiblesDropdown.tsx index 546186fa86..3d665232b8 100644 --- a/app.territoiresentransitions.react/src/ui/dropdownLists/ficheAction/CiblesDropdown/CiblesDropdown.tsx +++ b/app.territoiresentransitions.react/src/ui/dropdownLists/ficheAction/CiblesDropdown/CiblesDropdown.tsx @@ -1,4 +1,4 @@ -import { TFicheActionCibles } from '@/app/types/alias'; +import { Cible } from '@/domain/plans/fiches'; import { SelectFilter, SelectMultipleProps } from '@/ui'; import { ficheActionCiblesOptions } from '../../listesStatiques'; @@ -6,13 +6,13 @@ type CiblesDropdownProps = Omit< SelectMultipleProps, 'values' | 'onChange' | 'options' > & { - values?: TFicheActionCibles[]; + values?: Cible[]; onChange: ({ cibles, selectedCible, }: { - cibles: TFicheActionCibles[]; - selectedCible: TFicheActionCibles; + cibles: Cible[]; + selectedCible: Cible; }) => void; }; @@ -25,8 +25,8 @@ const CiblesDropdown = (props: CiblesDropdownProps) => { placeholder={props.placeholder ?? 'Sélectionnez une ou plusieurs cibles'} onChange={({ values, selectedValue }) => props.onChange({ - cibles: values as TFicheActionCibles[], - selectedCible: selectedValue as TFicheActionCibles, + cibles: values as Cible[], + selectedCible: selectedValue as Cible, }) } /> diff --git a/app.territoiresentransitions.react/src/ui/dropdownLists/ficheAction/EffetsAttendusDropdown/EffetsAttendusDropdown.tsx b/app.territoiresentransitions.react/src/ui/dropdownLists/ficheAction/EffetsAttendusDropdown/EffetsAttendusDropdown.tsx index df1f8f50cd..4b13c01ad6 100644 --- a/app.territoiresentransitions.react/src/ui/dropdownLists/ficheAction/EffetsAttendusDropdown/EffetsAttendusDropdown.tsx +++ b/app.territoiresentransitions.react/src/ui/dropdownLists/ficheAction/EffetsAttendusDropdown/EffetsAttendusDropdown.tsx @@ -1,4 +1,4 @@ -import { EffetsAttendus } from '@/api/plan-actions'; +import { EffetAttendu } from '@/domain/shared'; import { SelectFilter, SelectMultipleProps } from '@/ui'; import { useEffetsAttendus } from './useEffetsAttendus'; @@ -6,8 +6,8 @@ type EffetsAttendusDropdownProps = Omit< SelectMultipleProps, 'values' | 'onChange' | 'options' > & { - values?: EffetsAttendus[]; - onChange: ({ effets }: { effets: EffetsAttendus[] }) => void; + values?: EffetAttendu[]; + onChange: ({ effets }: { effets: EffetAttendu[] }) => void; }; const EffetsAttendusDropdown = ({ @@ -26,7 +26,7 @@ const EffetsAttendusDropdown = ({ onChange({ effets: options.filter((v) => values?.includes(v.id) - ) as EffetsAttendus[], + ) as EffetAttendu[], }) } /> diff --git a/app.territoiresentransitions.react/src/ui/dropdownLists/ficheAction/MiseEnOeuvreDropdown/MiseEnOeuvreDropdown.tsx b/app.territoiresentransitions.react/src/ui/dropdownLists/ficheAction/MiseEnOeuvreDropdown/MiseEnOeuvreDropdown.tsx index 796d03731a..3fe8a4c467 100644 --- a/app.territoiresentransitions.react/src/ui/dropdownLists/ficheAction/MiseEnOeuvreDropdown/MiseEnOeuvreDropdown.tsx +++ b/app.territoiresentransitions.react/src/ui/dropdownLists/ficheAction/MiseEnOeuvreDropdown/MiseEnOeuvreDropdown.tsx @@ -1,4 +1,4 @@ -import { TempsDeMiseEnOeuvre } from '@/api/plan-actions'; +import { TempsDeMiseEnOeuvre } from '@/domain/shared'; import { Select, SelectProps } from '@/ui'; import { useMiseEnOeuvre } from './useMiseEnOeuvre'; diff --git a/app.territoiresentransitions.react/src/ui/dropdownLists/ficheAction/ParticipationCitoyenneDropdown/ParticipationCitoyenneDropdown.tsx b/app.territoiresentransitions.react/src/ui/dropdownLists/ficheAction/ParticipationCitoyenneDropdown/ParticipationCitoyenneDropdown.tsx index 0cd15f63c2..9ddc72b70a 100644 --- a/app.territoiresentransitions.react/src/ui/dropdownLists/ficheAction/ParticipationCitoyenneDropdown/ParticipationCitoyenneDropdown.tsx +++ b/app.territoiresentransitions.react/src/ui/dropdownLists/ficheAction/ParticipationCitoyenneDropdown/ParticipationCitoyenneDropdown.tsx @@ -1,4 +1,4 @@ -import { ParticipationCitoyenne } from '@/api/plan-actions'; +import { ParticipationCitoyenne } from '@/domain/plans/fiches'; import { Select, SelectMultipleProps } from '@/ui'; import { ficheActionParticipationOptions } from '../../listesStatiques'; diff --git a/app.territoiresentransitions.react/src/ui/dropdownLists/ficheAction/priorites/PrioritesFilterDropdown.tsx b/app.territoiresentransitions.react/src/ui/dropdownLists/ficheAction/priorites/PrioritesFilterDropdown.tsx index 8ae93dc0b2..5a2a58f778 100644 --- a/app.territoiresentransitions.react/src/ui/dropdownLists/ficheAction/priorites/PrioritesFilterDropdown.tsx +++ b/app.territoiresentransitions.react/src/ui/dropdownLists/ficheAction/priorites/PrioritesFilterDropdown.tsx @@ -1,16 +1,16 @@ -import { NiveauPriorite } from '@/api/plan-actions'; import BadgePriorite from '@/app/app/pages/collectivite/PlansActions/components/BadgePriorite'; import { ficheActionNiveauPrioriteOptions } from '@/app/ui/dropdownLists/listesStatiques'; +import { Priorite } from '@/domain/plans/fiches'; import { SelectFilter, SelectMultipleProps } from '@/ui'; type Props = Omit & { - values?: NiveauPriorite[]; + values?: Priorite[]; onChange: ({ priorites, selectedPriorites, }: { - priorites: NiveauPriorite[]; - selectedPriorites: NiveauPriorite; + priorites: Priorite[]; + selectedPriorites: Priorite; }) => void; }; @@ -22,13 +22,11 @@ const PrioritesFilterDropdown = (props: Props) => { options={ficheActionNiveauPrioriteOptions} onChange={({ values, selectedValue }) => props.onChange({ - priorites: values as NiveauPriorite[], - selectedPriorites: selectedValue as NiveauPriorite, + priorites: values as Priorite[], + selectedPriorites: selectedValue as Priorite, }) } - customItem={(item) => ( - - )} + customItem={(item) => } /> ); }; diff --git a/app.territoiresentransitions.react/src/ui/dropdownLists/ficheAction/priorites/PrioritesSelectDropdown.tsx b/app.territoiresentransitions.react/src/ui/dropdownLists/ficheAction/priorites/PrioritesSelectDropdown.tsx index 802bafc00e..c46933c28e 100644 --- a/app.territoiresentransitions.react/src/ui/dropdownLists/ficheAction/priorites/PrioritesSelectDropdown.tsx +++ b/app.territoiresentransitions.react/src/ui/dropdownLists/ficheAction/priorites/PrioritesSelectDropdown.tsx @@ -1,11 +1,11 @@ -import { NiveauPriorite } from '@/api/plan-actions'; import BadgePriorite from '@/app/app/pages/collectivite/PlansActions/components/BadgePriorite'; import { ficheActionNiveauPrioriteOptions } from '@/app/ui/dropdownLists/listesStatiques'; +import { Priorite } from '@/domain/plans/fiches'; import { Select, SelectProps } from '@/ui'; type Props = Omit & { - values?: NiveauPriorite | null; - onChange: (priorite: NiveauPriorite) => void; + values?: Priorite | null; + onChange: (priorite: Priorite) => void; }; const PrioritesSelectDropdown = (props: Props) => { @@ -15,10 +15,8 @@ const PrioritesSelectDropdown = (props: Props) => { values={props.values ?? undefined} dataTest={props.dataTest ?? 'priorites'} options={ficheActionNiveauPrioriteOptions} - onChange={(priorite) => props.onChange(priorite as NiveauPriorite)} - customItem={(item) => ( - - )} + onChange={(priorite) => props.onChange(priorite as Priorite)} + customItem={(item) => } /> ); }; diff --git a/app.territoiresentransitions.react/src/ui/dropdownLists/ficheAction/statuts/StatutsFilterDropdown.tsx b/app.territoiresentransitions.react/src/ui/dropdownLists/ficheAction/statuts/StatutsFilterDropdown.tsx index 0769320b73..031ec9f23d 100644 --- a/app.territoiresentransitions.react/src/ui/dropdownLists/ficheAction/statuts/StatutsFilterDropdown.tsx +++ b/app.territoiresentransitions.react/src/ui/dropdownLists/ficheAction/statuts/StatutsFilterDropdown.tsx @@ -1,6 +1,6 @@ -import { Statut } from '@/api/plan-actions'; import BadgeStatut from '@/app/app/pages/collectivite/PlansActions/components/BadgeStatut'; import { ficheActionStatutOptions } from '@/app/ui/dropdownLists/listesStatiques'; +import { Statut } from '@/domain/plans/fiches'; import { SelectFilter, SelectMultipleProps } from '@/ui'; type Props = Omit & { diff --git a/app.territoiresentransitions.react/src/ui/dropdownLists/ficheAction/statuts/StatutsSelectDropdown.tsx b/app.territoiresentransitions.react/src/ui/dropdownLists/ficheAction/statuts/StatutsSelectDropdown.tsx index 3ae2ad9c99..cb5205c7da 100644 --- a/app.territoiresentransitions.react/src/ui/dropdownLists/ficheAction/statuts/StatutsSelectDropdown.tsx +++ b/app.territoiresentransitions.react/src/ui/dropdownLists/ficheAction/statuts/StatutsSelectDropdown.tsx @@ -1,6 +1,6 @@ -import { Statut } from '@/api/plan-actions'; import BadgeStatut from '@/app/app/pages/collectivite/PlansActions/components/BadgeStatut'; import { ficheActionStatutOptions } from '@/app/ui/dropdownLists/listesStatiques'; +import { Statut } from '@/domain/plans/fiches'; import { Select, SelectProps } from '@/ui'; type Props = Omit & { diff --git a/app.territoiresentransitions.react/src/ui/dropdownLists/indicateur/use-categorie-tags.tsx b/app.territoiresentransitions.react/src/ui/dropdownLists/indicateur/use-categorie-tags.tsx index e96b0444d9..d34bb84eda 100644 --- a/app.territoiresentransitions.react/src/ui/dropdownLists/indicateur/use-categorie-tags.tsx +++ b/app.territoiresentransitions.react/src/ui/dropdownLists/indicateur/use-categorie-tags.tsx @@ -3,8 +3,11 @@ import { useCollectiviteId } from '../../../core-logic/hooks/params'; export const useCategorieTags = () => { const collectiviteId = useCollectiviteId(); - if (!collectiviteId) return { data: null }; - return trpc.tags.categories.list.useQuery({ + if (!collectiviteId) { + return { data: null }; + } + + return trpc.collectivites.categories.list.useQuery({ collectiviteId, withPredefinedTags: true, }); diff --git a/app.territoiresentransitions.react/src/ui/dropdownLists/listesStatiques.ts b/app.territoiresentransitions.react/src/ui/dropdownLists/listesStatiques.ts index fb90d95bef..ae2082fff2 100644 --- a/app.territoiresentransitions.react/src/ui/dropdownLists/listesStatiques.ts +++ b/app.territoiresentransitions.react/src/ui/dropdownLists/listesStatiques.ts @@ -1,10 +1,11 @@ -import { ParticipationCitoyenne, Statut } from '@/api/plan-actions'; import { ModifiedSince } from '@/api/plan-actions/fiche-resumes.list/domain/fetch-options.schema'; +import { TFicheActionEcheances } from '@/app/types/alias'; import { - TFicheActionCibles, - TFicheActionEcheances, - TFicheActionNiveauxPriorite, -} from '@/app/types/alias'; + Cible, + ParticipationCitoyenne, + Priorite, + Statut, +} from '@/domain/plans/fiches'; type Options = { value: T; @@ -12,7 +13,7 @@ type Options = { disabled?: boolean; }[]; -export const ficheActionCiblesOptions: Options = [ +export const ficheActionCiblesOptions: Options = [ { value: 'Grand public', label: 'Grand public', @@ -74,12 +75,11 @@ export const ficheActionStatutOptions: Options = [ { value: 'Bloqué', label: 'Bloqué' }, ]; -export const ficheActionNiveauPrioriteOptions: Options = - [ - { value: 'Élevé', label: 'Élevé' }, - { value: 'Moyen', label: 'Moyen' }, - { value: 'Bas', label: 'Bas' }, - ]; +export const ficheActionNiveauPrioriteOptions: Options = [ + { value: 'Élevé', label: 'Élevé' }, + { value: 'Moyen', label: 'Moyen' }, + { value: 'Bas', label: 'Bas' }, +]; export const ficheActionModifiedSinceOptions: Options = [ { value: 'last-15-days', label: 'les 15 derniers jours' }, diff --git a/app.territoiresentransitions.react/src/ui/dropdownLists/tags/SelectTags.tsx b/app.territoiresentransitions.react/src/ui/dropdownLists/tags/SelectTags.tsx index 896e257f75..c3048a64ba 100644 --- a/app.territoiresentransitions.react/src/ui/dropdownLists/tags/SelectTags.tsx +++ b/app.territoiresentransitions.react/src/ui/dropdownLists/tags/SelectTags.tsx @@ -1,6 +1,6 @@ import { TableTag } from '@/api'; -import { Tag } from '@/api/shared/domain'; import { useCollectiviteId } from '@/app/core-logic/hooks/params'; +import { Tag } from '@/domain/collectivites'; import { Option, OptionValue, SelectFilter, SelectMultipleProps } from '@/ui'; import { useEffect } from 'react'; import { QueryKey } from 'react-query'; diff --git a/app.territoiresentransitions.react/src/ui/dropdownLists/tags/useTagCreate.ts b/app.territoiresentransitions.react/src/ui/dropdownLists/tags/useTagCreate.ts index b38f1237e0..b98c370ba0 100644 --- a/app.territoiresentransitions.react/src/ui/dropdownLists/tags/useTagCreate.ts +++ b/app.territoiresentransitions.react/src/ui/dropdownLists/tags/useTagCreate.ts @@ -1,6 +1,6 @@ import { CollectiviteTag, TableTag } from '@/api'; -import { TagInsert } from '@/api/shared/domain'; import { supabaseClient } from '@/app/core-logic/api/supabase'; +import { TagInsert } from '@/domain/collectivites'; import { QueryKey, useMutation, useQueryClient } from 'react-query'; import { objectToSnake } from 'ts-case-convert'; diff --git a/app.territoiresentransitions.react/src/ui/dropdownLists/tags/useTagUpdate.ts b/app.territoiresentransitions.react/src/ui/dropdownLists/tags/useTagUpdate.ts index cdb9fd7379..3f4b40a70f 100644 --- a/app.territoiresentransitions.react/src/ui/dropdownLists/tags/useTagUpdate.ts +++ b/app.territoiresentransitions.react/src/ui/dropdownLists/tags/useTagUpdate.ts @@ -1,6 +1,6 @@ import { TableTag } from '@/api'; -import { TagUpdate } from '@/api/shared/domain'; import { supabaseClient } from '@/app/core-logic/api/supabase'; +import { TagUpdate } from '@/domain/collectivites'; import { QueryKey, useMutation, useQueryClient } from 'react-query'; import { objectToSnake } from 'ts-case-convert'; diff --git a/app.territoiresentransitions.react/src/ui/export-pdf/components/Badge/BadgeStatut.tsx b/app.territoiresentransitions.react/src/ui/export-pdf/components/Badge/BadgeStatut.tsx index 7c89438f5b..a4c288703e 100644 --- a/app.territoiresentransitions.react/src/ui/export-pdf/components/Badge/BadgeStatut.tsx +++ b/app.territoiresentransitions.react/src/ui/export-pdf/components/Badge/BadgeStatut.tsx @@ -1,11 +1,11 @@ -import { Statut as PlanActionStatut } from '@/api/plan-actions/domain'; import { statusToState } from '@/app/app/pages/collectivite/PlansActions/components/BadgeStatut'; +import { Statut } from '@/domain/plans/fiches'; import classNames from 'classnames'; import { Badge } from './Badge'; type BadgeStatutProps = { count?: number; - statut: PlanActionStatut | 'Sans statut'; + statut: Statut | 'Sans statut'; size?: 'sm' | 'md'; uppercase?: boolean; className?: string; diff --git a/backend/README.md b/backend/README.md index 58be49e156..3fd452f999 100644 --- a/backend/README.md +++ b/backend/README.md @@ -46,20 +46,31 @@ $ nx test backend ### Tests -Pour lancer tous les tests : +Les tests sont colocalisés au plus près du fichier testé. + +Exemple : ``` -nx test backend +└ update-action-statut.router.ts +└ update-action-statut.router.e2e-spec.ts ``` -Pour lancer uniquement les tests unitaires (dossier `src`) : +--- -``` -nx test backend src +Lancer tous les tests : + +```sh +nx test backend ``` -Pour lancer uniquement les tests end-to-end (dossier `test`) : +Lancer uniquement un fichier de test donné : +```sh +nx test backend 'update-action-statut.router.e2e-spec.ts' ``` -nx test backend test + +Lancer uniquement les tests dont le chemin contient `referentiels` : + +```sh +nx test backend 'referentiels' ``` diff --git a/backend/src/app.module.ts b/backend/src/app.module.ts index 1721d9bf38..f45b3df0fc 100644 --- a/backend/src/app.module.ts +++ b/backend/src/app.module.ts @@ -3,17 +3,17 @@ import { ConfigModule } from '@nestjs/config'; import { SentryModule } from '@sentry/nestjs/setup'; import { AuthModule } from './auth/auth.module'; import { CollectivitesModule } from './collectivites/collectivites.module'; -import { CommonModule } from './common/common.module'; -import configuration from './config/configuration'; -import { ConfigurationModule } from './config/configuration.module'; -import { FichesActionModule } from './fiches/fiches-action.module'; import { IndicateursModule } from './indicateurs/indicateurs.module'; import { PersonnalisationsModule } from './personnalisations/personnalisations.module'; +import { FichesActionModule } from './plans/fiches/fiches.module'; import { ReferentielsModule } from './referentiels/referentiels.module'; -import { SheetModule } from './spreadsheets/sheet.module'; -import { TaxonomieModule } from './taxonomie/taxonomie.module'; -import { TrpcModule } from './trpc/trpc.module'; -import { TrpcRouter } from './trpc/trpc.router'; +import configuration from './utils/config/configuration'; +import { ConfigurationModule } from './utils/config/configuration.module'; +import { DatabaseModule } from './utils/database/database.module'; +import { SheetModule } from './utils/google-sheets/sheet.module'; +import { TrpcModule } from './utils/trpc/trpc.module'; +import { TrpcRouter } from './utils/trpc/trpc.router'; +import { UtilsModule } from './utils/utils.module'; @Module({ imports: [ @@ -24,7 +24,9 @@ import { TrpcRouter } from './trpc/trpc.router'; load: [configuration], }), ConfigurationModule, - CommonModule, + // Test without + UtilsModule, + DatabaseModule, TrpcModule, SheetModule, CollectivitesModule, @@ -33,7 +35,6 @@ import { TrpcRouter } from './trpc/trpc.router'; FichesActionModule, PersonnalisationsModule, ReferentielsModule, - TaxonomieModule, ], providers: [TrpcRouter], }) diff --git a/backend/src/auth/auth.module.ts b/backend/src/auth/auth.module.ts index 110b14009a..bfe825c7de 100644 --- a/backend/src/auth/auth.module.ts +++ b/backend/src/auth/auth.module.ts @@ -1,12 +1,10 @@ +import { PermissionService } from '@/backend/auth/authorizations/permission.service'; +import { RoleService } from '@/backend/auth/authorizations/roles/role.service'; import { Global, Module } from '@nestjs/common'; import { APP_GUARD } from '@nestjs/core'; import { JwtModule } from '@nestjs/jwt'; import { CollectivitesModule } from '../collectivites/collectivites.module'; -import { CommonModule } from '../common/common.module'; -import { ConfigurationModule } from '../config/configuration.module'; import { AuthGuard } from './guards/auth.guard'; -import { PermissionService } from '@/backend/auth/authorizations/permission.service'; -import { RoleService } from '@/backend/auth/authorizations/roles/role.service'; @Global() @Module({ @@ -15,8 +13,6 @@ import { RoleService } from '@/backend/auth/authorizations/roles/role.service'; global: true, secret: process.env.SUPABASE_JWT_SECRET, }), - ConfigurationModule, - CommonModule, CollectivitesModule, ], providers: [ @@ -25,7 +21,7 @@ import { RoleService } from '@/backend/auth/authorizations/roles/role.service'; useClass: AuthGuard, }, PermissionService, - RoleService + RoleService, ], exports: [PermissionService], }) diff --git a/backend/src/auth/authorizations/permission.models.ts b/backend/src/auth/authorizations/permission.models.ts index 4558387b68..2145c887c0 100644 --- a/backend/src/auth/authorizations/permission.models.ts +++ b/backend/src/auth/authorizations/permission.models.ts @@ -1,9 +1,13 @@ -import { Role } from '@/backend/auth/authorizations/roles/role.enum'; -import { PermissionOperation } from '@/backend/auth/authorizations/permission-operation.enum'; +import { PermissionOperation } from './permission-operation.enum'; +import { Role } from './roles/role.enum'; export const Permission: Record = { [Role.CONNECTE]: [], - [Role.VERIFIE]: [PermissionOperation.COLLECTIVITES_VISITE, PermissionOperation.PLANS_FICHES_VISITE, PermissionOperation.INDICATEURS_VISITE], + [Role.VERIFIE]: [ + PermissionOperation.COLLECTIVITES_VISITE, + PermissionOperation.PLANS_FICHES_VISITE, + PermissionOperation.INDICATEURS_VISITE, + ], [Role.SUPPORT]: [ PermissionOperation.COLLECTIVITES_VISITE, PermissionOperation.COLLECTIVITES_LECTURE, diff --git a/backend/src/auth/authorizations/permission.service.e2e-spec.ts b/backend/src/auth/authorizations/permission.service.e2e-spec.ts index e9276db8d8..b470c89093 100644 --- a/backend/src/auth/authorizations/permission.service.e2e-spec.ts +++ b/backend/src/auth/authorizations/permission.service.e2e-spec.ts @@ -1,15 +1,20 @@ -import { getAuthUser, getTestApp, getTestDatabase, YOULOU_DOUDOU } from '@/backend/test'; -import { INestApplication } from '@nestjs/common'; -import { PermissionService } from '@/backend/auth/authorizations/permission.service'; -import { AuthenticatedUser } from '@/backend/auth/models/auth.models'; +import { dcpTable } from '@/backend/auth'; import { PermissionOperation } from '@/backend/auth/authorizations/permission-operation.enum'; +import { PermissionService } from '@/backend/auth/authorizations/permission.service'; import { ResourceType } from '@/backend/auth/authorizations/resource-type.enum'; -import DatabaseService from '../../common/services/database.service'; -import { eq } from 'drizzle-orm'; import { utilisateurSupportTable } from '@/backend/auth/authorizations/roles/utilisateur-support.table'; import { utilisateurVerifieTable } from '@/backend/auth/authorizations/roles/utilisateur-verifie.table'; -import { dcpTable } from '@/backend/auth'; -import { collectiviteTable } from '@/backend/collectivites/models/collectivite.table'; +import { AuthenticatedUser } from '@/backend/auth/models/auth.models'; +import { collectiviteTable } from '@/backend/collectivites'; +import { + getAuthUser, + getTestApp, + getTestDatabase, + YOULOU_DOUDOU, +} from '@/backend/test'; +import { DatabaseService } from '@/backend/utils'; +import { INestApplication } from '@nestjs/common'; +import { eq } from 'drizzle-orm'; describe('Gestion des droits', () => { let app: INestApplication; @@ -22,7 +27,7 @@ describe('Gestion des droits', () => { app = await getTestApp(); permissionService = app.get(PermissionService); yoloDodoUser = await getAuthUser(); - youlouDoudouUser = await getAuthUser(YOULOU_DOUDOU) + youlouDoudouUser = await getAuthUser(YOULOU_DOUDOU); databaseService = await getTestDatabase(app); }); diff --git a/backend/src/auth/authorizations/roles/private-utilisateur-droit.table.ts b/backend/src/auth/authorizations/roles/private-utilisateur-droit.table.ts index f15b247579..e06ce601f5 100644 --- a/backend/src/auth/authorizations/roles/private-utilisateur-droit.table.ts +++ b/backend/src/auth/authorizations/roles/private-utilisateur-droit.table.ts @@ -1,9 +1,9 @@ +import { createdAt, modifiedAt } from '@/domain/utils'; import { InferSelectModel } from 'drizzle-orm'; import { boolean, integer, pgTable, serial, uuid } from 'drizzle-orm/pg-core'; -import { collectiviteTable } from '../../../collectivites/models/collectivite.table'; +import { collectiviteTable } from '../../../collectivites/shared/models/collectivite.table'; +import { invitationTable } from '../../models/invitation.table'; import { NiveauAcces, niveauAccessEnum } from './niveau-acces.enum'; -import { createdAt, modifiedAt } from '@/backend/utils'; -import { invitationTable } from '@/backend/auth/models/invitation.table'; export const utilisateurDroitTable = pgTable('private_utilisateur_droit', { id: serial('id').primaryKey(), diff --git a/backend/src/auth/authorizations/roles/role.service.ts b/backend/src/auth/authorizations/roles/role.service.ts index 9d68fbb712..a445a362a0 100644 --- a/backend/src/auth/authorizations/roles/role.service.ts +++ b/backend/src/auth/authorizations/roles/role.service.ts @@ -1,18 +1,17 @@ -import { Injectable, Logger } from '@nestjs/common'; -import { and, eq, sql } from 'drizzle-orm'; -import DatabaseService from '../../../common/services/database.service'; -import { AuthRole, AuthUser } from '../../models/auth.models'; import { + dcpTable, utilisateurDroitTable, UtilisateurDroitType, } from '@/backend/auth'; +import { ResourceType } from '@/backend/auth/authorizations/resource-type.enum'; +import { Role } from '@/backend/auth/authorizations/roles/role.enum'; +import { DatabaseService } from '@/backend/utils'; +import { Injectable, Logger } from '@nestjs/common'; +import { and, eq, sql } from 'drizzle-orm'; +import { AuthRole, AuthUser } from '../../models/auth.models'; import { NiveauAcces } from './niveau-acces.enum'; import { utilisateurSupportTable } from './utilisateur-support.table'; import { utilisateurVerifieTable } from './utilisateur-verifie.table'; -import { ResourceType } from '@/backend/auth/authorizations/resource-type.enum'; -import { Role } from '@/backend/auth/authorizations/roles/role.enum'; -import { dcpTable } from '@/backend/auth'; - @Injectable() export class RoleService { diff --git a/backend/src/auth/authorizations/roles/utilisateur-support.table.ts b/backend/src/auth/authorizations/roles/utilisateur-support.table.ts index 9a4cca0e2a..72986bcbe6 100644 --- a/backend/src/auth/authorizations/roles/utilisateur-support.table.ts +++ b/backend/src/auth/authorizations/roles/utilisateur-support.table.ts @@ -1,5 +1,5 @@ +import { dcpTable } from '@/domain/auth'; import { boolean, pgTable, uuid } from 'drizzle-orm/pg-core'; -import { dcpTable } from '@/backend/auth'; export const utilisateurSupportTable = pgTable('utilisateur_support', { userId: uuid('user_id') diff --git a/backend/src/auth/authorizations/roles/utilisateur-verifie.table.ts b/backend/src/auth/authorizations/roles/utilisateur-verifie.table.ts index f9f13170dc..f3d32453ae 100644 --- a/backend/src/auth/authorizations/roles/utilisateur-verifie.table.ts +++ b/backend/src/auth/authorizations/roles/utilisateur-verifie.table.ts @@ -1,5 +1,5 @@ +import { dcpTable } from '@/domain/auth'; import { boolean, pgTable, uuid } from 'drizzle-orm/pg-core'; -import { dcpTable } from '@/backend/auth'; export const utilisateurVerifieTable = pgTable('utilisateur_verifie', { userId: uuid('user_id') diff --git a/backend/src/auth/guards/auth.guard.ts b/backend/src/auth/guards/auth.guard.ts index 3ae9e9d25f..8141eea06b 100644 --- a/backend/src/auth/guards/auth.guard.ts +++ b/backend/src/auth/guards/auth.guard.ts @@ -8,8 +8,8 @@ import { import { Reflector } from '@nestjs/core'; import { JwtService } from '@nestjs/jwt'; import { Request } from 'express'; -import { getErrorMessage } from '../../common/services/errors.helper'; -import BackendConfigurationService from '../../config/configuration.service'; +import BackendConfigurationService from '../../utils/config/configuration.service'; +import { getErrorMessage } from '../../utils/nest/errors.utils'; import { AllowAnonymousAccess } from '../decorators/allow-anonymous-access.decorator'; import { AllowPublicAccess } from '../decorators/allow-public-access.decorator'; import { diff --git a/backend/src/auth/index-domain.ts b/backend/src/auth/index-domain.ts new file mode 100644 index 0000000000..9629ef3391 --- /dev/null +++ b/backend/src/auth/index-domain.ts @@ -0,0 +1,11 @@ +// `index-domain.ts` file must only contain exports that are shareable with client-side apps. +// Exports from this file can be imported with `@/domain/*` alias path. + +export * from './authorizations/permission-operation.enum'; +export * from './authorizations/permission.models'; +export * from './authorizations/resource-type.enum'; +export * from './authorizations/roles/private-utilisateur-droit.table'; +export * from './models/auth-users.table'; +export * from './models/auth.models'; +export * from './models/dcp.table'; +export * from './models/invitation.table'; diff --git a/backend/src/auth/index.ts b/backend/src/auth/index.ts index d570b38f15..81ce45f809 100644 --- a/backend/src/auth/index.ts +++ b/backend/src/auth/index.ts @@ -1,2 +1 @@ -export * from './models/dcp.table'; -export * from '@/backend/auth/authorizations/roles/private-utilisateur-droit.table'; +export * from './index-domain'; diff --git a/backend/src/auth/models/dcp.table.ts b/backend/src/auth/models/dcp.table.ts index 5e91520e41..14df13b45b 100644 --- a/backend/src/auth/models/dcp.table.ts +++ b/backend/src/auth/models/dcp.table.ts @@ -6,6 +6,7 @@ import { uuid, varchar, } from 'drizzle-orm/pg-core'; +import { createSelectSchema } from 'drizzle-zod'; import { createdAt, modifiedAt } from '../../utils/column.utils'; export const dcpTable = pgTable('dcp', { @@ -23,3 +24,12 @@ export const dcpTable = pgTable('dcp', { mode: 'string', }), }); + +export const dcpSchema = createSelectSchema(dcpTable); + +export const authorSchema = dcpSchema.pick({ + userId: true, + nom: true, + prenom: true, + email: true, +}); diff --git a/backend/src/auth/models/invitation.table.ts b/backend/src/auth/models/invitation.table.ts index 6110bc2631..9a597c7cef 100644 --- a/backend/src/auth/models/invitation.table.ts +++ b/backend/src/auth/models/invitation.table.ts @@ -7,13 +7,13 @@ import { timestamp, uuid, } from 'drizzle-orm/pg-core'; -import { collectiviteTable } from '../../collectivites/models/collectivite.table'; +import { collectiviteTable } from '../../collectivites/shared/models/collectivite.table'; import { createdAt, createdBy, TIMESTAMP_OPTIONS, } from '../../utils/column.utils'; -import { niveauAccessEnum } from '@/backend/auth/authorizations/roles/niveau-acces.enum'; +import { niveauAccessEnum } from '../authorizations/roles/niveau-acces.enum'; export const utilisateurSchema = pgSchema('utilisateur'); diff --git a/backend/src/collectivites/controllers/collectivite.controller.ts b/backend/src/collectivites/collectivite.controller.ts similarity index 85% rename from backend/src/collectivites/controllers/collectivite.controller.ts rename to backend/src/collectivites/collectivite.controller.ts index 4b16cd5e30..08728510ba 100644 --- a/backend/src/collectivites/controllers/collectivite.controller.ts +++ b/backend/src/collectivites/collectivite.controller.ts @@ -1,7 +1,7 @@ import { Controller, Get, Param, Query } from '@nestjs/common'; import { ApiOkResponse } from '@nestjs/swagger'; -import { AllowPublicAccess } from '../../auth/decorators/allow-public-access.decorator'; -import CollectivitesService from '../services/collectivites.service'; +import { AllowPublicAccess } from '../auth/decorators/allow-public-access.decorator'; +import CollectivitesService from './services/collectivites.service'; /** * Création des classes de réponse à partir du schema pour générer automatiquement la documentation OpenAPI diff --git a/backend/src/collectivites/models/collectivite.request.ts b/backend/src/collectivites/collectivite.request.ts similarity index 100% rename from backend/src/collectivites/models/collectivite.request.ts rename to backend/src/collectivites/collectivite.request.ts diff --git a/backend/src/collectivites/collectivites.module.ts b/backend/src/collectivites/collectivites.module.ts index b541bc7b9f..10223c180b 100644 --- a/backend/src/collectivites/collectivites.module.ts +++ b/backend/src/collectivites/collectivites.module.ts @@ -1,15 +1,16 @@ import { Module } from '@nestjs/common'; -import { CommonModule } from '../common/common.module'; -import { CollectiviteController } from './controllers/collectivite.controller'; +import { CollectiviteController } from './collectivite.controller'; +import { ListCategoriesRouter } from './handle-categories/list-categories.router'; +import ListCategoriesService from './handle-categories/list-categories.service'; +import { CollectiviteMembresRouter } from './membres/membres.router'; +import { CollectiviteMembresService } from './membres/membres.service'; import { PersonnesRouter } from './personnes.router'; import CollectivitesService from './services/collectivites.service'; import GroupementsService from './services/groupements.service'; import { PersonnesService } from './services/personnes.service'; -import { CollectiviteMembresService } from './membres/membres.service'; -import { CollectiviteMembresRouter } from './membres/membres.router'; @Module({ - imports: [CommonModule], + imports: [], providers: [ CollectivitesService, CollectiviteMembresService, @@ -17,6 +18,8 @@ import { CollectiviteMembresRouter } from './membres/membres.router'; GroupementsService, PersonnesService, PersonnesRouter, + ListCategoriesService, + ListCategoriesRouter, ], exports: [ CollectivitesService, @@ -24,6 +27,8 @@ import { CollectiviteMembresRouter } from './membres/membres.router'; CollectiviteMembresRouter, GroupementsService, PersonnesRouter, + ListCategoriesService, + ListCategoriesRouter, ], controllers: [CollectiviteController], }) diff --git a/backend/src/taxonomie/routers/get-categories-by-collectivite.router.e2e-spec.ts b/backend/src/collectivites/handle-categories/list-categories.router.e2e-spec.ts similarity index 75% rename from backend/src/taxonomie/routers/get-categories-by-collectivite.router.e2e-spec.ts rename to backend/src/collectivites/handle-categories/list-categories.router.e2e-spec.ts index cca62c5e05..bcb1e293e0 100644 --- a/backend/src/taxonomie/routers/get-categories-by-collectivite.router.e2e-spec.ts +++ b/backend/src/collectivites/handle-categories/list-categories.router.e2e-spec.ts @@ -1,10 +1,12 @@ import { inferProcedureInput } from '@trpc/server'; import { getTestRouter } from '../../../test/app-utils'; import { getAuthUser } from '../../../test/auth-utils'; -import { AppRouter, TrpcRouter } from '../../trpc/trpc.router'; -import { AuthenticatedUser } from './../../auth/models/auth.models'; +import { AuthenticatedUser } from '../../auth/models/auth.models'; +import { AppRouter, TrpcRouter } from '../../utils/trpc/trpc.router'; -type Input = inferProcedureInput; +type Input = inferProcedureInput< + AppRouter['collectivites']['categories']['list'] +>; describe('Route de lecture des tags catégories', () => { let router: TrpcRouter; @@ -22,7 +24,7 @@ describe('Route de lecture des tags catégories', () => { collectiviteId: 1, withPredefinedTags: false, }; - const result = await caller.tags.categories.list(input); + const result = await caller.collectivites.categories.list(input); // Il n'y a pas de catégories propres à une collectivité dans le jeu de test expect(result.length).toBe(0); }); @@ -34,7 +36,7 @@ describe('Route de lecture des tags catégories', () => { collectiviteId: 1, withPredefinedTags: true, }; - const result = await caller.tags.categories.list(input); + const result = await caller.collectivites.categories.list(input); expect(result.length).not.toBe(0); }); }); diff --git a/backend/src/taxonomie/routers/get-categories-by-collectivite.router.ts b/backend/src/collectivites/handle-categories/list-categories.router.ts similarity index 51% rename from backend/src/taxonomie/routers/get-categories-by-collectivite.router.ts rename to backend/src/collectivites/handle-categories/list-categories.router.ts index c6ec369887..bbd85d5c36 100644 --- a/backend/src/taxonomie/routers/get-categories-by-collectivite.router.ts +++ b/backend/src/collectivites/handle-categories/list-categories.router.ts @@ -1,18 +1,18 @@ +import { TrpcService } from '@/backend/utils/trpc/trpc.service'; import { Injectable } from '@nestjs/common'; import { z } from 'zod'; -import TagService from '../services/tag.service'; -import { TrpcService } from '../../trpc/trpc.service'; +import ListCategoriesService from './list-categories.service'; const inputSchema = z.object({ collectiviteId: z.number(), - withPredefinedTags : z.boolean().default(true) + withPredefinedTags: z.boolean().default(true), }); @Injectable() -export class GetCategoriesByCollectiviteRouter { +export class ListCategoriesRouter { constructor( private readonly trpc: TrpcService, - private readonly service: TagService + private readonly service: ListCategoriesService ) {} router = this.trpc.router({ @@ -20,7 +20,11 @@ export class GetCategoriesByCollectiviteRouter { .input(inputSchema) .query(({ ctx, input }) => { const { collectiviteId, withPredefinedTags } = input; - return this.service.getCategoriesByCollectivite(collectiviteId, withPredefinedTags, ctx.user); + return this.service.listCategories( + collectiviteId, + withPredefinedTags, + ctx.user + ); }), }); } diff --git a/backend/src/taxonomie/services/tag.service.ts b/backend/src/collectivites/handle-categories/list-categories.service.ts similarity index 53% rename from backend/src/taxonomie/services/tag.service.ts rename to backend/src/collectivites/handle-categories/list-categories.service.ts index 7aa3577538..29a2c29387 100644 --- a/backend/src/taxonomie/services/tag.service.ts +++ b/backend/src/collectivites/handle-categories/list-categories.service.ts @@ -1,19 +1,18 @@ -import { Injectable, Logger } from '@nestjs/common'; -import { and, eq, or, isNull, inArray } from 'drizzle-orm'; -import DatabaseService from '../../common/services/database.service'; -import { partenaireTagTable } from '../models/partenaire-tag.table'; -import { categorieTagTable } from '../models/categorie-tag.table'; -import { groupementCollectiviteTable } from '../../collectivites/models/groupement-collectivite.table'; -import { TagType } from '../models/tag.table-base'; -import { AuthenticatedUser } from '../../auth/models/auth.models'; import { PermissionOperation } from '@/backend/auth/authorizations/permission-operation.enum'; -import { ResourceType } from '@/backend/auth/authorizations/resource-type.enum'; -import CollectivitesService from '../../collectivites/services/collectivites.service'; import { PermissionService } from '@/backend/auth/authorizations/permission.service'; +import { ResourceType } from '@/backend/auth/authorizations/resource-type.enum'; +import CollectivitesService from '@/backend/collectivites/services/collectivites.service'; +import { Injectable, Logger } from '@nestjs/common'; +import { and, eq, inArray, isNull, or } from 'drizzle-orm'; +import { AuthenticatedUser } from '../../auth/models/auth.models'; +import { DatabaseService } from '../../utils/database/database.service'; +import { categorieTagTable } from '../shared/models/categorie-tag.table'; +import { groupementCollectiviteTable } from '../shared/models/groupement-collectivite.table'; +import { Tag } from '../shared/models/tag.table-base'; @Injectable() -export default class TagService { - private readonly logger = new Logger(TagService.name); +export default class ListCategoriesService { + private readonly logger = new Logger(ListCategoriesService.name); constructor( private readonly databaseService: DatabaseService, @@ -21,51 +20,17 @@ export default class TagService { private readonly collectiviteService: CollectivitesService ) {} - /** - * TODO à factoriser avec les autres tags - * Récupère l'id du tag partenaire pour une collectivité et le crée s'il n'existe pas - * @param nom du partenaire - * @param collectiviteId identifiant de la collectivité - * @return identifiant du tag partenaire - */ - async getPartenaireId(nom: string, collectiviteId: number): Promise { - let tag = null; - if (collectiviteId) { - const tags = await this.databaseService.db - .select() - .from(partenaireTagTable) - .where( - and( - eq(partenaireTagTable.nom, nom.trim()), - eq(partenaireTagTable.collectiviteId, collectiviteId) - ) - ); - tag = tags.length > 0 ? tags[0] : null; - } - if (!tag) { - const toReturn = await this.databaseService.db - .insert(partenaireTagTable) - .values({ - collectiviteId: collectiviteId, - nom: nom, - }) - .returning(); - return toReturn[0]?.id; - } - return tag.id; - } - /** * Récupère les catégories possibles pour une collectivité * @param collectiviteId * @param withPredefinedTags vrai pour inclure les tags prédéfinis par TeT * @param tokenInfo */ - async getCategoriesByCollectivite( + async listCategories( collectiviteId: number, withPredefinedTags: boolean, tokenInfo: AuthenticatedUser - ): Promise { + ): Promise { // Vérifie les droits const collectivitePrivate = await this.collectiviteService.isPrivate( collectiviteId @@ -97,11 +62,11 @@ export default class TagService { .from(categorieTagTable) .where( withPredefinedTags - // Récupère les catégories - // - propres à la collectivité - // - propres aux groupements de la collectivité - // - prédéfinies visibles par TeT - ? and( + ? // Récupère les catégories + // - propres à la collectivité + // - propres aux groupements de la collectivité + // - prédéfinies visibles par TeT + and( or( and( isNull(categorieTagTable.collectiviteId), @@ -112,8 +77,8 @@ export default class TagService { ), eq(categorieTagTable.visible, true) ) - // Récupère seulement les catégories propres à la collectivité - : eq(categorieTagTable.collectiviteId, collectiviteId) + : // Récupère seulement les catégories propres à la collectivité + eq(categorieTagTable.collectiviteId, collectiviteId) ); } } diff --git a/backend/src/collectivites/models/identite-collectivite.dto.ts b/backend/src/collectivites/identite-collectivite.dto.ts similarity index 90% rename from backend/src/collectivites/models/identite-collectivite.dto.ts rename to backend/src/collectivites/identite-collectivite.dto.ts index 3803e423d3..6d82b0ec58 100644 --- a/backend/src/collectivites/models/identite-collectivite.dto.ts +++ b/backend/src/collectivites/identite-collectivite.dto.ts @@ -1,8 +1,8 @@ import { pgEnum } from 'drizzle-orm/pg-core'; import { z } from 'zod'; -import { collectiviteSchema } from './collectivite.table'; -import { communeSchema } from './commune.table'; -import { epciSchema } from './epci.table'; +import { collectiviteSchema } from './shared/models/collectivite.table'; +import { communeSchema } from './shared/models/commune.table'; +import { epciSchema } from './shared/models/epci.table'; export enum CollectiviteTypeEnum { EPCI = 'EPCI', diff --git a/backend/src/collectivites/index-domain.ts b/backend/src/collectivites/index-domain.ts new file mode 100644 index 0000000000..e89c558080 --- /dev/null +++ b/backend/src/collectivites/index-domain.ts @@ -0,0 +1,12 @@ +// `index-domain.ts` file must only contain exports that are shareable with client-side apps. +// Exports from this file can be imported with `@/domain/*` alias path. + +export * from './shared/models/categorie-tag.table'; +export * from './shared/models/collectivite.table'; +export * from './shared/models/financeur-tag.table'; +export * from './shared/models/libre-tag.table'; +export * from './shared/models/partenaire-tag.table'; +export * from './shared/models/personne-tag.table'; +export * from './shared/models/service-tag.table'; +export * from './shared/models/structure-tag.table'; +export * from './shared/models/tag.table-base'; diff --git a/backend/src/collectivites/index.ts b/backend/src/collectivites/index.ts new file mode 100644 index 0000000000..81ce45f809 --- /dev/null +++ b/backend/src/collectivites/index.ts @@ -0,0 +1 @@ +export * from './index-domain'; diff --git a/backend/src/collectivites/membres/membres.router.e2e-spec.ts b/backend/src/collectivites/membres/membres.router.e2e-spec.ts index 3e61b3ac03..093f2a0048 100644 --- a/backend/src/collectivites/membres/membres.router.e2e-spec.ts +++ b/backend/src/collectivites/membres/membres.router.e2e-spec.ts @@ -1,3 +1,4 @@ +import { NiveauAcces } from '@/backend/auth/authorizations/roles/niveau-acces.enum'; import { INestApplication } from '@nestjs/common'; import { inferProcedureInput } from '@trpc/server'; import { sql } from 'drizzle-orm'; @@ -6,10 +7,9 @@ import { getAuthUser } from '../../../test/auth-utils'; import { YOLO_DODO } from '../../../test/test-users.samples'; import { AuthenticatedUser } from '../../auth/models/auth.models'; import { invitationTable } from '../../auth/models/invitation.table'; -import { NiveauAcces } from '@/backend/auth/authorizations/roles/niveau-acces.enum'; -import DatabaseService from '../../common/services/database.service'; -import { AppRouter, TrpcRouter } from '../../trpc/trpc.router'; -import { MembreFonctionEnum } from '../models/membre-fonction.enum'; +import { DatabaseService } from '../../utils/database/database.service'; +import { AppRouter, TrpcRouter } from '../../utils/trpc/trpc.router'; +import { MembreFonctionEnum } from '../shared/models/membre-fonction.enum'; type Input = inferProcedureInput; diff --git a/backend/src/collectivites/membres/membres.router.ts b/backend/src/collectivites/membres/membres.router.ts index 21e57266d3..91a9095c57 100644 --- a/backend/src/collectivites/membres/membres.router.ts +++ b/backend/src/collectivites/membres/membres.router.ts @@ -1,5 +1,5 @@ +import { TrpcService } from '@/backend/utils/trpc/trpc.service'; import { Injectable } from '@nestjs/common'; -import { TrpcService } from '../../trpc/trpc.service'; import { CollectiviteMembresService } from './membres.service'; @Injectable() diff --git a/backend/src/collectivites/membres/membres.service.ts b/backend/src/collectivites/membres/membres.service.ts index 599227fd39..b761cef753 100644 --- a/backend/src/collectivites/membres/membres.service.ts +++ b/backend/src/collectivites/membres/membres.service.ts @@ -1,13 +1,13 @@ import { dcpTable } from '@/backend/auth'; +import { utilisateurDroitTable } from '@/backend/auth/authorizations/roles/private-utilisateur-droit.table'; import { Injectable, Logger } from '@nestjs/common'; import { and, eq, sql } from 'drizzle-orm'; import { unionAll } from 'drizzle-orm/pg-core'; import z from 'zod'; import { invitationTable } from '../../auth/models/invitation.table'; -import { utilisateurDroitTable } from '@/backend/auth/authorizations/roles/private-utilisateur-droit.table'; -import DatabaseService from '../../common/services/database.service'; -import { MembreFonction } from '../models/membre-fonction.enum'; -import { insertMembreSchema, membreTable } from '../models/membre.table'; +import { DatabaseService } from '../../utils/database/database.service'; +import { MembreFonction } from '../shared/models/membre-fonction.enum'; +import { insertMembreSchema, membreTable } from '../shared/models/membre.table'; @Injectable() export class CollectiviteMembresService { diff --git a/backend/src/collectivites/personnes.router.e2e-spec.ts b/backend/src/collectivites/personnes.router.e2e-spec.ts index 9830d38603..a3354d6a37 100644 --- a/backend/src/collectivites/personnes.router.e2e-spec.ts +++ b/backend/src/collectivites/personnes.router.e2e-spec.ts @@ -1,3 +1,4 @@ +import { utilisateurDroitTable } from '@/backend/auth/authorizations/roles/private-utilisateur-droit.table'; import { inferProcedureInput } from '@trpc/server'; import { eq } from 'drizzle-orm'; import { @@ -8,9 +9,8 @@ import { import { getAuthUser } from '../../test/auth-utils'; import { YOLO_DODO, YULU_DUDU } from '../../test/test-users.samples'; import { AuthenticatedUser } from '../auth/models/auth.models'; -import { utilisateurDroitTable } from '@/backend/auth/authorizations/roles/private-utilisateur-droit.table'; -import DatabaseService from '../common/services/database.service'; -import { AppRouter, TrpcRouter } from '../trpc/trpc.router'; +import { DatabaseService } from '../utils/database/database.service'; +import { AppRouter, TrpcRouter } from '../utils/trpc/trpc.router'; type ListRequest = inferProcedureInput< AppRouter['collectivites']['personnes']['list'] diff --git a/backend/src/collectivites/personnes.router.ts b/backend/src/collectivites/personnes.router.ts index 3718b9dc10..995aeddc54 100644 --- a/backend/src/collectivites/personnes.router.ts +++ b/backend/src/collectivites/personnes.router.ts @@ -1,14 +1,14 @@ +import { PermissionOperation } from '@/backend/auth/authorizations/permission-operation.enum'; +import { PermissionService } from '@/backend/auth/authorizations/permission.service'; +import { ResourceType } from '@/backend/auth/authorizations/resource-type.enum'; import { Injectable } from '@nestjs/common'; import { TRPCError } from '@trpc/server'; -import { TrpcService } from '../trpc/trpc.service'; +import CollectivitesService from '../collectivites/services/collectivites.service'; +import { TrpcService } from '../utils/trpc/trpc.service'; import { listRequestSchema, PersonnesService, } from './services/personnes.service'; -import { PermissionService } from '@/backend/auth/authorizations/permission.service'; -import { PermissionOperation } from '@/backend/auth/authorizations/permission-operation.enum'; -import { ResourceType } from '@/backend/auth/authorizations/resource-type.enum'; -import CollectivitesService from '../collectivites/services/collectivites.service'; const inputSchema = listRequestSchema; diff --git a/backend/src/collectivites/services/collectivites.service.ts b/backend/src/collectivites/services/collectivites.service.ts index 01f5f13bca..35220cefd8 100644 --- a/backend/src/collectivites/services/collectivites.service.ts +++ b/backend/src/collectivites/services/collectivites.service.ts @@ -1,20 +1,20 @@ import { Injectable, Logger, NotFoundException } from '@nestjs/common'; import { aliasedTable, eq, or } from 'drizzle-orm'; import { isNil } from 'es-toolkit'; -import DatabaseService from '../../common/services/database.service'; -import { collectiviteTestTable } from '../models/collectivite-test.table'; -import { collectiviteTable } from '../models/collectivite.table'; -import { communeTable, CommuneType } from '../models/commune.table'; -import { epciTable, EpciType } from '../models/epci.table'; +import { DatabaseService } from '../../utils/database/database.service'; import { CollectiviteAvecType, CollectivitePopulationTypeEnum, CollectiviteSousTypeEnum, CollectiviteTypeEnum, -} from '../models/identite-collectivite.dto'; -import { banaticTable } from '../models/imports-banatic.table'; -import { importCommuneTable } from '../models/imports-commune.table'; -import { regionTable } from '../models/imports-region.table'; +} from '../identite-collectivite.dto'; +import { collectiviteTestTable } from '../shared/models/collectivite-test.table'; +import { collectiviteTable } from '../shared/models/collectivite.table'; +import { communeTable, CommuneType } from '../shared/models/commune.table'; +import { epciTable, EpciType } from '../shared/models/epci.table'; +import { banaticTable } from '../shared/models/imports-banatic.table'; +import { importCommuneTable } from '../shared/models/imports-commune.table'; +import { regionTable } from '../shared/models/imports-region.table'; @Injectable() export default class CollectivitesService { @@ -199,10 +199,8 @@ export default class CollectivitesService { return epciBySirenResult[0]; } - async isPrivate(collectiviteId : number) : Promise{ - const collectivite = await this.getCollectivite( - collectiviteId - ); + async isPrivate(collectiviteId: number): Promise { + const collectivite = await this.getCollectivite(collectiviteId); return collectivite.collectivite.accessRestreint || false; } } diff --git a/backend/src/collectivites/services/groupements.service.ts b/backend/src/collectivites/services/groupements.service.ts index 2a51797fd1..73297b124a 100644 --- a/backend/src/collectivites/services/groupements.service.ts +++ b/backend/src/collectivites/services/groupements.service.ts @@ -6,12 +6,12 @@ import { NotFoundException, } from '@nestjs/common'; import { eq } from 'drizzle-orm'; -import DatabaseService from '../../common/services/database.service'; -import { groupementTable } from '../models/groupement.table'; +import { DatabaseService } from '../../utils/database/database.service'; import { CreateGroupementCollectiviteType, groupementCollectiviteTable, -} from '../models/groupement-collectivite.table'; +} from '../shared/models/groupement-collectivite.table'; +import { groupementTable } from '../shared/models/groupement.table'; @Injectable() export default class GroupementsService { diff --git a/backend/src/collectivites/services/personnes.service.ts b/backend/src/collectivites/services/personnes.service.ts index f1dce87719..b2ccdbebf1 100644 --- a/backend/src/collectivites/services/personnes.service.ts +++ b/backend/src/collectivites/services/personnes.service.ts @@ -1,6 +1,6 @@ import { dcpTable, utilisateurDroitTable } from '@/backend/auth'; -import { DatabaseService } from '@/backend/common'; -import { personneTagTable } from '@/backend/taxonomie/models/personne-tag.table'; +import { personneTagTable } from '@/backend/collectivites/shared/models/personne-tag.table'; +import { DatabaseService } from '@/backend/utils'; import { Injectable } from '@nestjs/common'; import { and, eq, sql } from 'drizzle-orm'; import { union } from 'drizzle-orm/pg-core'; diff --git a/backend/src/taxonomie/models/categorie-tag.table.ts b/backend/src/collectivites/shared/models/categorie-tag.table.ts similarity index 84% rename from backend/src/taxonomie/models/categorie-tag.table.ts rename to backend/src/collectivites/shared/models/categorie-tag.table.ts index 7e44f7d9a6..7e041cbceb 100644 --- a/backend/src/taxonomie/models/categorie-tag.table.ts +++ b/backend/src/collectivites/shared/models/categorie-tag.table.ts @@ -1,5 +1,5 @@ import { boolean, integer, pgTable } from 'drizzle-orm/pg-core'; -import { createdAt, createdBy } from '../../utils/column.utils'; +import { createdAt, createdBy } from '../../../utils/column.utils'; import { tagTableBase } from './tag.table-base'; export const categorieTagTable = pgTable('categorie_tag', { diff --git a/backend/src/collectivites/models/collectivite-banatic-competence.table.ts b/backend/src/collectivites/shared/models/collectivite-banatic-competence.table.ts similarity index 79% rename from backend/src/collectivites/models/collectivite-banatic-competence.table.ts rename to backend/src/collectivites/shared/models/collectivite-banatic-competence.table.ts index 9557f6e101..921b9af375 100644 --- a/backend/src/collectivites/models/collectivite-banatic-competence.table.ts +++ b/backend/src/collectivites/shared/models/collectivite-banatic-competence.table.ts @@ -1,7 +1,6 @@ -import { integer, pgTable } from 'drizzle-orm/pg-core'; +import { integer, pgTable, primaryKey } from 'drizzle-orm/pg-core'; +import { banaticCompetenceTable } from '../../../shared/models/banatic-competence.table'; import { collectiviteTable } from './collectivite.table'; -import { primaryKey } from 'drizzle-orm/pg-core'; -import { banaticCompetenceTable } from '../../taxonomie/models/banatic-competence.table'; export const collectiviteBanaticCompetenceTable = pgTable( 'collectivite_banatic_competence', diff --git a/backend/src/collectivites/models/collectivite-test.table.ts b/backend/src/collectivites/shared/models/collectivite-test.table.ts similarity index 100% rename from backend/src/collectivites/models/collectivite-test.table.ts rename to backend/src/collectivites/shared/models/collectivite-test.table.ts diff --git a/backend/src/collectivites/models/collectivite.table.ts b/backend/src/collectivites/shared/models/collectivite.table.ts similarity index 92% rename from backend/src/collectivites/models/collectivite.table.ts rename to backend/src/collectivites/shared/models/collectivite.table.ts index d65d978aec..35b21c5780 100644 --- a/backend/src/collectivites/models/collectivite.table.ts +++ b/backend/src/collectivites/shared/models/collectivite.table.ts @@ -1,7 +1,7 @@ import { InferInsertModel, InferSelectModel } from 'drizzle-orm'; import { boolean, pgTable, serial } from 'drizzle-orm/pg-core'; import { createInsertSchema, createSelectSchema } from 'drizzle-zod'; -import { createdAt, modifiedAt } from '../../utils/column.utils'; +import { createdAt, modifiedAt } from '../../../utils/column.utils'; // TODO: create domain siren as varchar(9) check ( value ~ '^\d{9}$' ); // TODO: create domain codegeo as varchar(5); diff --git a/backend/src/collectivites/models/commune.table.ts b/backend/src/collectivites/shared/models/commune.table.ts similarity index 100% rename from backend/src/collectivites/models/commune.table.ts rename to backend/src/collectivites/shared/models/commune.table.ts diff --git a/backend/src/collectivites/models/epci.table.ts b/backend/src/collectivites/shared/models/epci.table.ts similarity index 100% rename from backend/src/collectivites/models/epci.table.ts rename to backend/src/collectivites/shared/models/epci.table.ts diff --git a/backend/src/taxonomie/models/financeur-tag.table.ts b/backend/src/collectivites/shared/models/financeur-tag.table.ts similarity index 85% rename from backend/src/taxonomie/models/financeur-tag.table.ts rename to backend/src/collectivites/shared/models/financeur-tag.table.ts index 0bf4544e0d..e10635e513 100644 --- a/backend/src/taxonomie/models/financeur-tag.table.ts +++ b/backend/src/collectivites/shared/models/financeur-tag.table.ts @@ -1,6 +1,7 @@ import { pgTable, uniqueIndex } from 'drizzle-orm/pg-core'; -import { tagTableBase } from './tag.table-base'; import { createSelectSchema } from 'drizzle-zod'; +import z from 'zod'; +import { tagTableBase } from './tag.table-base'; export const financeurTagTable = pgTable( 'financeur_tag', @@ -15,3 +16,4 @@ export const financeurTagTable = pgTable( ); export const financeurTagSchema = createSelectSchema(financeurTagTable); +export type FinanceurTag = z.infer; diff --git a/backend/src/collectivites/models/groupement-collectivite.table.ts b/backend/src/collectivites/shared/models/groupement-collectivite.table.ts similarity index 100% rename from backend/src/collectivites/models/groupement-collectivite.table.ts rename to backend/src/collectivites/shared/models/groupement-collectivite.table.ts diff --git a/backend/src/collectivites/models/groupement.table.ts b/backend/src/collectivites/shared/models/groupement.table.ts similarity index 100% rename from backend/src/collectivites/models/groupement.table.ts rename to backend/src/collectivites/shared/models/groupement.table.ts diff --git a/backend/src/collectivites/models/imports-banatic.table.ts b/backend/src/collectivites/shared/models/imports-banatic.table.ts similarity index 100% rename from backend/src/collectivites/models/imports-banatic.table.ts rename to backend/src/collectivites/shared/models/imports-banatic.table.ts diff --git a/backend/src/collectivites/models/imports-commune.table.ts b/backend/src/collectivites/shared/models/imports-commune.table.ts similarity index 100% rename from backend/src/collectivites/models/imports-commune.table.ts rename to backend/src/collectivites/shared/models/imports-commune.table.ts diff --git a/backend/src/collectivites/models/imports-region.table.ts b/backend/src/collectivites/shared/models/imports-region.table.ts similarity index 100% rename from backend/src/collectivites/models/imports-region.table.ts rename to backend/src/collectivites/shared/models/imports-region.table.ts diff --git a/backend/src/taxonomie/models/libre-tag.table.ts b/backend/src/collectivites/shared/models/libre-tag.table.ts similarity index 78% rename from backend/src/taxonomie/models/libre-tag.table.ts rename to backend/src/collectivites/shared/models/libre-tag.table.ts index a27fa6fb62..156ba45734 100644 --- a/backend/src/taxonomie/models/libre-tag.table.ts +++ b/backend/src/collectivites/shared/models/libre-tag.table.ts @@ -1,6 +1,7 @@ import { pgTable, uniqueIndex } from 'drizzle-orm/pg-core'; import { createSelectSchema } from 'drizzle-zod'; -import { createdAt, createdBy } from '../../utils/column.utils'; +import z from 'zod'; +import { createdAt, createdBy } from '../../../utils/column.utils'; import { tagTableBase } from './tag.table-base'; export const libreTagTable = pgTable( @@ -20,3 +21,4 @@ export const libreTagTable = pgTable( ); export const libreTagSchema = createSelectSchema(libreTagTable); +export type LibreTag = z.infer; diff --git a/backend/src/collectivites/models/membre-fonction.enum.ts b/backend/src/collectivites/shared/models/membre-fonction.enum.ts similarity index 81% rename from backend/src/collectivites/models/membre-fonction.enum.ts rename to backend/src/collectivites/shared/models/membre-fonction.enum.ts index 648137a317..9db2ec8f04 100644 --- a/backend/src/collectivites/models/membre-fonction.enum.ts +++ b/backend/src/collectivites/shared/models/membre-fonction.enum.ts @@ -1,5 +1,5 @@ +import { createEnumObject } from '@/backend/utils'; import { pgEnum } from 'drizzle-orm/pg-core'; -import { createEnumObject } from '../../common/models/enum.helpers'; export const MembreFonction = [ 'conseiller', diff --git a/backend/src/collectivites/models/membre.table.ts b/backend/src/collectivites/shared/models/membre.table.ts similarity index 81% rename from backend/src/collectivites/models/membre.table.ts rename to backend/src/collectivites/shared/models/membre.table.ts index 4772fe7bda..fc251072ec 100644 --- a/backend/src/collectivites/models/membre.table.ts +++ b/backend/src/collectivites/shared/models/membre.table.ts @@ -7,9 +7,9 @@ import { uuid, } from 'drizzle-orm/pg-core'; import { createInsertSchema } from 'drizzle-zod'; -import { authUsersTable } from '../../auth/models/auth-users.table'; -import { referentielEnum } from '../../referentiels/models/referentiel.enum'; -import { createdAt, modifiedAt } from '../../utils/column.utils'; +import { authUsersTable } from '../../../auth/models/auth-users.table'; +import { referentielEnum } from '../../../referentiels/models/referentiel.enum'; +import { createdAt, modifiedAt } from '../../../utils/column.utils'; import { collectiviteTable } from './collectivite.table'; import { membreFonctionEnum } from './membre-fonction.enum'; diff --git a/backend/src/taxonomie/models/partenaire-tag.table.ts b/backend/src/collectivites/shared/models/partenaire-tag.table.ts similarity index 100% rename from backend/src/taxonomie/models/partenaire-tag.table.ts rename to backend/src/collectivites/shared/models/partenaire-tag.table.ts index 43e999a041..653e667ec5 100644 --- a/backend/src/taxonomie/models/partenaire-tag.table.ts +++ b/backend/src/collectivites/shared/models/partenaire-tag.table.ts @@ -1,6 +1,6 @@ import { pgTable, uniqueIndex } from 'drizzle-orm/pg-core'; -import { tagTableBase } from './tag.table-base'; import { createSelectSchema } from 'drizzle-zod'; +import { tagTableBase } from './tag.table-base'; export const partenaireTagTable = pgTable( 'partenaire_tag', diff --git a/backend/src/taxonomie/models/personne-tag.table.ts b/backend/src/collectivites/shared/models/personne-tag.table.ts similarity index 64% rename from backend/src/taxonomie/models/personne-tag.table.ts rename to backend/src/collectivites/shared/models/personne-tag.table.ts index 009ed584cc..443cea86a7 100644 --- a/backend/src/taxonomie/models/personne-tag.table.ts +++ b/backend/src/collectivites/shared/models/personne-tag.table.ts @@ -1,4 +1,6 @@ import { pgTable, uniqueIndex } from 'drizzle-orm/pg-core'; +import { createSelectSchema } from 'drizzle-zod'; +import z from 'zod'; import { tagTableBase } from './tag.table-base'; export const personneTagTable = pgTable( @@ -12,3 +14,6 @@ export const personneTagTable = pgTable( }; } ); + +export const personneTagSchema = createSelectSchema(personneTagTable); +export type PersonneTag = z.infer; diff --git a/backend/src/taxonomie/models/service-tag.table.ts b/backend/src/collectivites/shared/models/service-tag.table.ts similarity index 100% rename from backend/src/taxonomie/models/service-tag.table.ts rename to backend/src/collectivites/shared/models/service-tag.table.ts diff --git a/backend/src/taxonomie/models/structure-tag.table.ts b/backend/src/collectivites/shared/models/structure-tag.table.ts similarity index 100% rename from backend/src/taxonomie/models/structure-tag.table.ts rename to backend/src/collectivites/shared/models/structure-tag.table.ts index 0a5fd9415a..68fc7b2ef8 100644 --- a/backend/src/taxonomie/models/structure-tag.table.ts +++ b/backend/src/collectivites/shared/models/structure-tag.table.ts @@ -1,6 +1,6 @@ import { pgTable, uniqueIndex } from 'drizzle-orm/pg-core'; -import { tagTableBase } from './tag.table-base'; import { createSelectSchema } from 'drizzle-zod'; +import { tagTableBase } from './tag.table-base'; export const structureTagTable = pgTable( 'structure_tag', diff --git a/packages/api/src/shared/domain/tag.schema.ts b/backend/src/collectivites/shared/models/tag.table-base.ts similarity index 53% rename from packages/api/src/shared/domain/tag.schema.ts rename to backend/src/collectivites/shared/models/tag.table-base.ts index 6ab9774df4..0140060a09 100644 --- a/packages/api/src/shared/domain/tag.schema.ts +++ b/backend/src/collectivites/shared/models/tag.table-base.ts @@ -1,28 +1,35 @@ -import { z } from 'zod'; - -export type TypeTag = - | 'personne' - | 'service' - | 'partenaire' - | 'categorie' - | 'financeur' - | 'structure' - | 'libre'; - -export const tagSchema = z.object({ - id: z.number(), - collectiviteId: z.number(), - nom: z.string(), -}); - -export type Tag = z.input; - -export const tagUpdateSchema = tagSchema.partial(); - -export type TagUpdate = z.input; - -export const tagInsertSchema = tagSchema.extend({ - id: z.number().optional(), -}); - -export type TagInsert = z.input; +import { integer, serial, text } from 'drizzle-orm/pg-core'; +import z from 'zod'; +import { collectiviteTable } from './collectivite.table'; + +export type TagType = + | 'personne' + | 'service' + | 'partenaire' + | 'categorie' + | 'financeur' + | 'structure' + | 'libre'; + +export const tagTableBase = { + id: serial('id').primaryKey(), + nom: text('nom').notNull(), + collectiviteId: integer('collectivite_id') + .notNull() + .references(() => collectiviteTable.id), +}; + +export const tagSchema = z.object({ + id: z.number(), + nom: z.string(), + collectiviteId: z.number(), +}); +export type Tag = z.infer; + +export const tagUpdateSchema = tagSchema.partial(); +export type TagUpdate = z.input; + +export const tagInsertSchema = tagSchema.extend({ + id: z.number().optional(), +}); +export type TagInsert = z.input; diff --git a/backend/src/common/common.module.ts b/backend/src/common/common.module.ts deleted file mode 100644 index 5ab45c3f96..0000000000 --- a/backend/src/common/common.module.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { Module } from '@nestjs/common'; -import { ConfigurationModule } from '../config/configuration.module'; -import { VersionController } from './controllers/version.controller'; -import DatabaseService from './services/database.service'; -import MattermostNotificationService from './services/mattermost-notification.service'; -import SupabaseService from './services/supabase.service'; - -@Module({ - imports: [ConfigurationModule], - providers: [DatabaseService, MattermostNotificationService, SupabaseService], - exports: [DatabaseService, MattermostNotificationService, SupabaseService], - controllers: [VersionController], -}) -export class CommonModule {} diff --git a/backend/src/common/index.ts b/backend/src/common/index.ts deleted file mode 100644 index 35e7573d73..0000000000 --- a/backend/src/common/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { default as DatabaseService } from './services/database.service'; diff --git a/backend/src/common/models/enum.helpers.ts b/backend/src/common/models/enum.helpers.ts deleted file mode 100644 index 6c909b5468..0000000000 --- a/backend/src/common/models/enum.helpers.ts +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Permet de créer un objet jouant le rôle d'enum à partir d'une liste de chaînes - * - * Usage : - * ``` - * const Color = [ "Red", "Green", "Blue" ] as const - * const ColorEnum = createEnumObject(Color); - * - * const colorEnum = pgEnum("color", Color); - * const colorSchema = z.enum(Color); - * const table = pgTable("table",{enum: colorEnum("enum")}); - * db.insert(table).values({enum: ColorEnum.BLUE}); - * ``` - * - * Ref: https://github.com/drizzle-team/drizzle-orm/discussions/1914#discussioncomment-8816193 - */ -export const createEnumObject = ( - values: T -): Record, T[number]> => { - const obj: Record = {}; - for (const value of values) { - obj[value.toUpperCase()] = value; - } - return obj; -}; diff --git a/backend/src/common/services/optionalBooleanMapper.ts b/backend/src/common/services/optionalBooleanMapper.ts deleted file mode 100644 index c70023fb91..0000000000 --- a/backend/src/common/services/optionalBooleanMapper.ts +++ /dev/null @@ -1,7 +0,0 @@ -const optionalBooleanMapper = new Map([ - ['undefined', undefined], - ['true', true], - ['false', false], -]); - -export default optionalBooleanMapper; diff --git a/backend/src/documents/models/annexe.table.ts b/backend/src/documents/models/annexe.table.ts index abf9fa5a6c..3c2334322a 100644 --- a/backend/src/documents/models/annexe.table.ts +++ b/backend/src/documents/models/annexe.table.ts @@ -1,5 +1,5 @@ import { integer, pgTable } from 'drizzle-orm/pg-core'; -import { ficheActionTable } from '../../fiches/models/fiche-action.table'; +import { ficheActionTable } from '../../plans/fiches/shared/models/fiche-action.table'; import { DocumentBase } from './document.basetable'; export const annexeTable = pgTable('annexe', { diff --git a/backend/src/documents/models/document.basetable.ts b/backend/src/documents/models/document.basetable.ts index 96ea0f073f..b32effdcbc 100644 --- a/backend/src/documents/models/document.basetable.ts +++ b/backend/src/documents/models/document.basetable.ts @@ -1,13 +1,6 @@ -import { TIMESTAMP_OPTIONS } from '@/backend/utils'; -import { - integer, - jsonb, - serial, - text, - timestamp, - uuid, -} from 'drizzle-orm/pg-core'; -import { collectiviteTable } from '../../collectivites/models/collectivite.table'; +import { modifiedAt, modifiedBy } from '@/backend/utils'; +import { integer, jsonb, serial, text } from 'drizzle-orm/pg-core'; +import { collectiviteTable } from '../../collectivites/shared/models/collectivite.table'; export const DocumentBase = { id: serial('id').primaryKey(), @@ -18,9 +11,7 @@ export const DocumentBase = { url: text('url'), titre: text('titre'), commentaire: text('commentaire'), - modifiedAt: timestamp('modified_at', TIMESTAMP_OPTIONS) - .notNull() - .defaultNow(), - modifiedBy: uuid('modified_by'), // TODO references auth.uid, + modifiedAt, + modifiedBy, lien: jsonb('lien'), }; diff --git a/backend/src/documents/models/preuve-rapport.table.ts b/backend/src/documents/models/preuve-rapport.table.ts index 749dc99736..56de6ef904 100644 --- a/backend/src/documents/models/preuve-rapport.table.ts +++ b/backend/src/documents/models/preuve-rapport.table.ts @@ -1,4 +1,4 @@ -import { TIMESTAMP_OPTIONS } from '@/backend/utils'; +import { TIMESTAMP_OPTIONS } from '@/domain/utils'; import { pgTable, timestamp } from 'drizzle-orm/pg-core'; import { DocumentBase } from './document.basetable'; diff --git a/backend/src/documents/services/document.service.ts b/backend/src/documents/services/document.service.ts index 9eab9bfbf8..39da0d0c15 100644 --- a/backend/src/documents/services/document.service.ts +++ b/backend/src/documents/services/document.service.ts @@ -1,5 +1,5 @@ import { Injectable, Logger } from '@nestjs/common'; -import DatabaseService from '../../common/services/database.service'; +import { DatabaseService } from '../../utils/database/database.service'; import { annexeTable } from '../models/annexe.table'; import { lienType } from '../models/document-lien.dto'; diff --git a/backend/src/fiches/models/fiche-action-financeur-tag.table.ts b/backend/src/fiches/models/fiche-action-financeur-tag.table.ts deleted file mode 100644 index 97280715ae..0000000000 --- a/backend/src/fiches/models/fiche-action-financeur-tag.table.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { integer, pgTable, serial } from 'drizzle-orm/pg-core'; -import { ficheActionTable } from './fiche-action.table'; -import { financeurTagTable } from '../../taxonomie/models/financeur-tag.table'; - -export const ficheActionFinanceurTagTable = pgTable( - 'fiche_action_financeur_tag', - { - id: serial('id').primaryKey(), - ficheId: integer('fiche_id') - .notNull() - .references(() => ficheActionTable.id), - financeurTagId: integer('financeur_tag_id').references( - () => financeurTagTable.id - ), - montantTtc: integer('montant_ttc'), - } -); diff --git a/backend/src/fiches/models/fiche-action-service.table.ts b/backend/src/fiches/models/fiche-action-service.table.ts deleted file mode 100644 index 51f6f36c64..0000000000 --- a/backend/src/fiches/models/fiche-action-service.table.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { integer, pgTable, primaryKey } from 'drizzle-orm/pg-core'; -import { serviceTagTable } from '../../taxonomie/models/service-tag.table'; -import { ficheActionTable } from './fiche-action.table'; - -export const ficheActionServiceTagTable = pgTable( - 'fiche_action_service_tag', - { - ficheId: integer('fiche_id').references(() => ficheActionTable.id), - serviceTagId: integer('service_tag_id').references( - () => serviceTagTable.id - ), - }, - (table) => { - return { - pk: primaryKey({ columns: [table.ficheId, table.serviceTagId] }), - }; - } -); diff --git a/backend/src/fiches/models/get-fiches-action-synthese.response.ts b/backend/src/fiches/models/get-fiches-action-synthese.response.ts deleted file mode 100644 index a8cf02d592..0000000000 --- a/backend/src/fiches/models/get-fiches-action-synthese.response.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { extendApi } from '@anatine/zod-openapi'; -import { z } from 'zod'; -import { countSyntheseValeurSchema } from '../../common/models/count-synthese.dto'; - -export const getFichesActionSyntheseSchema = extendApi( - z.object({ - par_statut: countSyntheseValeurSchema, - }) -); - -export type GetFichesActionSyntheseResponseType = z.infer< - typeof getFichesActionSyntheseSchema ->; diff --git a/backend/src/fiches/models/plan-action-type-category.table.ts b/backend/src/fiches/models/plan-action-type-category.table.ts deleted file mode 100644 index 0f584324b8..0000000000 --- a/backend/src/fiches/models/plan-action-type-category.table.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { pgTable, text } from 'drizzle-orm/pg-core'; - -export const planActionTypeCategorieTable = pgTable( - 'plan_action_type_categorie', - { - categorie: text('categorie').primaryKey(), - } -); diff --git a/backend/src/fiches/services/axe.service.ts b/backend/src/fiches/services/axe.service.ts deleted file mode 100644 index 9faf20d62e..0000000000 --- a/backend/src/fiches/services/axe.service.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { Injectable, Logger } from '@nestjs/common'; -import DatabaseService from '../../common/services/database.service'; -import { axeTable, CreateAxeType } from '../models/axe.table'; -import { ficheActionAxeTable } from '../models/fiche-action-axe.table'; - -@Injectable() -export default class AxeService { - private readonly logger = new Logger(AxeService.name); - - constructor(private readonly databaseService: DatabaseService) {} - - /** - * Crée un axe - * @param axe - * @return identifiant de l'axe créé - */ - async createAxe(axe: CreateAxeType): Promise { - this.logger.log( - `Création de l'axe ${axe.nom} pour la collectivité ${axe.collectiviteId}` - ); - const axeCree = await this.databaseService.db - .insert(axeTable) - .values(axe) - .returning(); - return axeCree[0]?.id; - } - - /** - * Ajoute une fiche dans un axe - * @param ficheId identifiant de la fiche - * @param axeId identifiant de l'axe - */ - async addFicheAction(ficheId: number, axeId: number): Promise { - await this.databaseService.db.insert(ficheActionAxeTable).values({ - axeId: axeId, - ficheId: ficheId, - }); - } -} diff --git a/backend/src/indicateurs/controllers/trajectoires.controller.ts b/backend/src/indicateurs/controllers/trajectoires.controller.ts index ecc84cbd3b..a312ade9c8 100644 --- a/backend/src/indicateurs/controllers/trajectoires.controller.ts +++ b/backend/src/indicateurs/controllers/trajectoires.controller.ts @@ -12,16 +12,16 @@ import { ApiOkResponse, ApiResponse, ApiTags } from '@nestjs/swagger'; import { NextFunction, Response } from 'express'; import { AllowPublicAccess } from '../../auth/decorators/allow-public-access.decorator'; import { TokenInfo } from '../../auth/decorators/token-info.decorators'; -import { CollectiviteRequestClass } from '../../collectivites/models/collectivite.request'; +import type { AuthenticatedUser } from '../../auth/models/auth.models'; +import { CollectiviteRequestClass } from '../../collectivites/collectivite.request'; import { calculTrajectoireRequestSchema } from '../models/calcul-trajectoire.request'; +import { calculTrajectoireResponseSchema } from '../models/calcul-trajectoire.response'; +import { modeleTrajectoireTelechargementRequestSchema } from '../models/modele-trajectoire-telechargement.request'; +import { verificationTrajectoireRequestSchema } from '../models/verification-trajectoire.request'; +import { verificationTrajectoireResponseSchema } from '../models/verification-trajectoire.response'; import TrajectoiresDataService from '../services/trajectoires-data.service'; import TrajectoiresSpreadsheetService from '../services/trajectoires-spreadsheet.service'; import TrajectoiresXlsxService from '../services/trajectoires-xlsx.service'; -import type { AuthenticatedUser } from '../../auth/models/auth.models'; -import { verificationTrajectoireResponseSchema } from '../models/verification-trajectoire.response'; -import { modeleTrajectoireTelechargementRequestSchema } from '../models/modele-trajectoire-telechargement.request'; -import { verificationTrajectoireRequestSchema } from '../models/verification-trajectoire.request'; -import { calculTrajectoireResponseSchema } from '../models/calcul-trajectoire.response'; /** * Création des classes de requête/réponse à partir du schema pour générer automatiquement la documentation OpenAPI et la validation des entrées diff --git a/backend/src/indicateurs/index-domain.ts b/backend/src/indicateurs/index-domain.ts new file mode 100644 index 0000000000..a10e793525 --- /dev/null +++ b/backend/src/indicateurs/index-domain.ts @@ -0,0 +1,4 @@ +// `index-domain.ts` file must only contain exports that are shareable with client-side apps. +// Exports from this file can be imported with `@/domain/*` alias path. + +export * from './models/indicateur-definition.table'; diff --git a/backend/src/indicateurs/index.ts b/backend/src/indicateurs/index.ts new file mode 100644 index 0000000000..81ce45f809 --- /dev/null +++ b/backend/src/indicateurs/index.ts @@ -0,0 +1 @@ +export * from './index-domain'; diff --git a/backend/src/indicateurs/indicateur-filtre/get-filtered-indicateurs.request.ts b/backend/src/indicateurs/indicateur-filtre/get-filtered-indicateurs.request.ts index e93894d1e1..7f25fd25b4 100644 --- a/backend/src/indicateurs/indicateur-filtre/get-filtered-indicateurs.request.ts +++ b/backend/src/indicateurs/indicateur-filtre/get-filtered-indicateurs.request.ts @@ -1,4 +1,4 @@ -import { getQueryOptionsSchema } from '@/api/shared/domain'; +import { getPaginationSchema } from '@/backend/utils'; import { z } from 'zod'; export const getFilteredIndicateursRequestOptionsSchema = z.object({ @@ -134,7 +134,7 @@ export type GetFilteredIndicateursRequestOptionType = z.infer< >; export const getFilteredIndicateurRequestQueryOptionSchema = - getQueryOptionsSchema(['text', 'estComplet']); + getPaginationSchema(['text', 'estComplet']); export type GetFilteredIndicateurRequestQueryOptionType = z.infer< typeof getFilteredIndicateurRequestQueryOptionSchema diff --git a/backend/src/indicateurs/indicateur-filtre/indicateur-filtre.router.e2e-spec.ts b/backend/src/indicateurs/indicateur-filtre/indicateur-filtre.router.e2e-spec.ts index d23c2e6335..d03f198b89 100644 --- a/backend/src/indicateurs/indicateur-filtre/indicateur-filtre.router.e2e-spec.ts +++ b/backend/src/indicateurs/indicateur-filtre/indicateur-filtre.router.e2e-spec.ts @@ -1,7 +1,7 @@ import { inferProcedureInput } from '@trpc/server'; import { getTestRouter } from '../../../test/app-utils'; import { getAuthUser } from '../../../test/auth-utils'; -import { AppRouter, TrpcRouter } from '../../trpc/trpc.router'; +import { AppRouter, TrpcRouter } from '../../utils/trpc/trpc.router'; import { AuthenticatedUser } from './../../auth/models/auth.models'; import { GetFilteredIndicateurRequestQueryOptionType, @@ -9,7 +9,7 @@ import { } from './get-filtered-indicateurs.request'; import { getFilteredIndicateurResponseSchema } from './get-filtered-indicateurs.response'; -type Input = inferProcedureInput; +type Input = inferProcedureInput; describe('Route de lecture des indicateurs filtrés', () => { let router: TrpcRouter; @@ -39,7 +39,7 @@ describe('Route de lecture des indicateurs filtrés', () => { filtre: filtre, queryOptions: queryOptions, }; - const result = await caller.indicateurs.filtre.list(input); + const result = await caller.indicateurs.list(input); expect(result.length).not.toBe(0); const toCheck = getFilteredIndicateurResponseSchema.safeParse(result); expect(toCheck.success).toBeTruthy; @@ -73,7 +73,7 @@ describe('Route de lecture des indicateurs filtrés', () => { queryOptions: queryOptions, }; - const result = await caller.indicateurs.filtre.list(input); + const result = await caller.indicateurs.list(input); expect(result.length).toBe(0); }); }); diff --git a/backend/src/indicateurs/indicateur-filtre/indicateur-filtre.router.ts b/backend/src/indicateurs/indicateur-filtre/indicateur-filtre.router.ts index e95df16b98..502e37da14 100644 --- a/backend/src/indicateurs/indicateur-filtre/indicateur-filtre.router.ts +++ b/backend/src/indicateurs/indicateur-filtre/indicateur-filtre.router.ts @@ -1,5 +1,5 @@ import { Injectable } from '@nestjs/common'; -import { TrpcService } from '../../trpc/trpc.service'; +import { TrpcService } from '@/backend/utils/trpc/trpc.service'; import IndicateurFiltreService from './indicateur-filtre.service'; import { getFilteredIndicateursRequestSchema } from './get-filtered-indicateurs.request'; diff --git a/backend/src/indicateurs/indicateur-filtre/indicateur-filtre.service.spec.ts b/backend/src/indicateurs/indicateur-filtre/indicateur-filtre.service.spec.ts index 2545b68566..4d8d6e6898 100644 --- a/backend/src/indicateurs/indicateur-filtre/indicateur-filtre.service.spec.ts +++ b/backend/src/indicateurs/indicateur-filtre/indicateur-filtre.service.spec.ts @@ -1,12 +1,12 @@ +import { PermissionService } from '@/backend/auth/authorizations/permission.service'; import { Test } from '@nestjs/testing'; -import DatabaseService from '../../common/services/database.service'; -import IndicateurFiltreService from './indicateur-filtre.service'; +import CollectivitesService from '../../collectivites/services/collectivites.service'; +import { DatabaseService } from '../../utils/database/database.service'; import { GetFilteredIndicateurRequestQueryOptionType, GetFilteredIndicateursRequestOptionType, } from './get-filtered-indicateurs.request'; -import { PermissionService } from '@/backend/auth/authorizations/permission.service'; -import CollectivitesService from '../../collectivites/services/collectivites.service'; +import IndicateurFiltreService from './indicateur-filtre.service'; describe('IndicateurFiltreService', () => { let indicateurFiltreService: IndicateurFiltreService; diff --git a/backend/src/indicateurs/indicateur-filtre/indicateur-filtre.service.ts b/backend/src/indicateurs/indicateur-filtre/indicateur-filtre.service.ts index e3d4d17287..a024c25324 100644 --- a/backend/src/indicateurs/indicateur-filtre/indicateur-filtre.service.ts +++ b/backend/src/indicateurs/indicateur-filtre/indicateur-filtre.service.ts @@ -1,33 +1,32 @@ +import { PermissionOperation } from '@/backend/auth/authorizations/permission-operation.enum'; +import { PermissionService } from '@/backend/auth/authorizations/permission.service'; +import { ResourceType } from '@/backend/auth/authorizations/resource-type.enum'; +import { serviceTagTable } from '@/backend/collectivites'; +import { axeTable, ficheActionIndicateurTable } from '@/backend/plans/fiches'; +import { ficheActionAxeTable } from '@/backend/plans/fiches/shared/models/fiche-action-axe.table'; import { Injectable } from '@nestjs/common'; -import DatabaseService from '../../common/services/database.service'; -import { - GetFilteredIndicateurRequestQueryOptionType, - GetFilteredIndicateursRequestOptionType, -} from './get-filtered-indicateurs.request'; import { getTableName, sql } from 'drizzle-orm'; import { intersection, isNil } from 'es-toolkit'; -import { GetFilteredIndicateurResponseType } from './get-filtered-indicateurs.response'; import { AuthenticatedUser } from '../../auth/models/auth.models'; -import { indicateurValeurTable } from '../models/indicateur-valeur.table'; -import { groupementCollectiviteTable } from '../../collectivites/models/groupement-collectivite.table'; +import CollectivitesService from '../../collectivites/services/collectivites.service'; +import { categorieTagTable } from '../../collectivites/shared/models/categorie-tag.table'; +import { groupementCollectiviteTable } from '../../collectivites/shared/models/groupement-collectivite.table'; +import { ficheActionTable } from '../../plans/fiches/shared/models/fiche-action.table'; +import { DatabaseService } from '../../utils/database/database.service'; +import { indicateurActionTable } from '../models/indicateur-action.table'; +import { indicateurCategorieTagTable } from '../models/indicateur-categorie-tag.table'; +import { indicateurCollectiviteTable } from '../models/indicateur-collectivite.table'; import { indicateurDefinitionTable } from '../models/indicateur-definition.table'; import { indicateurGroupeTable } from '../models/indicateur-groupe.table'; -import { categorieTagTable } from '../../taxonomie/models/categorie-tag.table'; -import { indicateurCategorieTagTable } from '../models/indicateur-categorie-tag.table'; -import { ficheActionTable } from '../../fiches/models/fiche-action.table'; -import { axeTable } from '../../fiches/models/axe.table'; -import { ficheActionAxeTable } from '../../fiches/models/fiche-action-axe.table'; -import { serviceTagTable } from '../../taxonomie/models/service-tag.table'; -import { indicateurThematiqueTable } from '../models/indicateur-thematique.table'; import { indicateurPiloteTable } from '../models/indicateur-pilote.table'; -import { indicateurCollectiviteTable } from '../models/indicateur-collectivite.table'; -import { indicateurActionTable } from '../models/indicateur-action.table'; -import { ficheActionIndicateurTable } from '../../fiches/models/fiche-action-indicateur.table'; import { indicateurServiceTagTable } from '../models/indicateur-service-tag.table'; -import { PermissionService } from '@/backend/auth/authorizations/permission.service'; -import CollectivitesService from '../../collectivites/services/collectivites.service'; -import { PermissionOperation } from '@/backend/auth/authorizations/permission-operation.enum'; -import { ResourceType } from '@/backend/auth/authorizations/resource-type.enum'; +import { indicateurThematiqueTable } from '../models/indicateur-thematique.table'; +import { indicateurValeurTable } from '../models/indicateur-valeur.table'; +import { + GetFilteredIndicateurRequestQueryOptionType, + GetFilteredIndicateursRequestOptionType, +} from './get-filtered-indicateurs.request'; +import { GetFilteredIndicateurResponseType } from './get-filtered-indicateurs.response'; export type RequestResultIndicateursRaw = { id: number; @@ -171,7 +170,7 @@ export default class IndicateurFiltreService { return indicateursSorted.map((indicateur) => ({ id: indicateur.id, - titre: indicateur.titre?indicateur.titre:'', + titre: indicateur.titre ? indicateur.titre : '', estPerso: !isNil(indicateur.collectiviteId), identifiant: indicateur.identifiantReferentiel, hasOpenData: indicateur.hasOpenData, @@ -714,49 +713,39 @@ export default class IndicateurFiltreService { const hasOpenData = options.hasOpenData ? indicateur.hasOpenData : true; const categoriesNoms = options.categorieNoms && options.categorieNoms.length > 0 - ? intersection( - options.categorieNoms, - indicateur.categorieNoms - ).length>0 + ? intersection(options.categorieNoms, indicateur.categorieNoms) + .length > 0 : true; const planActionIds = options.planActionIds && options.planActionIds.length > 0 - ? intersection(options.planActionIds, indicateur.planIds).length>0 + ? intersection(options.planActionIds, indicateur.planIds).length > 0 : true; const ficheActionIds = options.ficheActionIds && options.ficheActionIds.length > 0 - ? intersection(options.ficheActionIds, indicateur.ficheIds).length>0 + ? intersection(options.ficheActionIds, indicateur.ficheIds).length > 0 : true; const fichesNonClassees = options.fichesNonClassees ? indicateur.hasFichesNonClassees : true; const servicePiloteIds = options.servicePiloteIds && options.servicePiloteIds.length > 0 - ? intersection( - options.servicePiloteIds, - indicateur.serviceIds - ).length>0 + ? intersection(options.servicePiloteIds, indicateur.serviceIds) + .length > 0 : true; const thematiqueIds = options.thematiqueIds && options.thematiqueIds.length > 0 - ? intersection( - options.thematiqueIds, - indicateur.thematiqueIds - ).length>0 + ? intersection(options.thematiqueIds, indicateur.thematiqueIds) + .length > 0 : true; const personnePiloteIds = options.personnePiloteIds && options.personnePiloteIds.length > 0 - ? intersection( - options.personnePiloteIds, - indicateur.piloteTagIds - ).length>0 + ? intersection(options.personnePiloteIds, indicateur.piloteTagIds) + .length > 0 : true; const utilisateurPiloteIds = options.utilisateurPiloteIds && options.utilisateurPiloteIds.length > 0 - ? intersection( - options.utilisateurPiloteIds, - indicateur.piloteUserIds - ).length>0 + ? intersection(options.utilisateurPiloteIds, indicateur.piloteUserIds) + .length > 0 : true; const estComplet = options.estComplet === true @@ -784,7 +773,7 @@ export default class IndicateurFiltreService { } } const actionId = options.actionId - ? intersection([options.actionId], indicateur.actionIds).length>0 + ? intersection([options.actionId], indicateur.actionIds).length > 0 : true; // Applique les conditions diff --git a/backend/src/indicateurs/indicateurs.module.ts b/backend/src/indicateurs/indicateurs.module.ts index 9e54bf81f6..ee5d077ad8 100644 --- a/backend/src/indicateurs/indicateurs.module.ts +++ b/backend/src/indicateurs/indicateurs.module.ts @@ -1,31 +1,21 @@ import { Module } from '@nestjs/common'; import { AuthModule } from '../auth/auth.module'; import { CollectivitesModule } from '../collectivites/collectivites.module'; -import { CommonModule } from '../common/common.module'; -import { SheetModule } from '../spreadsheets/sheet.module'; -import { TrpcModule } from '../trpc/trpc.module'; +import { SheetModule } from '../utils/google-sheets/sheet.module'; import { IndicateursController } from './controllers/indicateurs.controller'; import { TrajectoiresController } from './controllers/trajectoires.controller'; +import { IndicateurFiltreRouter } from './indicateur-filtre/indicateur-filtre.router'; +import IndicateurFiltreService from './indicateur-filtre/indicateur-filtre.service'; import { TrajectoiresRouter } from './routers/trajectoires.router'; -import IndicateursService from './services/indicateurs.service'; -import IndicateurSourcesService from './services/indicateur-sources.service'; import ExportIndicateursService from './services/export-indicateurs.service'; +import IndicateurSourcesService from './services/indicateur-sources.service'; +import IndicateursService from './services/indicateurs.service'; import TrajectoiresDataService from './services/trajectoires-data.service'; import TrajectoiresSpreadsheetService from './services/trajectoires-spreadsheet.service'; import TrajectoiresXlsxService from './services/trajectoires-xlsx.service'; -import { ConfigurationModule } from '../config/configuration.module'; -import IndicateurFiltreService from './indicateur-filtre/indicateur-filtre.service'; -import { IndicateurFiltreRouter } from './indicateur-filtre/indicateur-filtre.router'; @Module({ - imports: [ - ConfigurationModule, - CommonModule, - TrpcModule, - AuthModule, - CollectivitesModule, - SheetModule, - ], + imports: [AuthModule, CollectivitesModule, SheetModule], providers: [ ExportIndicateursService, IndicateurSourcesService, @@ -37,7 +27,13 @@ import { IndicateurFiltreRouter } from './indicateur-filtre/indicateur-filtre.ro TrajectoiresXlsxService, TrajectoiresRouter, ], - exports: [IndicateurSourcesService, IndicateursService, TrajectoiresRouter, IndicateurFiltreService, IndicateurFiltreRouter], + exports: [ + IndicateurSourcesService, + IndicateursService, + TrajectoiresRouter, + IndicateurFiltreService, + IndicateurFiltreRouter, + ], controllers: [IndicateursController, TrajectoiresController], }) export class IndicateursModule {} diff --git a/backend/src/indicateurs/models/calcul-trajectoire.request.ts b/backend/src/indicateurs/models/calcul-trajectoire.request.ts index 2b13e4ccdb..db10e771d2 100644 --- a/backend/src/indicateurs/models/calcul-trajectoire.request.ts +++ b/backend/src/indicateurs/models/calcul-trajectoire.request.ts @@ -1,6 +1,6 @@ import { extendApi } from '@anatine/zod-openapi'; import { z } from 'zod'; -import { collectiviteRequestSchema } from '../../collectivites/models/collectivite.request'; +import { collectiviteRequestSchema } from '../../collectivites/collectivite.request'; export enum CalculTrajectoireReset { MAJ_SPREADSHEET_EXISTANT = 'maj_spreadsheet_existant', diff --git a/backend/src/indicateurs/models/indicateur-categorie-tag.table.ts b/backend/src/indicateurs/models/indicateur-categorie-tag.table.ts index 08f217821c..9bdb2df45f 100644 --- a/backend/src/indicateurs/models/indicateur-categorie-tag.table.ts +++ b/backend/src/indicateurs/models/indicateur-categorie-tag.table.ts @@ -1,7 +1,6 @@ -import { integer, pgTable } from 'drizzle-orm/pg-core'; +import { integer, pgTable, primaryKey } from 'drizzle-orm/pg-core'; +import { categorieTagTable } from '../../collectivites/shared/models/categorie-tag.table'; import { indicateurDefinitionTable } from './indicateur-definition.table'; -import { primaryKey } from 'drizzle-orm/pg-core'; -import { categorieTagTable } from '../../taxonomie/models/categorie-tag.table'; export const indicateurCategorieTagTable = pgTable( 'indicateur_categorie_tag', diff --git a/backend/src/indicateurs/models/indicateur-collectivite.table.ts b/backend/src/indicateurs/models/indicateur-collectivite.table.ts index 8c5b0a2fe9..78e3a2177b 100644 --- a/backend/src/indicateurs/models/indicateur-collectivite.table.ts +++ b/backend/src/indicateurs/models/indicateur-collectivite.table.ts @@ -1,7 +1,12 @@ -import { boolean, integer, pgTable, text } from 'drizzle-orm/pg-core'; -import { collectiviteTable } from '../../collectivites/models/collectivite.table'; +import { + boolean, + integer, + pgTable, + primaryKey, + text, +} from 'drizzle-orm/pg-core'; +import { collectiviteTable } from '../../collectivites/shared/models/collectivite.table'; import { indicateurDefinitionTable } from './indicateur-definition.table'; -import { primaryKey } from 'drizzle-orm/pg-core'; export const indicateurCollectiviteTable = pgTable( 'indicateur_collectivite', diff --git a/backend/src/indicateurs/models/indicateur-definition.table.ts b/backend/src/indicateurs/models/indicateur-definition.table.ts index 7118cfdcd2..415755e4ea 100644 --- a/backend/src/indicateurs/models/indicateur-definition.table.ts +++ b/backend/src/indicateurs/models/indicateur-definition.table.ts @@ -9,7 +9,7 @@ import { } from 'drizzle-orm/pg-core'; import { createInsertSchema, createSelectSchema } from 'drizzle-zod'; import { z } from 'zod'; -import { collectiviteTable } from '../../collectivites/models/collectivite.table'; +import { collectiviteTable } from '../../collectivites/shared/models/collectivite.table'; import { createdAt, createdBy, diff --git a/backend/src/indicateurs/models/indicateur-pilote.table.ts b/backend/src/indicateurs/models/indicateur-pilote.table.ts index a7f7f47f67..5f206437cd 100644 --- a/backend/src/indicateurs/models/indicateur-pilote.table.ts +++ b/backend/src/indicateurs/models/indicateur-pilote.table.ts @@ -1,7 +1,6 @@ -import { integer, pgTable, uuid } from 'drizzle-orm/pg-core'; -import { personneTagTable } from '../../taxonomie/models/personne-tag.table'; -import { serial } from 'drizzle-orm/pg-core'; -import { collectiviteTable } from '../../collectivites/models/collectivite.table'; +import { integer, pgTable, serial, uuid } from 'drizzle-orm/pg-core'; +import { collectiviteTable } from '../../collectivites/shared/models/collectivite.table'; +import { personneTagTable } from '../../collectivites/shared/models/personne-tag.table'; import { indicateurDefinitionTable } from './indicateur-definition.table'; export const indicateurPiloteTable = pgTable('indicateur_pilote', { diff --git a/backend/src/indicateurs/models/indicateur-service-tag.table.ts b/backend/src/indicateurs/models/indicateur-service-tag.table.ts index 57838ead9f..dab77b160c 100644 --- a/backend/src/indicateurs/models/indicateur-service-tag.table.ts +++ b/backend/src/indicateurs/models/indicateur-service-tag.table.ts @@ -1,6 +1,6 @@ +import { serviceTagTable } from '@/domain/collectivites'; import { integer, pgTable, primaryKey } from 'drizzle-orm/pg-core'; -import { serviceTagTable } from '../../taxonomie/models/service-tag.table'; -import { collectiviteTable } from '../../collectivites/models/collectivite.table'; +import { collectiviteTable } from '../../collectivites/shared/models/collectivite.table'; import { indicateurDefinitionTable } from './indicateur-definition.table'; export const indicateurServiceTagTable = pgTable( diff --git a/backend/src/indicateurs/models/indicateur-thematique.table.ts b/backend/src/indicateurs/models/indicateur-thematique.table.ts index d3961cd263..73d1ba89d8 100644 --- a/backend/src/indicateurs/models/indicateur-thematique.table.ts +++ b/backend/src/indicateurs/models/indicateur-thematique.table.ts @@ -1,5 +1,5 @@ import { integer, pgTable, primaryKey } from 'drizzle-orm/pg-core'; -import { thematiqueTable } from '../../taxonomie/models/thematique.table'; +import { thematiqueTable } from '../../shared/models/thematique.table'; import { indicateurDefinitionTable } from './indicateur-definition.table'; export const indicateurThematiqueTable = pgTable( diff --git a/backend/src/indicateurs/models/indicateur-valeur.table.ts b/backend/src/indicateurs/models/indicateur-valeur.table.ts index 1a00009fd2..38b68d4b2b 100644 --- a/backend/src/indicateurs/models/indicateur-valeur.table.ts +++ b/backend/src/indicateurs/models/indicateur-valeur.table.ts @@ -11,7 +11,7 @@ import { } from 'drizzle-orm/pg-core'; import { createInsertSchema, createSelectSchema } from 'drizzle-zod'; import { z } from 'zod'; -import { collectiviteTable } from '../../collectivites/models/collectivite.table'; +import { collectiviteTable } from '../../collectivites/shared/models/collectivite.table'; import { createdAt, createdBy, diff --git a/backend/src/indicateurs/models/verification-trajectoire.request.ts b/backend/src/indicateurs/models/verification-trajectoire.request.ts index c4cd36391c..f151aa801b 100644 --- a/backend/src/indicateurs/models/verification-trajectoire.request.ts +++ b/backend/src/indicateurs/models/verification-trajectoire.request.ts @@ -1,6 +1,6 @@ import { extendApi } from '@anatine/zod-openapi'; import { z } from 'zod'; -import { collectiviteRequestSchema } from '../../collectivites/models/collectivite.request'; +import { collectiviteRequestSchema } from '../../collectivites/collectivite.request'; export const verificationTrajectoireRequestSchema = extendApi( collectiviteRequestSchema.extend({ diff --git a/backend/src/indicateurs/models/verification-trajectoire.response.ts b/backend/src/indicateurs/models/verification-trajectoire.response.ts index 69bc300b98..515150c151 100644 --- a/backend/src/indicateurs/models/verification-trajectoire.response.ts +++ b/backend/src/indicateurs/models/verification-trajectoire.response.ts @@ -1,6 +1,6 @@ import { extendApi } from '@anatine/zod-openapi'; import { z } from 'zod'; -import { epciSchema } from '../../collectivites/models/epci.table'; +import { epciSchema } from '../../collectivites/shared/models/epci.table'; import { donneesCalculTrajectoireARemplirSchema } from './donnees-calcul-trajectoire-a-remplir.dto'; import { IndicateurValeurType } from './indicateur-valeur.table'; diff --git a/backend/src/indicateurs/routers/trajectoires.router.ts b/backend/src/indicateurs/routers/trajectoires.router.ts index 12f16c2863..816c829f99 100644 --- a/backend/src/indicateurs/routers/trajectoires.router.ts +++ b/backend/src/indicateurs/routers/trajectoires.router.ts @@ -1,6 +1,6 @@ import { Injectable } from '@nestjs/common'; import { z } from 'zod'; -import { TrpcService } from '../../trpc/trpc.service'; +import { TrpcService } from '@/backend/utils/trpc/trpc.service'; import TrajectoiresSpreadsheetService from '../services/trajectoires-spreadsheet.service'; @Injectable() diff --git a/backend/src/indicateurs/services/export-indicateurs.service.ts b/backend/src/indicateurs/services/export-indicateurs.service.ts index 439ca17472..d72896c5d6 100644 --- a/backend/src/indicateurs/services/export-indicateurs.service.ts +++ b/backend/src/indicateurs/services/export-indicateurs.service.ts @@ -15,7 +15,7 @@ import { adjustColumnWidth, BOLD, normalizeWorksheetName, -} from '../../common/services/xlsx.helper'; +} from '../../utils/excel/excel.utils'; import CollectivitesService from '../../collectivites/services/collectivites.service'; import { PermissionService } from '@/backend/auth/authorizations/permission.service'; import { ResourceType } from '@/backend/auth/authorizations/resource-type.enum'; diff --git a/backend/src/indicateurs/services/indicateur-sources.service.ts b/backend/src/indicateurs/services/indicateur-sources.service.ts index cc13ebac21..1569205084 100644 --- a/backend/src/indicateurs/services/indicateur-sources.service.ts +++ b/backend/src/indicateurs/services/indicateur-sources.service.ts @@ -1,6 +1,6 @@ import { Injectable, Logger } from '@nestjs/common'; import { and, eq } from 'drizzle-orm'; -import DatabaseService from '../../common/services/database.service'; +import { DatabaseService } from '../../utils/database/database.service'; import { CreateIndicateurSourceMetadonneeType, indicateurSourceMetadonneeTable, diff --git a/backend/src/indicateurs/services/indicateurs.service.spec.ts b/backend/src/indicateurs/services/indicateurs.service.spec.ts index 72f5d87182..3b5ddf408d 100644 --- a/backend/src/indicateurs/services/indicateurs.service.spec.ts +++ b/backend/src/indicateurs/services/indicateurs.service.spec.ts @@ -1,7 +1,7 @@ +import { PermissionService } from '@/backend/auth/authorizations/permission.service'; import { Test } from '@nestjs/testing'; import * as _ from 'lodash'; -import { DateTime } from 'luxon'; -import DatabaseService from '../../common/services/database.service'; +import { DatabaseService } from '../../utils/database/database.service'; import { IndicateurDefinitionType } from '../models/indicateur-definition.table'; import { IndicateurSourceMetadonneeType } from '../models/indicateur-source-metadonnee.table'; import { @@ -10,7 +10,6 @@ import { IndicateurValeurAvecMetadonnesDefinition, IndicateurValeurType, } from '../models/indicateur-valeur.table'; -import { PermissionService } from '@/backend/auth/authorizations/permission.service'; import IndicateursService from './indicateurs.service'; describe('IndicateursService', () => { diff --git a/backend/src/indicateurs/services/indicateurs.service.ts b/backend/src/indicateurs/services/indicateurs.service.ts index 54060a14c1..69f79ce059 100644 --- a/backend/src/indicateurs/services/indicateurs.service.ts +++ b/backend/src/indicateurs/services/indicateurs.service.ts @@ -1,3 +1,6 @@ +import { PermissionOperation } from '@/backend/auth/authorizations/permission-operation.enum'; +import { PermissionService } from '@/backend/auth/authorizations/permission.service'; +import { ResourceType } from '@/backend/auth/authorizations/resource-type.enum'; import { Injectable, Logger } from '@nestjs/common'; import { aliasedTable, @@ -14,11 +17,13 @@ import { SQL, SQLWrapper, } from 'drizzle-orm'; -import { objectToCamel } from 'ts-case-convert'; import { groupBy, partition } from 'es-toolkit'; import * as _ from 'lodash'; +import { objectToCamel } from 'ts-case-convert'; import { AuthenticatedUser, AuthRole } from '../../auth/models/auth.models'; -import DatabaseService from '../../common/services/database.service'; +import { groupementCollectiviteTable } from '../../collectivites/shared/models/groupement-collectivite.table'; +import { groupementTable } from '../../collectivites/shared/models/groupement.table'; +import { DatabaseService } from '../../utils/database/database.service'; import { DeleteIndicateursValeursRequestType } from '../models/delete-indicateurs.request'; import { GetIndicateursValeursRequestType } from '../models/get-indicateurs.request'; import { GetIndicateursValeursResponseType } from '../models/get-indicateurs.response'; @@ -28,6 +33,7 @@ import { IndicateurDefinitionType, MinimalIndicateurDefinitionType, } from '../models/indicateur-definition.table'; +import { indicateurGroupeTable } from '../models/indicateur-groupe.table'; import { indicateurSourceMetadonneeTable, IndicateurSourceMetadonneeType, @@ -42,12 +48,6 @@ import { indicateurValeurTable, IndicateurValeurType, } from '../models/indicateur-valeur.table'; -import { indicateurGroupeTable } from '../models/indicateur-groupe.table'; -import { groupementTable } from '../../collectivites/models/groupement.table'; -import { groupementCollectiviteTable } from '../../collectivites/models/groupement-collectivite.table'; -import { PermissionService } from '@/backend/auth/authorizations/permission.service'; -import { PermissionOperation } from '@/backend/auth/authorizations/permission-operation.enum'; -import { ResourceType } from '@/backend/auth/authorizations/resource-type.enum'; @Injectable() export default class IndicateursService { diff --git a/backend/src/indicateurs/services/trajectoires-data.service.spec.ts b/backend/src/indicateurs/services/trajectoires-data.service.spec.ts index 481f49c4bb..680bd7f23f 100644 --- a/backend/src/indicateurs/services/trajectoires-data.service.spec.ts +++ b/backend/src/indicateurs/services/trajectoires-data.service.spec.ts @@ -1,7 +1,7 @@ import { Test } from '@nestjs/testing'; import { DateTime } from 'luxon'; import CollectivitesService from '../../collectivites/services/collectivites.service'; -import SheetService from '../../spreadsheets/services/sheet.service'; +import SheetService from '../../utils/google-sheets/sheet.service'; import { IndicateurValeurType } from '../models/indicateur-valeur.table'; import IndicateurSourcesService from './indicateur-sources.service'; import IndicateursService from './indicateurs.service'; diff --git a/backend/src/indicateurs/services/trajectoires-data.service.ts b/backend/src/indicateurs/services/trajectoires-data.service.ts index fc0bbb253f..3ceebef346 100644 --- a/backend/src/indicateurs/services/trajectoires-data.service.ts +++ b/backend/src/indicateurs/services/trajectoires-data.service.ts @@ -1,3 +1,6 @@ +import { PermissionOperation } from '@/backend/auth/authorizations/permission-operation.enum'; +import { PermissionService } from '@/backend/auth/authorizations/permission.service'; +import { ResourceType } from '@/backend/auth/authorizations/resource-type.enum'; import { Injectable, InternalServerErrorException, @@ -7,8 +10,11 @@ import { isNil } from 'es-toolkit'; import * as _ from 'lodash'; import { DateTime } from 'luxon'; import { AuthenticatedUser } from '../../auth/models/auth.models'; -import { EpciType } from '../../collectivites/models/epci.table'; import CollectivitesService from '../../collectivites/services/collectivites.service'; +import { EpciType } from '../../collectivites/shared/models/epci.table'; +import { DonneesARemplirResultType } from '../models/donnees-a-remplir-result.dto'; +import { DonneesARemplirValeurType } from '../models/donnees-a-remplir-valeur.dto'; +import { DonneesCalculTrajectoireARemplirType } from '../models/donnees-calcul-trajectoire-a-remplir.dto'; import { CreateIndicateurSourceMetadonneeType, IndicateurSourceMetadonneeType, @@ -18,17 +24,11 @@ import { IndicateurValeurAvecMetadonnesDefinition, IndicateurValeurType, } from '../models/indicateur-valeur.table'; +import { VerificationTrajectoireRequestType } from '../models/verification-trajectoire.request'; import { VerificationTrajectoireResultType, VerificationTrajectoireStatus, } from '../models/verification-trajectoire.response'; -import { VerificationTrajectoireRequestType } from '../models/verification-trajectoire.request'; -import { DonneesCalculTrajectoireARemplirType } from '../models/donnees-calcul-trajectoire-a-remplir.dto'; -import { DonneesARemplirValeurType } from '../models/donnees-a-remplir-valeur.dto'; -import { DonneesARemplirResultType } from '../models/donnees-a-remplir-result.dto'; -import { PermissionService } from '@/backend/auth/authorizations/permission.service'; -import { ResourceType } from '@/backend/auth/authorizations/resource-type.enum'; -import { PermissionOperation } from '@/backend/auth/authorizations/permission-operation.enum'; import IndicateurSourcesService from './indicateur-sources.service'; import IndicateursService from './indicateurs.service'; @@ -684,7 +684,7 @@ export default class TrajectoiresDataService { return response; } } - if(!forceRecuperationDonneesUniquementPourLecture) { + if (!forceRecuperationDonneesUniquementPourLecture) { // Vérification des droits pour calculer les données await this.permissionService.isAllowed( tokenInfo, diff --git a/backend/src/indicateurs/services/trajectoires-spreadsheet.service.ts b/backend/src/indicateurs/services/trajectoires-spreadsheet.service.ts index d42ee30061..fae81d1e33 100644 --- a/backend/src/indicateurs/services/trajectoires-spreadsheet.service.ts +++ b/backend/src/indicateurs/services/trajectoires-spreadsheet.service.ts @@ -8,10 +8,10 @@ import { isNil, partition } from 'es-toolkit'; import * as _ from 'lodash'; import slugify from 'slugify'; import { AuthenticatedUser } from '../../auth/models/auth.models'; -import { EpciType } from '../../collectivites/models/epci.table'; import GroupementsService from '../../collectivites/services/groupements.service'; -import ConfigurationService from '../../config/configuration.service'; -import SheetService from '../../spreadsheets/services/sheet.service'; +import { EpciType } from '../../collectivites/shared/models/epci.table'; +import ConfigurationService from '../../utils/config/configuration.service'; +import SheetService from '../../utils/google-sheets/sheet.service'; import { CalculTrajectoireRequestType, CalculTrajectoireReset, @@ -22,8 +22,8 @@ import { DonneesCalculTrajectoireARemplirType } from '../models/donnees-calcul-t import { IndicateurDefinitionType } from '../models/indicateur-definition.table'; import { CreateIndicateurValeurType } from '../models/indicateur-valeur.table'; import { VerificationTrajectoireStatus } from '../models/verification-trajectoire.response'; -import IndicateursService from './indicateurs.service'; import IndicateurSourcesService from './indicateur-sources.service'; +import IndicateursService from './indicateurs.service'; import TrajectoiresDataService from './trajectoires-data.service'; @Injectable() @@ -261,7 +261,7 @@ export default class TrajectoiresSpreadsheetService { // Ecriture des informations d'émission GES const emissionGesSpreadsheetData = resultatVerification.donneesEntree!.emissionsGes.valeurs.map((valeur) => [ - (valeur.valeur || 0), + valeur.valeur || 0, ]); await this.sheetService.overwriteRawDataToSheet( trajectoireCalculSheetId, @@ -273,7 +273,7 @@ export default class TrajectoiresSpreadsheetService { // Les valeurs de séquestration sont positives en base quand il y a une séquestration mais doivent être écrites avec le signe opposé const sequestrationSpreadsheetData = resultatVerification.donneesEntree!.sequestrations.valeurs.map( - (valeur) => [((valeur.valeur || 0) * -1)] + (valeur) => [(valeur.valeur || 0) * -1] ); await this.sheetService.overwriteRawDataToSheet( trajectoireCalculSheetId, diff --git a/backend/src/indicateurs/services/trajectoires-xlsx.service.ts b/backend/src/indicateurs/services/trajectoires-xlsx.service.ts index 39fcbc1b89..703fd41903 100644 --- a/backend/src/indicateurs/services/trajectoires-xlsx.service.ts +++ b/backend/src/indicateurs/services/trajectoires-xlsx.service.ts @@ -7,10 +7,10 @@ import { import { NextFunction, Response } from 'express'; import { default as XlsxTemplate } from 'xlsx-template'; import { AuthenticatedUser } from '../../auth/models/auth.models'; -import { CollectiviteRequestType } from '../../collectivites/models/collectivite.request'; -import { EpciType } from '../../collectivites/models/epci.table'; -import BackendConfigurationService from '../../config/configuration.service'; -import SheetService from '../../spreadsheets/services/sheet.service'; +import { CollectiviteRequestType } from '../../collectivites/collectivite.request'; +import { EpciType } from '../../collectivites/shared/models/epci.table'; +import BackendConfigurationService from '../../utils/config/configuration.service'; +import SheetService from '../../utils/google-sheets/sheet.service'; import { DonneesCalculTrajectoireARemplirType } from '../models/donnees-calcul-trajectoire-a-remplir.dto'; import { ModeleTrajectoireTelechargementRequestType } from '../models/modele-trajectoire-telechargement.request'; import { VerificationTrajectoireStatus } from '../models/verification-trajectoire.response'; @@ -162,14 +162,14 @@ export default class TrajectoiresXlsxService { valeur.identifiantsReferentiel ); emissionGesSequestrationConsommationsSubstitionValeurs[cleSubstitution] = - (valeur.valeur || 0); + valeur.valeur || 0; }); valeurIndicateurs?.sequestrations.valeurs.forEach((valeur) => { const cleSubstitution = this.getXlsxCleSubstitution( valeur.identifiantsReferentiel ); emissionGesSequestrationConsommationsSubstitionValeurs[cleSubstitution] = - ((valeur.valeur || 0) * -1); + (valeur.valeur || 0) * -1; }); valeurIndicateurs?.consommationsFinales.valeurs.forEach((valeur) => { const cleSubstitution = this.getXlsxCleSubstitution( diff --git a/backend/src/main.ts b/backend/src/main.ts index 430da40427..c9b049d939 100644 --- a/backend/src/main.ts +++ b/backend/src/main.ts @@ -1,21 +1,21 @@ // WARNING: Do this import first -import './common/services/sentry.service'; +import './utils/sentry-init'; // Other imports import { patchNestjsSwagger, ZodValidationPipe } from '@anatine/zod-nestjs'; import { Logger } from '@nestjs/common'; import { HttpAdapterHost, NestFactory } from '@nestjs/core'; import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'; import { AppModule } from './app.module'; -import { AllExceptionsFilter } from './common/filters/all-exceptions.filter'; -import { initApplicationCredentials } from './common/services/gcloud.helper'; -import { TrpcRouter } from './trpc/trpc.router'; +import { initGoogleCloudCredentials } from './utils/google-sheets/gcloud.helper'; +import { AllExceptionsFilter } from './utils/nest/all-exceptions.filter'; +import { TrpcRouter } from './utils/trpc/trpc.router'; const logger = new Logger('main'); const port = process.env.PORT || 8080; logger.log(`Launching NestJS app on port ${port}`); async function bootstrap() { - initApplicationCredentials(); + initGoogleCloudCredentials(); const app = await NestFactory.create(AppModule, { logger: ['fatal', 'error', 'warn', 'log'], // No debug by default diff --git a/backend/src/personnalisations/models/historique-reponse-binaire.table.ts b/backend/src/personnalisations/models/historique-reponse-binaire.table.ts index 844bba1b12..267126ba52 100644 --- a/backend/src/personnalisations/models/historique-reponse-binaire.table.ts +++ b/backend/src/personnalisations/models/historique-reponse-binaire.table.ts @@ -1,6 +1,6 @@ import { sql } from 'drizzle-orm'; import { boolean, integer, timestamp, varchar } from 'drizzle-orm/pg-core'; -import { collectiviteTable } from '../../collectivites/models/collectivite.table'; +import { collectiviteTable } from '../../collectivites/shared/models/collectivite.table'; import { historiqueSchema } from './historique-reponse-choix.table'; export const historiqueReponseBinaireTable = historiqueSchema.table( diff --git a/backend/src/personnalisations/models/historique-reponse-choix.table.ts b/backend/src/personnalisations/models/historique-reponse-choix.table.ts index 67ed56d4ee..f249b42745 100644 --- a/backend/src/personnalisations/models/historique-reponse-choix.table.ts +++ b/backend/src/personnalisations/models/historique-reponse-choix.table.ts @@ -1,6 +1,6 @@ import { sql } from 'drizzle-orm'; import { integer, pgSchema, timestamp, varchar } from 'drizzle-orm/pg-core'; -import { collectiviteTable } from '../../collectivites/models/collectivite.table'; +import { collectiviteTable } from '../../collectivites/shared/models/collectivite.table'; export const historiqueSchema = pgSchema('historique'); export const historiqueReponseChoixTable = historiqueSchema.table( diff --git a/backend/src/personnalisations/models/historique-reponse-proportion.table.ts b/backend/src/personnalisations/models/historique-reponse-proportion.table.ts index fbe93bb74d..b93b4a300d 100644 --- a/backend/src/personnalisations/models/historique-reponse-proportion.table.ts +++ b/backend/src/personnalisations/models/historique-reponse-proportion.table.ts @@ -5,7 +5,7 @@ import { timestamp, varchar, } from 'drizzle-orm/pg-core'; -import { collectiviteTable } from '../../collectivites/models/collectivite.table'; +import { collectiviteTable } from '../../collectivites/shared/models/collectivite.table'; import { historiqueSchema } from './historique-reponse-choix.table'; export const historiqueReponseProportionTable = historiqueSchema.table( diff --git a/backend/src/personnalisations/models/personnalisation-regle.table.ts b/backend/src/personnalisations/models/personnalisation-regle.table.ts index 151c1ca3f5..fa1557ba37 100644 --- a/backend/src/personnalisations/models/personnalisation-regle.table.ts +++ b/backend/src/personnalisations/models/personnalisation-regle.table.ts @@ -1,4 +1,4 @@ -import { modifiedAt } from '@/backend/utils'; +import { modifiedAt } from '@/domain/utils'; import { InferInsertModel, InferSelectModel } from 'drizzle-orm'; import { pgEnum, pgTable, primaryKey, text } from 'drizzle-orm/pg-core'; import { createInsertSchema, createSelectSchema } from 'drizzle-zod'; diff --git a/backend/src/personnalisations/models/reponse-binaire.table.ts b/backend/src/personnalisations/models/reponse-binaire.table.ts index ca2177877f..77704f35a7 100644 --- a/backend/src/personnalisations/models/reponse-binaire.table.ts +++ b/backend/src/personnalisations/models/reponse-binaire.table.ts @@ -1,6 +1,6 @@ -import { modifiedAt } from '@/backend/utils'; +import { modifiedAt } from '@/domain/utils'; import { boolean, integer, pgTable, varchar } from 'drizzle-orm/pg-core'; -import { collectiviteTable } from '../../collectivites/models/collectivite.table'; +import { collectiviteTable } from '../../collectivites/shared/models/collectivite.table'; export const reponseBinaireTable = pgTable('reponse_binaire', { modifiedAt, diff --git a/backend/src/personnalisations/models/reponse-choix.table.ts b/backend/src/personnalisations/models/reponse-choix.table.ts index 7adb0253a5..b561bcd56c 100644 --- a/backend/src/personnalisations/models/reponse-choix.table.ts +++ b/backend/src/personnalisations/models/reponse-choix.table.ts @@ -1,6 +1,6 @@ -import { modifiedAt } from '@/backend/utils'; +import { modifiedAt } from '@/domain/utils'; import { integer, pgTable, varchar } from 'drizzle-orm/pg-core'; -import { collectiviteTable } from '../../collectivites/models/collectivite.table'; +import { collectiviteTable } from '../../collectivites/shared/models/collectivite.table'; export const reponseChoixTable = pgTable('reponse_choix', { modifiedAt, diff --git a/backend/src/personnalisations/models/reponse-proportion.table.ts b/backend/src/personnalisations/models/reponse-proportion.table.ts index 4e0ebae1ba..7f908efb8f 100644 --- a/backend/src/personnalisations/models/reponse-proportion.table.ts +++ b/backend/src/personnalisations/models/reponse-proportion.table.ts @@ -1,11 +1,11 @@ -import { modifiedAt } from '@/backend/utils'; +import { modifiedAt } from '@/domain/utils'; import { doublePrecision, integer, pgTable, varchar, } from 'drizzle-orm/pg-core'; -import { collectiviteTable } from '../../collectivites/models/collectivite.table'; +import { collectiviteTable } from '../../collectivites/shared/models/collectivite.table'; export const reponseProportionTable = pgTable('reponse_proportion', { modifiedAt, diff --git a/backend/src/personnalisations/personnalisations.module.ts b/backend/src/personnalisations/personnalisations.module.ts index 0cbbd90cd5..9f8a90ddf0 100644 --- a/backend/src/personnalisations/personnalisations.module.ts +++ b/backend/src/personnalisations/personnalisations.module.ts @@ -1,13 +1,12 @@ import { Module } from '@nestjs/common'; import { AuthModule } from '../auth/auth.module'; import { CollectivitesModule } from '../collectivites/collectivites.module'; -import { CommonModule } from '../common/common.module'; import { PersonnalisationsController } from './controllers/personnalisations.controller'; import ExpressionParserService from './services/expression-parser.service'; import PersonnalisationsService from './services/personnalisations-service'; @Module({ - imports: [CommonModule, CollectivitesModule, AuthModule], + imports: [CollectivitesModule, AuthModule], providers: [ExpressionParserService, PersonnalisationsService], exports: [ExpressionParserService, PersonnalisationsService], controllers: [PersonnalisationsController], diff --git a/backend/src/personnalisations/services/expression-parser.service.spec.ts b/backend/src/personnalisations/services/expression-parser.service.spec.ts index c890520417..cd48cd5f55 100644 --- a/backend/src/personnalisations/services/expression-parser.service.spec.ts +++ b/backend/src/personnalisations/services/expression-parser.service.spec.ts @@ -2,7 +2,7 @@ import { Test } from '@nestjs/testing'; import { CollectivitePopulationTypeEnum, CollectiviteTypeEnum, -} from '../../collectivites/models/identite-collectivite.dto'; +} from '../../collectivites/identite-collectivite.dto'; import ExpressionParserService from './expression-parser.service'; describe('ExpressionParserService', () => { @@ -256,8 +256,8 @@ describe('ExpressionParserService', () => { le score de la 1.2.3 est réduit à 2 points. */ - const expression = `si reponse(dechets_1, OUI) et reponse(dechets_2, OUI) et reponse(dechets_3, OUI) alors 1.0 -sinon si reponse(dechets_1, NON) et reponse(dechets_2, NON) et reponse(dechets_3, NON) alors 2/12 + const expression = `si reponse(dechets_1, OUI) et reponse(dechets_2, OUI) et reponse(dechets_3, OUI) alors 1.0 +sinon si reponse(dechets_1, NON) et reponse(dechets_2, NON) et reponse(dechets_3, NON) alors 2/12 sinon 0.75`; expect(() => expressionParserService.parseAndEvaluateExpression(expression) @@ -331,12 +331,12 @@ sinon 0.75`; Ces réductions sont cumulables dans la limite de 2 points restants pour prendre en compte la part d’influence dans les instances compétentes et les actions partenariales. */ - const expression = `si reponse(AOD_elec, OUI) et reponse(AOD_gaz, OUI) et reponse(AOD_chaleur, OUI) alors 1.0 -sinon si reponse(AOD_elec, NON) et reponse(AOD_gaz, NON) et reponse(AOD_chaleur, NON) alors 2/10 -sinon si reponse(AOD_elec, NON) et reponse(AOD_gaz, NON) alors 4/10 -sinon si reponse(AOD_elec, NON) et reponse(AOD_chaleur, NON) alors 3/10 -sinon si reponse(AOD_gaz, NON) et reponse(AOD_chaleur, NON) alors 3/10 -sinon si reponse(AOD_elec, NON) ou reponse(AOD_gaz, NON) alors 7/10 + const expression = `si reponse(AOD_elec, OUI) et reponse(AOD_gaz, OUI) et reponse(AOD_chaleur, OUI) alors 1.0 +sinon si reponse(AOD_elec, NON) et reponse(AOD_gaz, NON) et reponse(AOD_chaleur, NON) alors 2/10 +sinon si reponse(AOD_elec, NON) et reponse(AOD_gaz, NON) alors 4/10 +sinon si reponse(AOD_elec, NON) et reponse(AOD_chaleur, NON) alors 3/10 +sinon si reponse(AOD_gaz, NON) et reponse(AOD_chaleur, NON) alors 3/10 +sinon si reponse(AOD_elec, NON) ou reponse(AOD_gaz, NON) alors 7/10 sinon si reponse(AOD_chaleur, NON) alors 6/10`; expect( diff --git a/backend/src/personnalisations/services/expression-parser.service.ts b/backend/src/personnalisations/services/expression-parser.service.ts index 9882405ddb..4ff7403c0a 100644 --- a/backend/src/personnalisations/services/expression-parser.service.ts +++ b/backend/src/personnalisations/services/expression-parser.service.ts @@ -7,7 +7,7 @@ import { tokenMatcher, } from 'chevrotain'; import * as _ from 'lodash'; -import { IdentiteCollectivite } from '../../collectivites/models/identite-collectivite.dto'; +import { IdentiteCollectivite } from '../../collectivites/identite-collectivite.dto'; // Define all the tokens used in the grammar const VRAI = createToken({ name: 'VRAI', pattern: /VRAI/ }); diff --git a/backend/src/personnalisations/services/personnalisations-service.ts b/backend/src/personnalisations/services/personnalisations-service.ts index 84c9a5028d..bc8ac5cdcb 100644 --- a/backend/src/personnalisations/services/personnalisations-service.ts +++ b/backend/src/personnalisations/services/personnalisations-service.ts @@ -1,12 +1,15 @@ +import { PermissionOperation } from '@/backend/auth/authorizations/permission-operation.enum'; +import { PermissionService } from '@/backend/auth/authorizations/permission.service'; +import { ResourceType } from '@/backend/auth/authorizations/resource-type.enum'; import { Injectable, Logger } from '@nestjs/common'; import { and, asc, desc, eq, like, lte, SQL, SQLWrapper } from 'drizzle-orm'; import { AuthenticatedUser } from '../../auth/models/auth.models'; import { CollectiviteAvecType, IdentiteCollectivite, -} from '../../collectivites/models/identite-collectivite.dto'; +} from '../../collectivites/identite-collectivite.dto'; import CollectivitesService from '../../collectivites/services/collectivites.service'; -import DatabaseService from '../../common/services/database.service'; +import { DatabaseService } from '../../utils/database/database.service'; import { GetPersonnalisationConsequencesRequestType } from '../models/get-personnalisation-consequences.request'; import { GetPersonnalitionConsequencesResponseType } from '../models/get-personnalisation-consequences.response'; import { GetPersonnalisationReglesResponseType } from '../models/get-personnalisation-regles.response'; @@ -22,9 +25,6 @@ import { reponseBinaireTable } from '../models/reponse-binaire.table'; import { reponseChoixTable } from '../models/reponse-choix.table'; import { reponseProportionTable } from '../models/reponse-proportion.table'; import ExpressionParserService from './expression-parser.service'; -import { PermissionService } from '@/backend/auth/authorizations/permission.service'; -import { PermissionOperation } from '@/backend/auth/authorizations/permission-operation.enum'; -import { ResourceType } from '@/backend/auth/authorizations/resource-type.enum'; export type ReponseTables = | typeof reponseBinaireTable diff --git a/backend/src/plans/fiches/axe.service.ts b/backend/src/plans/fiches/axe.service.ts new file mode 100644 index 0000000000..b92731e39a --- /dev/null +++ b/backend/src/plans/fiches/axe.service.ts @@ -0,0 +1,69 @@ +import { Injectable, Logger } from '@nestjs/common'; +import { DatabaseService } from '../../utils/database/database.service'; +import { axeTable, CreateAxeType } from './shared/models/axe.table'; +import { ficheActionAxeTable } from './shared/models/fiche-action-axe.table'; + +@Injectable() +export default class AxeService { + private readonly logger = new Logger(AxeService.name); + + constructor(private readonly databaseService: DatabaseService) {} + + /** + * Crée un axe + * @param axe + * @return identifiant de l'axe créé + */ + async createAxe(axe: CreateAxeType): Promise { + this.logger.log( + `Création de l'axe ${axe.nom} pour la collectivité ${axe.collectiviteId}` + ); + const axeCree = await this.databaseService.db + .insert(axeTable) + .values(axe) + .returning(); + return axeCree[0]?.id; + } + + // /** + // * Retourne l'identifiant d'un axe s'il existe déjà ou le crée + // * Un axe existe déjà si : même nom, même collectivité, et même axe parent + // * @param axe + // * @return identifiant de l'axe récupéré ou créé + // */ + // async createOrReturnAxeId(axe: CreateAxeType): Promise { + // const axeExistants = await this.databaseService.db + // .select() + // .from(axeTable) + // .where( + // and( + // eq(axeTable.nom, axe.nom.trim()), + // eq(axeTable.collectiviteId, axe.collectiviteId), + // or( + // and( + // isNull(axeTable.parent), + // isNull(axe.parent ? axe.parent : null) + // ), + // eq(axeTable.parent, axe.parent) + // ) + // ) + // ); + // const axeExistant = axeExistants?.length > 0 ? axeExistants[0] : null; + // if (!axeExistant) { + // return await this.createAxe(axe); + // } + // return axeExistant.id; + // } + + /** + * Ajoute une fiche dans un axe + * @param ficheId identifiant de la fiche + * @param axeId identifiant de l'axe + */ + async addFicheAction(ficheId: number, axeId: number): Promise { + await this.databaseService.db.insert(ficheActionAxeTable).values({ + axeId: axeId, + ficheId: ficheId, + }); + } +} diff --git a/backend/src/fiches/bulk-edit/bulk-edit.router.e2e-spec.ts b/backend/src/plans/fiches/bulk-edit/bulk-edit.router.e2e-spec.ts similarity index 92% rename from backend/src/fiches/bulk-edit/bulk-edit.router.e2e-spec.ts rename to backend/src/plans/fiches/bulk-edit/bulk-edit.router.e2e-spec.ts index 7503b27073..88607faa83 100644 --- a/backend/src/fiches/bulk-edit/bulk-edit.router.e2e-spec.ts +++ b/backend/src/plans/fiches/bulk-edit/bulk-edit.router.e2e-spec.ts @@ -1,23 +1,24 @@ -import { DatabaseService } from '@/backend/common'; -import { inferProcedureInput } from '@trpc/server'; -import { eq, inArray, sql } from 'drizzle-orm'; +import { AuthenticatedUser } from '@/backend/auth/models/auth.models'; +import { libreTagTable } from '@/backend/collectivites'; import { + getAuthUser, getTestApp, getTestDatabase, getTestRouter, -} from '../../../test/app-utils'; -import { getAuthUser } from '../../../test/auth-utils'; -import { YOLO_DODO, YULU_DUDU } from '../../../test/test-users.samples'; -import { AuthenticatedUser } from '../../auth/models/auth.models'; -import { libreTagTable } from '../../taxonomie/models/libre-tag.table'; -import { AppRouter, TrpcRouter } from '../../trpc/trpc.router'; -import { ficheActionLibreTagTable } from '../models/fiche-action-libre-tag.table'; -import { ficheActionPiloteTable } from '../models/fiche-action-pilote.table'; + YOLO_DODO, + YULU_DUDU, +} from '@/backend/test'; +import { DatabaseService } from '@/backend/utils'; +import { AppRouter, TrpcRouter } from '@/backend/utils/trpc/trpc.router'; +import { inferProcedureInput } from '@trpc/server'; +import { eq, inArray, sql } from 'drizzle-orm'; +import { ficheActionLibreTagTable } from '../shared/models/fiche-action-libre-tag.table'; +import { ficheActionPiloteTable } from '../shared/models/fiche-action-pilote.table'; import { - FicheActionStatutsEnumType, ficheActionTable, prioriteEnumSchema, -} from '../models/fiche-action.table'; + statutsEnumSchema, +} from '../shared/models/fiche-action.table'; type Input = inferProcedureInput; @@ -94,7 +95,7 @@ describe('BulkEditRouter', () => { const input1: Input = { ficheIds, - statut: FicheActionStatutsEnumType.EN_RETARD, + statut: statutsEnumSchema.enum['En retard'], }; const result = await caller.plans.fiches.bulkEdit(input1); @@ -360,7 +361,7 @@ describe('BulkEditRouter', () => { const input = { ficheIds: [...ficheIds, newFiche.id], - statut: FicheActionStatutsEnumType.EN_RETARD, + statut: statutsEnumSchema.enum['En retard'], }; await expect(() => @@ -373,7 +374,7 @@ describe('BulkEditRouter', () => { const input = { ficheIds, - statut: FicheActionStatutsEnumType.EN_RETARD, + statut: statutsEnumSchema.Enum['En retard'], }; await expect(() => diff --git a/backend/src/fiches/bulk-edit/bulk-edit.router.ts b/backend/src/plans/fiches/bulk-edit/bulk-edit.router.ts similarity index 88% rename from backend/src/fiches/bulk-edit/bulk-edit.router.ts rename to backend/src/plans/fiches/bulk-edit/bulk-edit.router.ts index 6088fd0f22..6c078679b0 100644 --- a/backend/src/fiches/bulk-edit/bulk-edit.router.ts +++ b/backend/src/plans/fiches/bulk-edit/bulk-edit.router.ts @@ -1,5 +1,5 @@ import { Injectable } from '@nestjs/common'; -import { TrpcService } from '../../trpc/trpc.service'; +import { TrpcService } from '@/backend/utils/trpc/trpc.service'; import { BulkEditService } from './bulk-edit.service'; @Injectable() diff --git a/backend/src/fiches/bulk-edit/bulk-edit.service.ts b/backend/src/plans/fiches/bulk-edit/bulk-edit.service.ts similarity index 82% rename from backend/src/fiches/bulk-edit/bulk-edit.service.ts rename to backend/src/plans/fiches/bulk-edit/bulk-edit.service.ts index df0e739361..961d8ddae3 100644 --- a/backend/src/fiches/bulk-edit/bulk-edit.service.ts +++ b/backend/src/plans/fiches/bulk-edit/bulk-edit.service.ts @@ -1,18 +1,18 @@ +import { PermissionOperation } from '@/backend/auth/authorizations/permission-operation.enum'; +import { PermissionService } from '@/backend/auth/authorizations/permission.service'; +import { ResourceType } from '@/backend/auth/authorizations/resource-type.enum'; import { AuthUser } from '@/backend/auth/models/auth.models'; -import { DatabaseService } from '@/backend/common'; +import { + ficheActionLibreTagTable, + ficheActionTable, + ficheSchema, +} from '@/backend/plans/fiches'; +import { editFicheRequestSchema } from '@/backend/plans/fiches/shared/edit-fiche.request'; +import { DatabaseService } from '@/backend/utils'; import { Injectable } from '@nestjs/common'; import { and, inArray, or } from 'drizzle-orm'; import z from 'zod'; -import { ficheActionLibreTagTable } from '../models/fiche-action-libre-tag.table'; -import { ficheActionPiloteTable } from '../models/fiche-action-pilote.table'; -import { - ficheActionSchema, - ficheActionTable, -} from '../models/fiche-action.table'; -import { updateFicheActionRequestSchema } from '../models/update-fiche-action.request'; -import { PermissionService } from '@/backend/auth/authorizations/permission.service'; -import { PermissionOperation } from '@/backend/auth/authorizations/permission-operation.enum'; -import { ResourceType } from '@/backend/auth/authorizations/resource-type.enum'; +import { ficheActionPiloteTable } from '../shared/models/fiche-action-pilote.table'; @Injectable() export class BulkEditService { @@ -24,18 +24,15 @@ export class BulkEditService { ) {} bulkEditRequestSchema = z.object({ - ficheIds: ficheActionSchema.shape.id.array(), - statut: ficheActionSchema.shape.statut.optional(), - priorite: ficheActionSchema.shape.priorite.optional(), - dateFin: ficheActionSchema.shape.dateFin.optional(), - ameliorationContinue: - ficheActionSchema.shape.ameliorationContinue.optional(), - - pilotes: listSchema( - updateFicheActionRequestSchema.shape.pilotes.unwrap().unwrap() - ), + ficheIds: ficheSchema.shape.id.array(), + statut: ficheSchema.shape.statut.optional(), + priorite: ficheSchema.shape.priorite.optional(), + dateFin: ficheSchema.shape.dateFin.optional(), + ameliorationContinue: ficheSchema.shape.ameliorationContinue.optional(), + + pilotes: listSchema(editFicheRequestSchema.shape.pilotes.unwrap().unwrap()), libreTags: listSchema( - updateFicheActionRequestSchema.shape.libresTag.unwrap().unwrap() + editFicheRequestSchema.shape.libresTag.unwrap().unwrap() ), }); diff --git a/backend/src/fiches/count-by-statut/count-by-statut.router.e2e-spec.ts b/backend/src/plans/fiches/count-by-statut/count-by-statut.router.e2e-spec.ts similarity index 75% rename from backend/src/fiches/count-by-statut/count-by-statut.router.e2e-spec.ts rename to backend/src/plans/fiches/count-by-statut/count-by-statut.router.e2e-spec.ts index e6ce519dc1..933ef7e098 100644 --- a/backend/src/fiches/count-by-statut/count-by-statut.router.e2e-spec.ts +++ b/backend/src/plans/fiches/count-by-statut/count-by-statut.router.e2e-spec.ts @@ -1,9 +1,9 @@ +import { AuthenticatedUser } from '@/backend/auth/models/auth.models'; +import { getAuthUser, getTestRouter } from '@/backend/test'; +import { AppRouter } from '@/backend/utils'; +import { TrpcRouter } from '@/backend/utils/trpc/trpc.router'; import { inferProcedureInput } from '@trpc/server'; -import { getTestRouter } from '../../../test/app-utils'; -import { getAuthUser } from '../../../test/auth-utils'; -import { AppRouter, TrpcRouter } from '../../trpc/trpc.router'; -import { FicheActionStatutsEnumType } from '../models/fiche-action.table'; -import { AuthenticatedUser } from './../../auth/models/auth.models'; +import { statutsEnumValues } from '../shared/models/fiche-action.table'; type Input = inferProcedureInput; @@ -27,7 +27,7 @@ describe('CountByStatutRouter', () => { const result = await caller.plans.fiches.countByStatut(input); expect(result).toMatchObject({}); - for (const statut of Object.values(FicheActionStatutsEnumType)) { + for (const statut of statutsEnumValues) { expect(result[statut]).toMatchObject({ valeur: expect.any(String), count: expect.any(Number), diff --git a/backend/src/fiches/count-by-statut/count-by-statut.router.ts b/backend/src/plans/fiches/count-by-statut/count-by-statut.router.ts similarity index 74% rename from backend/src/fiches/count-by-statut/count-by-statut.router.ts rename to backend/src/plans/fiches/count-by-statut/count-by-statut.router.ts index 95e9aea06c..56f1b1417a 100644 --- a/backend/src/fiches/count-by-statut/count-by-statut.router.ts +++ b/backend/src/plans/fiches/count-by-statut/count-by-statut.router.ts @@ -1,12 +1,12 @@ +import { fetchFichesFilterRequestSchema } from '@/backend/plans/fiches/shared/fetch-fiches-filter.request'; +import { TrpcService } from '@/backend/utils/trpc/trpc.service'; import { Injectable } from '@nestjs/common'; import { z } from 'zod'; -import { getFichesActionFilterRequestSchema } from '../models/get-fiches-actions-filter.request'; -import { TrpcService } from '../../trpc/trpc.service'; import { CountByStatutService } from './count-by-statut.service'; const inputSchema = z.object({ collectiviteId: z.number(), - filter: getFichesActionFilterRequestSchema, + filter: fetchFichesFilterRequestSchema, }); @Injectable() diff --git a/backend/src/fiches/count-by-statut/count-by-statut.service.ts b/backend/src/plans/fiches/count-by-statut/count-by-statut.service.ts similarity index 90% rename from backend/src/fiches/count-by-statut/count-by-statut.service.ts rename to backend/src/plans/fiches/count-by-statut/count-by-statut.service.ts index f4d8615172..f170db3249 100644 --- a/backend/src/fiches/count-by-statut/count-by-statut.service.ts +++ b/backend/src/plans/fiches/count-by-statut/count-by-statut.service.ts @@ -1,3 +1,15 @@ +import { + axeTable, + ficheActionPartenaireTagTable, + ficheActionServiceTagTable, + ficheActionTable, + SANS_STATUT_FICHE_ACTION_SYNTHESE_KEY, + statutsEnumValues, +} from '@/backend/plans/fiches'; +import { GetFichesActionFilterRequestType } from '@/backend/plans/fiches/shared/fetch-fiches-filter.request'; +import { DatabaseService } from '@/backend/utils'; +import { CountByRecordType } from '@/backend/utils/count-by.dto'; +import { getModifiedSinceDate } from '@/backend/utils/modified-since.enum'; import { Injectable, Logger } from '@nestjs/common'; import { and, @@ -12,20 +24,8 @@ import { SQLWrapper, } from 'drizzle-orm'; import { PgColumn } from 'drizzle-orm/pg-core'; -import { CountByRecordType } from '../../common/models/count-synthese.dto'; -import { getModifiedSinceDate } from '../../common/models/modified-since.enum'; -import DatabaseService from '../../common/services/database.service'; -import { axeTable } from '../models/axe.table'; -import { ficheActionAxeTable } from '../models/fiche-action-axe.table'; -import { ficheActionPartenaireTagTable } from '../models/fiche-action-partenaire-tag.table'; -import { ficheActionPiloteTable } from '../models/fiche-action-pilote.table'; -import { ficheActionServiceTagTable } from '../models/fiche-action-service.table'; -import { - FicheActionStatutsEnumType, - ficheActionTable, - SANS_STATUT_FICHE_ACTION_SYNTHESE_KEY, -} from '../models/fiche-action.table'; -import { GetFichesActionFilterRequestType } from '../models/get-fiches-actions-filter.request'; +import { ficheActionAxeTable } from '../shared/models/fiche-action-axe.table'; +import { ficheActionPiloteTable } from '../shared/models/fiche-action-pilote.table'; @Injectable() export class CountByStatutService { @@ -36,9 +36,7 @@ export class CountByStatutService { private readonly FICHE_ACTION_PARTENAIRE_TAGS_QUERY_FIELD = 'partenaire_tag_ids'; - constructor( - private readonly databaseService: DatabaseService - ) {} + constructor(private readonly databaseService: DatabaseService) {} async countByStatut( collectiviteId: number, @@ -50,7 +48,7 @@ export class CountByStatutService { )}` ); - const listeValeurs = Object.values(FicheActionStatutsEnumType); + const listeValeurs = statutsEnumValues; const conditions = this.getConditions(collectiviteId, filter); const result = await this.countBy( @@ -235,7 +233,7 @@ export class CountByStatutService { private async countBy( propriete: PgColumn, conditions: (SQLWrapper | SQL)[], - values: Value[], + values: readonly Value[], nullValue?: NullValue ) { const ficheActionPartenaireTags = this.getFicheActionPartenaireTagsQuery(); diff --git a/backend/src/fiches/fiche-action-etape/fiche-action-etape.router.e2e-spec.ts b/backend/src/plans/fiches/fiche-action-etape/fiche-action-etape.router.e2e-spec.ts similarity index 93% rename from backend/src/fiches/fiche-action-etape/fiche-action-etape.router.e2e-spec.ts rename to backend/src/plans/fiches/fiche-action-etape/fiche-action-etape.router.e2e-spec.ts index e5409ae361..58f4fd0030 100644 --- a/backend/src/fiches/fiche-action-etape/fiche-action-etape.router.e2e-spec.ts +++ b/backend/src/plans/fiches/fiche-action-etape/fiche-action-etape.router.e2e-spec.ts @@ -1,14 +1,14 @@ -import { inferProcedureInput } from '@trpc/server'; -import { eq } from 'drizzle-orm'; +import { AuthenticatedUser } from '@/backend/auth/models/auth.models'; import { + getAuthUser, getTestApp, getTestDatabase, getTestRouter, -} from '../../../test/app-utils'; -import { getAuthUser } from '../../../test/auth-utils'; -import DatabaseService from '../../common/services/database.service'; -import { AppRouter, TrpcRouter } from '../../trpc/trpc.router'; -import { AuthenticatedUser } from './../../auth/models/auth.models'; +} from '@/backend/test'; +import { AppRouter, DatabaseService } from '@/backend/utils'; +import { TrpcRouter } from '@/backend/utils/trpc/trpc.router'; +import { inferProcedureInput } from '@trpc/server'; +import { eq } from 'drizzle-orm'; import { ficheActionEtapeTable } from './fiche-action-etape.table'; type upsertInput = inferProcedureInput< diff --git a/backend/src/fiches/fiche-action-etape/fiche-action-etape.router.ts b/backend/src/plans/fiches/fiche-action-etape/fiche-action-etape.router.ts similarity index 85% rename from backend/src/fiches/fiche-action-etape/fiche-action-etape.router.ts rename to backend/src/plans/fiches/fiche-action-etape/fiche-action-etape.router.ts index 48956a6cad..05e0940987 100644 --- a/backend/src/fiches/fiche-action-etape/fiche-action-etape.router.ts +++ b/backend/src/plans/fiches/fiche-action-etape/fiche-action-etape.router.ts @@ -1,8 +1,8 @@ +import { TrpcService } from '@/backend/utils/trpc/trpc.service'; import { Injectable } from '@nestjs/common'; -import { upsertFicheActionEtapeSchema } from '@/backend/fiches/fiche-action-etape/fiche-action-etape.table'; import { z } from 'zod'; -import { TrpcService } from '../../trpc/trpc.service'; import { FicheActionEtapeService } from './fiche-action-etape.service'; +import { upsertFicheActionEtapeSchema } from './fiche-action-etape.table'; @Injectable() export class FicheActionEtapeRouter { diff --git a/backend/src/fiches/fiche-action-etape/fiche-action-etape.service.ts b/backend/src/plans/fiches/fiche-action-etape/fiche-action-etape.service.ts similarity index 96% rename from backend/src/fiches/fiche-action-etape/fiche-action-etape.service.ts rename to backend/src/plans/fiches/fiche-action-etape/fiche-action-etape.service.ts index faa1b913e1..be9451760b 100644 --- a/backend/src/fiches/fiche-action-etape/fiche-action-etape.service.ts +++ b/backend/src/plans/fiches/fiche-action-etape/fiche-action-etape.service.ts @@ -1,8 +1,8 @@ +import { AuthenticatedUser } from '@/backend/auth/models/auth.models'; +import { DatabaseService } from '@/backend/utils'; import { Injectable } from '@nestjs/common'; import { and, eq, gt, gte, lt, lte, sql } from 'drizzle-orm'; -import { AuthenticatedUser } from '../../auth/models/auth.models'; -import DatabaseService from '../../common/services/database.service'; -import FicheService from '../services/fiche.service'; +import FicheService from '../fiche.service'; import { ficheActionEtapeTable, FicheActionEtapeType, diff --git a/backend/src/fiches/fiche-action-etape/fiche-action-etape.table.ts b/backend/src/plans/fiches/fiche-action-etape/fiche-action-etape.table.ts similarity index 91% rename from backend/src/fiches/fiche-action-etape/fiche-action-etape.table.ts rename to backend/src/plans/fiches/fiche-action-etape/fiche-action-etape.table.ts index bc29238b6d..1b1a1f1ab0 100644 --- a/backend/src/fiches/fiche-action-etape/fiche-action-etape.table.ts +++ b/backend/src/plans/fiches/fiche-action-etape/fiche-action-etape.table.ts @@ -1,9 +1,9 @@ -import { createdAt, createdBy, modifiedAt, modifiedBy } from '@/backend/utils'; +import { createdAt, createdBy, modifiedAt, modifiedBy } from '@/domain/utils'; import { InferSelectModel } from 'drizzle-orm'; import { boolean, integer, pgTable, serial, text } from 'drizzle-orm/pg-core'; import { createInsertSchema } from 'drizzle-zod'; import { z } from 'zod'; -import { ficheActionTable } from '../models/fiche-action.table'; +import { ficheActionTable } from '../shared/models/fiche-action.table'; export const ficheActionEtapeTable = pgTable('fiche_action_etape', { id: serial('id').primaryKey(), diff --git a/backend/src/fiches/controllers/fiche-action-update.e2e-spec.ts b/backend/src/plans/fiches/fiche-action-update.e2e-spec.ts similarity index 91% rename from backend/src/fiches/controllers/fiche-action-update.e2e-spec.ts rename to backend/src/plans/fiches/fiche-action-update.e2e-spec.ts index 8bc64fd605..3175d29021 100644 --- a/backend/src/fiches/controllers/fiche-action-update.e2e-spec.ts +++ b/backend/src/plans/fiches/fiche-action-update.e2e-spec.ts @@ -1,32 +1,13 @@ +import { libreTagTable } from '@/backend/collectivites'; import { INestApplication } from '@nestjs/common'; import { eq } from 'drizzle-orm'; import { default as request } from 'supertest'; import { describe, expect, it } from 'vitest'; import { getTestApp } from '../../../test/app-utils'; import { getAuthToken } from '../../../test/auth-utils'; -import DatabaseService from '../../common/services/database.service'; -import { libreTagTable } from '../../taxonomie/models/libre-tag.table'; -import { ficheActionActionTable } from '../models/fiche-action-action.table'; -import { ficheActionAxeTable } from '../models/fiche-action-axe.table'; -import { ficheActionEffetAttenduTable } from '../models/fiche-action-effet-attendu.table'; -import { ficheActionFinanceurTagTable } from '../models/fiche-action-financeur-tag.table'; -import { ficheActionIndicateurTable } from '../models/fiche-action-indicateur.table'; -import { ficheActionLibreTagTable } from '../models/fiche-action-libre-tag.table'; -import { ficheActionLienTable } from '../models/fiche-action-lien.table'; -import { ficheActionPartenaireTagTable } from '../models/fiche-action-partenaire-tag.table'; -import { ficheActionPiloteTable } from '../models/fiche-action-pilote.table'; -import { ficheActionReferentTable } from '../models/fiche-action-referent.table'; -import { ficheActionServiceTagTable } from '../models/fiche-action-service.table'; -import { ficheActionSousThematiqueTable } from '../models/fiche-action-sous-thematique.table'; -import { ficheActionStructureTagTable } from '../models/fiche-action-structure-tag.table'; -import { ficheActionThematiqueTable } from '../models/fiche-action-thematique.table'; -import { - FicheActionCiblesEnumType, - FicheActionStatutsEnumType, - ficheActionTable, - piliersEciEnumType, -} from '../models/fiche-action.table'; -import { UpdateFicheActionRequestType } from '../models/update-fiche-action.request'; +import { DatabaseService } from '../../utils/database/database.service'; +import { UpdateFicheActionRequestClass } from './fiches-action.controller'; +import { UpdateFicheActionRequestType } from './shared/edit-fiche.request'; import { actionsFixture, axesFixture, @@ -42,9 +23,28 @@ import { sousThematiquesFixture, structuresFixture, thematiquesFixture, -} from '../shared/fixtures/fiche-action-relations.fixture'; -import { ficheActionFixture } from '../shared/fixtures/fiche-action.fixture'; -import { UpdateFicheActionRequestClass } from './fiches-action.controller'; +} from './shared/fixtures/fiche-action-relations.fixture'; +import { ficheActionFixture } from './shared/fixtures/fiche-action.fixture'; +import { ficheActionActionTable } from './shared/models/fiche-action-action.table'; +import { ficheActionAxeTable } from './shared/models/fiche-action-axe.table'; +import { ficheActionEffetAttenduTable } from './shared/models/fiche-action-effet-attendu.table'; +import { ficheActionFinanceurTagTable } from './shared/models/fiche-action-financeur-tag.table'; +import { ficheActionIndicateurTable } from './shared/models/fiche-action-indicateur.table'; +import { ficheActionLibreTagTable } from './shared/models/fiche-action-libre-tag.table'; +import { ficheActionLienTable } from './shared/models/fiche-action-lien.table'; +import { ficheActionPartenaireTagTable } from './shared/models/fiche-action-partenaire-tag.table'; +import { ficheActionPiloteTable } from './shared/models/fiche-action-pilote.table'; +import { ficheActionReferentTable } from './shared/models/fiche-action-referent.table'; +import { ficheActionServiceTagTable } from './shared/models/fiche-action-service-tag.table'; +import { ficheActionSousThematiqueTable } from './shared/models/fiche-action-sous-thematique.table'; +import { ficheActionStructureTagTable } from './shared/models/fiche-action-structure-tag.table'; +import { ficheActionThematiqueTable } from './shared/models/fiche-action-thematique.table'; +import { + ciblesEnumSchema, + ficheActionTable, + piliersEciEnumType, + statutsEnumSchema, +} from './shared/models/fiche-action.table'; const collectiviteId = 1; const ficheActionId = 9999; @@ -208,13 +208,13 @@ describe('FichesActionUpdateService', () => { objectifs: 'Diminution de 15% de la consommation de feuilles de papier / Indicateurs : Nombre de papiers', cibles: [ - FicheActionCiblesEnumType.GRAND_PUBLIC, - FicheActionCiblesEnumType.ASSOCIATIONS, + ciblesEnumSchema.enum['Grand public'], + ciblesEnumSchema.enum['Associations'], ], ressources: 'Service numérique', financements: 'De 40 000€ à 100 000€', budgetPrevisionnel: '35000', - statut: FicheActionStatutsEnumType.EN_PAUSE, + statut: statutsEnumSchema.enum['En pause'], ameliorationContinue: false, calendrier: 'Calendrier prévisionnel', notesComplementaires: 'Vive le vélo !', diff --git a/backend/src/fiches/services/fiche.service.ts b/backend/src/plans/fiches/fiche.service.ts similarity index 79% rename from backend/src/fiches/services/fiche.service.ts rename to backend/src/plans/fiches/fiche.service.ts index 6711f8ef40..4f095a8f0b 100644 --- a/backend/src/fiches/services/fiche.service.ts +++ b/backend/src/plans/fiches/fiche.service.ts @@ -1,24 +1,23 @@ +import { dcpTable } from '@/backend/auth'; +import { PermissionOperation } from '@/backend/auth/authorizations/permission-operation.enum'; +import { PermissionService } from '@/backend/auth/authorizations/permission.service'; +import { ResourceType } from '@/backend/auth/authorizations/resource-type.enum'; import { Injectable, Logger } from '@nestjs/common'; import { aliasedTable, desc, eq } from 'drizzle-orm'; import { AuthenticatedUser } from '../../auth/models/auth.models'; -import DatabaseService from '../../common/services/database.service'; -import TagService from '../../taxonomie/services/tag.service'; -import { actionImpactFicheActionTable } from '../models/action-impact-fiche-action.table'; -import { ficheActionActionTable } from '../models/fiche-action-action.table'; -import { ficheActionEffetAttenduTable } from '../models/fiche-action-effet-attendu.table'; -import { ficheActionIndicateurTable } from '../models/fiche-action-indicateur.table'; -import { ficheActionNoteTable } from '../models/fiche-action-note.table'; -import { ficheActionPartenaireTagTable } from '../models/fiche-action-partenaire-tag.table'; -import { ficheActionSousThematiqueTable } from '../models/fiche-action-sous-thematique.table'; -import { ficheActionThematiqueTable } from '../models/fiche-action-thematique.table'; +import { DatabaseService } from '../../utils/database/database.service'; +import { ficheActionActionImpactTable } from './shared/models/fiche-action-action-impact.table'; +import { ficheActionActionTable } from './shared/models/fiche-action-action.table'; +import { ficheActionEffetAttenduTable } from './shared/models/fiche-action-effet-attendu.table'; +import { ficheActionIndicateurTable } from './shared/models/fiche-action-indicateur.table'; +import { ficheActionNoteTable } from './shared/models/fiche-action-note.table'; +import { ficheActionPartenaireTagTable } from './shared/models/fiche-action-partenaire-tag.table'; +import { ficheActionSousThematiqueTable } from './shared/models/fiche-action-sous-thematique.table'; +import { ficheActionThematiqueTable } from './shared/models/fiche-action-thematique.table'; import { - CreateFicheActionType, + FicheCreate, ficheActionTable, -} from '../models/fiche-action.table'; -import { dcpTable } from '@/backend/auth'; -import { PermissionService } from '@/backend/auth/authorizations/permission.service'; -import { PermissionOperation } from '@/backend/auth/authorizations/permission-operation.enum'; -import { ResourceType } from '@/backend/auth/authorizations/resource-type.enum'; +} from './shared/models/fiche-action.table'; @Injectable() export default class FicheService { @@ -26,8 +25,7 @@ export default class FicheService { constructor( private readonly permissionService: PermissionService, - private readonly databaseService: DatabaseService, - private readonly tagService: TagService + private readonly databaseService: DatabaseService ) {} /** Renvoi une fiche à partir de son id */ @@ -76,7 +74,7 @@ export default class FicheService { * @param fiche * @return identifiant de la fiche crée */ - async createFiche(fiche: CreateFicheActionType): Promise { + async createFiche(fiche: FicheCreate): Promise { this.logger.log( `Création de la fiche ${fiche.titre} pour la collectivité ${fiche.collectiviteId}` ); @@ -155,21 +153,6 @@ export default class FicheService { }); } - /** - * Ajoute un partenaire à une fiche à partir du nom du partenaire et la collectivité - * @param ficheId identifiant de la fiche - * @param nomTag nom du partenaire - * @param collectiviteId identifiant de la collectivité - */ - async addPartenaireByNom( - ficheId: number, - nomTag: string, - collectiviteId: number - ): Promise { - const tagId = await this.tagService.getPartenaireId(nomTag, collectiviteId); - await this.addPartenaireById(ficheId, tagId); - } - // On ajoute le financement /** @@ -190,7 +173,7 @@ export default class FicheService { * @param actionId identifiant de l'action */ async addActionImpact(ficheId: number, actionId: number): Promise { - await this.databaseService.db.insert(actionImpactFicheActionTable).values({ + await this.databaseService.db.insert(ficheActionActionImpactTable).values({ ficheId: ficheId, actionImpactId: actionId, }); diff --git a/backend/src/fiches/services/fiches-action-update.service.ts b/backend/src/plans/fiches/fiches-action-update.service.ts similarity index 89% rename from backend/src/fiches/services/fiches-action-update.service.ts rename to backend/src/plans/fiches/fiches-action-update.service.ts index 77ac123650..ec2e5fa39a 100644 --- a/backend/src/fiches/services/fiches-action-update.service.ts +++ b/backend/src/plans/fiches/fiches-action-update.service.ts @@ -1,3 +1,4 @@ +import { DatabaseService } from '@/backend/utils'; import { Injectable, Logger, NotFoundException } from '@nestjs/common'; import { and, @@ -13,32 +14,31 @@ import { PgTable, PgTransaction } from 'drizzle-orm/pg-core'; import { PostgresJsQueryResultHKT } from 'drizzle-orm/postgres-js'; import { toCamel } from 'postgres'; import { AuthenticatedUser } from '../../auth/models/auth.models'; -import { buildConflictUpdateColumns } from '../../common/services/conflict.helper'; -import DatabaseService from '../../common/services/database.service'; -import { ficheActionActionTable } from '../models/fiche-action-action.table'; -import { ficheActionAxeTable } from '../models/fiche-action-axe.table'; -import { ficheActionEffetAttenduTable } from '../models/fiche-action-effet-attendu.table'; -import { ficheActionFinanceurTagTable } from '../models/fiche-action-financeur-tag.table'; -import { ficheActionIndicateurTable } from '../models/fiche-action-indicateur.table'; -import { ficheActionLibreTagTable } from '../models/fiche-action-libre-tag.table'; -import { ficheActionLienTable } from '../models/fiche-action-lien.table'; +import { buildConflictUpdateColumns } from '../../utils/database/conflict.utils'; +import FicheService from './fiche.service'; +import { UpdateFicheActionRequestType } from './shared/edit-fiche.request'; +import { ficheActionActionTable } from './shared/models/fiche-action-action.table'; +import { ficheActionAxeTable } from './shared/models/fiche-action-axe.table'; +import { ficheActionEffetAttenduTable } from './shared/models/fiche-action-effet-attendu.table'; +import { ficheActionFinanceurTagTable } from './shared/models/fiche-action-financeur-tag.table'; +import { ficheActionIndicateurTable } from './shared/models/fiche-action-indicateur.table'; +import { ficheActionLibreTagTable } from './shared/models/fiche-action-libre-tag.table'; +import { ficheActionLienTable } from './shared/models/fiche-action-lien.table'; import { ficheActionNoteTable, UpsertFicheActionNoteType, -} from '../models/fiche-action-note.table'; -import { ficheActionPartenaireTagTable } from '../models/fiche-action-partenaire-tag.table'; -import { ficheActionPiloteTable } from '../models/fiche-action-pilote.table'; -import { ficheActionReferentTable } from '../models/fiche-action-referent.table'; -import { ficheActionServiceTagTable } from '../models/fiche-action-service-tag.table'; -import { ficheActionSousThematiqueTable } from '../models/fiche-action-sous-thematique.table'; -import { ficheActionStructureTagTable } from '../models/fiche-action-structure-tag.table'; -import { ficheActionThematiqueTable } from '../models/fiche-action-thematique.table'; +} from './shared/models/fiche-action-note.table'; +import { ficheActionPartenaireTagTable } from './shared/models/fiche-action-partenaire-tag.table'; +import { ficheActionPiloteTable } from './shared/models/fiche-action-pilote.table'; +import { ficheActionReferentTable } from './shared/models/fiche-action-referent.table'; +import { ficheActionServiceTagTable } from './shared/models/fiche-action-service-tag.table'; +import { ficheActionSousThematiqueTable } from './shared/models/fiche-action-sous-thematique.table'; +import { ficheActionStructureTagTable } from './shared/models/fiche-action-structure-tag.table'; +import { ficheActionThematiqueTable } from './shared/models/fiche-action-thematique.table'; import { ficheActionTable, - updateFicheActionSchema, -} from '../models/fiche-action.table'; -import { UpdateFicheActionRequestType } from '../models/update-fiche-action.request'; -import FicheService from './fiche.service'; + ficheSchemaUpdate, +} from './shared/models/fiche-action.table'; type TxType = PgTransaction< PostgresJsQueryResultHKT, @@ -114,7 +114,7 @@ export default class FichesActionUpdateService { } // Removes all props that are not in the schema - const ficheAction = updateFicheActionSchema.parse(unsafeFicheAction); + const ficheAction = ficheSchemaUpdate.parse(unsafeFicheAction); let updatedFicheAction; let updatedAxes; diff --git a/backend/src/fiches/controllers/fiches-action.controller.ts b/backend/src/plans/fiches/fiches-action.controller.ts similarity index 84% rename from backend/src/fiches/controllers/fiches-action.controller.ts rename to backend/src/plans/fiches/fiches-action.controller.ts index 01bcf0ff09..e8bcacfd9b 100644 --- a/backend/src/fiches/controllers/fiches-action.controller.ts +++ b/backend/src/plans/fiches/fiches-action.controller.ts @@ -1,4 +1,8 @@ +import { ficheActionNoteSchema } from '@/backend/plans/fiches'; +import { CountByStatutService } from '@/backend/plans/fiches/count-by-statut/count-by-statut.service'; +import { countSyntheseValeurSchema } from '@/backend/utils/count-by.dto'; import { createZodDto } from '@anatine/zod-nestjs'; +import { extendApi } from '@anatine/zod-openapi'; import { Body, Controller, @@ -12,30 +16,31 @@ import { ApiOkResponse, ApiTags } from '@nestjs/swagger'; import { z } from 'zod'; import { TokenInfo } from '../../auth/decorators/token-info.decorators'; import type { AuthenticatedUser } from '../../auth/models/auth.models'; -import { CountByStatutService } from '../count-by-statut/count-by-statut.service'; -import { ficheActionNoteSchema } from '../models/fiche-action-note.table'; -import { getFichesActionSyntheseSchema } from '../models/get-fiches-action-synthese.response'; -import { getFichesActionFilterRequestSchema } from '../models/get-fiches-actions-filter.request'; -import { updateFicheActionRequestSchema } from '../models/update-fiche-action.request'; import { deleteFicheActionNotesRequestSchema, upsertFicheActionNotesRequestSchema, -} from '../models/upsert-fiche-action-note.request'; -import FicheService from '../services/fiche.service'; -import FichesActionUpdateService from '../services/fiches-action-update.service'; +} from './shared/upsert-fiche-action-note.request'; +import FicheService from './fiche.service'; +import FichesActionUpdateService from './fiches-action-update.service'; +import { editFicheRequestSchema } from './shared/edit-fiche.request'; +import { fetchFichesFilterRequestSchema } from './shared/fetch-fiches-filter.request'; /** * Création des classes de réponse à partir du schema pour générer automatiquement la documentation OpenAPI */ export class GetFichesActionSyntheseResponseClass extends createZodDto( - getFichesActionSyntheseSchema + extendApi( + z.object({ + par_statut: countSyntheseValeurSchema, + }) + ) ) {} export class GetFichesActionFilterRequestClass extends createZodDto( - getFichesActionFilterRequestSchema + fetchFichesFilterRequestSchema ) {} export class UpdateFicheActionRequestClass extends createZodDto( - updateFicheActionRequestSchema.refine( + editFicheRequestSchema.refine( (schema) => Object.keys(schema).length > 0, 'Body cannot be empty' ) diff --git a/backend/src/fiches/fiches-action.module.ts b/backend/src/plans/fiches/fiches.module.ts similarity index 64% rename from backend/src/fiches/fiches-action.module.ts rename to backend/src/plans/fiches/fiches.module.ts index acc6223739..038b77f118 100644 --- a/backend/src/fiches/fiches-action.module.ts +++ b/backend/src/plans/fiches/fiches.module.ts @@ -1,20 +1,18 @@ import { Module } from '@nestjs/common'; -import { AuthModule } from '../auth/auth.module'; -import { CollectivitesModule } from '../collectivites/collectivites.module'; -import { CommonModule } from '../common/common.module'; -import TagService from '../taxonomie/services/tag.service'; +import { AuthModule } from '../../auth/auth.module'; +import { CollectivitesModule } from '../../collectivites/collectivites.module'; import { BulkEditRouter } from './bulk-edit/bulk-edit.router'; import { BulkEditService } from './bulk-edit/bulk-edit.service'; -import { FichesActionController } from './controllers/fiches-action.controller'; import { CountByStatutRouter } from './count-by-statut/count-by-statut.router'; import { CountByStatutService } from './count-by-statut/count-by-statut.service'; import { FicheActionEtapeRouter } from './fiche-action-etape/fiche-action-etape.router'; import { FicheActionEtapeService } from './fiche-action-etape/fiche-action-etape.service'; -import FicheService from './services/fiche.service'; -import FichesActionUpdateService from './services/fiches-action-update.service'; +import FicheService from './fiche.service'; +import FichesActionUpdateService from './fiches-action-update.service'; +import { FichesActionController } from './fiches-action.controller'; @Module({ - imports: [CommonModule, AuthModule, CollectivitesModule], + imports: [AuthModule, CollectivitesModule], providers: [ FicheService, CountByStatutService, @@ -22,7 +20,6 @@ import FichesActionUpdateService from './services/fiches-action-update.service'; BulkEditService, BulkEditRouter, FichesActionUpdateService, - TagService, FicheActionEtapeService, FicheActionEtapeRouter, ], diff --git a/backend/src/plans/fiches/index-domain.ts b/backend/src/plans/fiches/index-domain.ts new file mode 100644 index 0000000000..5d35bca520 --- /dev/null +++ b/backend/src/plans/fiches/index-domain.ts @@ -0,0 +1,18 @@ +// `index-domain.ts` file must only contain exports that are shareable with client-side apps. +// Exports from this file can be imported with `@/domain/*` alias path. + +export * from './shared/models/axe.table'; +export * from './shared/models/fiche-action-effet-attendu.table'; +export * from './shared/models/fiche-action-financeur-tag.table'; +export * from './shared/models/fiche-action-indicateur.table'; +export * from './shared/models/fiche-action-libre-tag.table'; +export * from './shared/models/fiche-action-lien.table'; +export * from './shared/models/fiche-action-note.table'; +export * from './shared/models/fiche-action-partenaire-tag.table'; +export * from './shared/models/fiche-action-service-tag.table'; +export * from './shared/models/fiche-action-sous-thematique.table'; +export * from './shared/models/fiche-action-structure-tag.table'; +export * from './shared/models/fiche-action-thematique.table'; +export * from './shared/models/fiche-action.table'; +export * from './shared/models/plan-action-type-categorie.table'; +export * from './shared/models/plan-action-type.table'; diff --git a/backend/src/plans/fiches/index.ts b/backend/src/plans/fiches/index.ts new file mode 100644 index 0000000000..81ce45f809 --- /dev/null +++ b/backend/src/plans/fiches/index.ts @@ -0,0 +1 @@ +export * from './index-domain'; diff --git a/backend/src/fiches/models/update-fiche-action.request.ts b/backend/src/plans/fiches/shared/edit-fiche.request.ts similarity index 66% rename from backend/src/fiches/models/update-fiche-action.request.ts rename to backend/src/plans/fiches/shared/edit-fiche.request.ts index 17b1d30776..77ec3579f0 100644 --- a/backend/src/fiches/models/update-fiche-action.request.ts +++ b/backend/src/plans/fiches/shared/edit-fiche.request.ts @@ -1,21 +1,23 @@ +import { + libreTagSchema, + partenaireTagSchema, + serviceTagSchema, + structureTagSchema, +} from '@/backend/collectivites'; import z from 'zod'; -import { indicateurDefinitionSchema } from '../../indicateurs/models/indicateur-definition.table'; -import { actionRelationSchema } from '../../referentiels/models/action-relation.table'; -import { effetAttenduSchema } from '../../taxonomie/models/effet-attendu.table'; -import { financeurTagSchema } from '../../taxonomie/models/financeur-tag.table'; -import { libreTagSchema } from '../../taxonomie/models/libre-tag.table'; -import { partenaireTagSchema } from '../../taxonomie/models/partenaire-tag.table'; -import { serviceTagSchema } from '../../taxonomie/models/service-tag.table'; -import { sousThematiqueSchema } from '../../taxonomie/models/sous-thematique.table'; -import { structureTagSchema } from '../../taxonomie/models/structure-tag.table'; -import { thematiqueSchema } from '../../taxonomie/models/thematique.table'; -import { axeSchema } from './axe.table'; +import { financeurTagSchema } from '../../../collectivites/shared/models/financeur-tag.table'; +import { indicateurDefinitionSchema } from '../../../indicateurs/models/indicateur-definition.table'; +import { actionRelationSchema } from '../../../referentiels/models/action-relation.table'; +import { effetAttenduSchema } from '../../../shared/models/effet-attendu.table'; +import { sousThematiqueSchema } from '../../../shared/models/sous-thematique.table'; +import { thematiqueSchema } from '../../../shared/models/thematique.table'; +import { axeSchema } from './models/axe.table'; import { - FicheActionCiblesEnumType, - ficheActionSchema, + ciblesEnumSchema, + ficheSchema, + ficheSchemaUpdate, piliersEciEnumType, - updateFicheActionSchema, -} from './fiche-action.table'; +} from './models/fiche-action.table'; // There is no proper Pilote or Referent tables, so we use a custom schema here export const personneSchema = z.object({ @@ -32,7 +34,7 @@ const financeurWithMontantSchema = z.object({ montantTtc: z.number().nullish(), }); -export const updateFicheActionRequestSchema = updateFicheActionSchema.extend({ +export const editFicheRequestSchema = ficheSchemaUpdate.extend({ // We're overriding piliersEci and cibles because, // for some unknown reason (a bug with zod/drizzle ?), extend() looses enum's array piliersEci: z @@ -42,7 +44,7 @@ export const updateFicheActionRequestSchema = updateFicheActionSchema.extend({ ) .array() .nullish(), - cibles: z.nativeEnum(FicheActionCiblesEnumType).array().nullish(), + cibles: ciblesEnumSchema.array().nullish(), // Overriding because numeric and timestamp types are not properly converted otherwise (a bug with zod/drizzle ?) budgetPrevisionnel: z .union([z.string(), z.number()]) @@ -81,13 +83,13 @@ export const updateFicheActionRequestSchema = updateFicheActionSchema.extend({ indicateurs: indicateurDefinitionSchema.pick({ id: true }).array().nullish(), services: serviceTagSchema.pick({ id: true }).array().nullish(), financeurs: financeurWithMontantSchema.array().nullish(), - fichesLiees: ficheActionSchema.pick({ id: true }).array().nullish(), + fichesLiees: ficheSchema.pick({ id: true }).array().nullish(), resultatsAttendus: effetAttenduSchema.pick({ id: true }).array().nullish(), libresTag: libreTagSchema.pick({ id: true }).array().nullish(), }); export type UpdateFicheActionRequestType = z.infer< - typeof updateFicheActionRequestSchema + typeof editFicheRequestSchema >; -export type UpdateFicheActionType = z.infer; +export type UpdateFicheActionType = z.infer; diff --git a/backend/src/fiches/models/get-fiches-actions-filter.request.ts b/backend/src/plans/fiches/shared/fetch-fiches-filter.request.ts similarity index 86% rename from backend/src/fiches/models/get-fiches-actions-filter.request.ts rename to backend/src/plans/fiches/shared/fetch-fiches-filter.request.ts index c71d1dc1c2..004b72354c 100644 --- a/backend/src/fiches/models/get-fiches-actions-filter.request.ts +++ b/backend/src/plans/fiches/shared/fetch-fiches-filter.request.ts @@ -1,13 +1,13 @@ +import { modifiedSinceSchema } from '@/backend/utils/modified-since.enum'; import { z } from 'zod'; -import { modifiedSinceSchema } from '../../common/models/modified-since.enum'; -import { ficheActionCiblesEnumSchema } from './fiche-action.table'; +import { ciblesEnumSchema } from './models/fiche-action.table'; -export const getFichesActionFilterRequestSchema = z +export const fetchFichesFilterRequestSchema = z .object({ cibles: z .string() .transform((value) => value.split(',')) - .pipe(ficheActionCiblesEnumSchema.array()) + .pipe(ciblesEnumSchema.array()) .optional() .describe('Liste des cibles séparées par des virgules'), partenaire_tag_ids: z @@ -64,5 +64,5 @@ export const getFichesActionFilterRequestSchema = z .describe('Filtre de récupération des fiches action'); export type GetFichesActionFilterRequestType = z.infer< - typeof getFichesActionFilterRequestSchema + typeof fetchFichesFilterRequestSchema >; diff --git a/backend/src/fiches/shared/fixtures/fiche-action-relations.fixture.ts b/backend/src/plans/fiches/shared/fixtures/fiche-action-relations.fixture.ts similarity index 100% rename from backend/src/fiches/shared/fixtures/fiche-action-relations.fixture.ts rename to backend/src/plans/fiches/shared/fixtures/fiche-action-relations.fixture.ts diff --git a/backend/src/fiches/shared/fixtures/fiche-action.fixture.ts b/backend/src/plans/fiches/shared/fixtures/fiche-action.fixture.ts similarity index 58% rename from backend/src/fiches/shared/fixtures/fiche-action.fixture.ts rename to backend/src/plans/fiches/shared/fixtures/fiche-action.fixture.ts index 8793c2a715..fe27b195b1 100644 --- a/backend/src/fiches/shared/fixtures/fiche-action.fixture.ts +++ b/backend/src/plans/fiches/shared/fixtures/fiche-action.fixture.ts @@ -1,24 +1,21 @@ import { - CreateFicheActionType, - FicheActionCiblesEnumType, - FicheActionStatutsEnumType, - piliersEciEnumType, -} from '../../models/fiche-action.table'; + ciblesEnumSchema, + FicheCreate, + piliersEciEnumSchema, + statutsEnumSchema, +} from '../models/fiche-action.table'; -export const ficheActionFixture: CreateFicheActionType = { +export const ficheActionFixture: FicheCreate = { id: 9999, titre: 'Test Fiche Action', description: 'patati', - piliersEci: [piliersEciEnumType.APPROVISIONNEMENT_DURABLE], + piliersEci: [piliersEciEnumSchema.enum['Approvisionnement durable']], objectifs: 'Diminution des émissions de carbone', - cibles: [ - FicheActionCiblesEnumType.GRAND_PUBLIC_ET_ASSOCIATIONS, - FicheActionCiblesEnumType.AGENTS, - ], + cibles: [ciblesEnumSchema.enum.Agents, ciblesEnumSchema.enum['Grand public']], ressources: 'Service digitaux', financements: '100 000€', budgetPrevisionnel: '35000', - statut: FicheActionStatutsEnumType.EN_PAUSE, + statut: statutsEnumSchema.enum['En pause'], priorite: 'Moyen', dateDebut: null, dateFin: null, diff --git a/backend/src/fiches/models/axe.table.ts b/backend/src/plans/fiches/shared/models/axe.table.ts similarity index 51% rename from backend/src/fiches/models/axe.table.ts rename to backend/src/plans/fiches/shared/models/axe.table.ts index eaf55bf847..eababe421b 100644 --- a/backend/src/fiches/models/axe.table.ts +++ b/backend/src/plans/fiches/shared/models/axe.table.ts @@ -1,3 +1,4 @@ +import { createdAt, modifiedAt, modifiedBy } from '@/domain/utils'; import { InferInsertModel } from 'drizzle-orm'; import { AnyPgColumn, @@ -7,10 +8,13 @@ import { text, } from 'drizzle-orm/pg-core'; import { createSelectSchema } from 'drizzle-zod'; -import { collectiviteTable } from '../../collectivites/models/collectivite.table'; -import { panierTable } from '../../panier/models/panier.table'; -import { createdAt, modifiedAt, modifiedBy } from '../../utils/column.utils'; -import { planActionTypeTable } from './plan-action-type.table'; +import z from 'zod'; +import { collectiviteTable } from '../../../../collectivites/shared/models/collectivite.table'; +import { panierTable } from '../../../paniers/models/panier.table'; +import { + planActionTypeSchema, + planActionTypeTable, +} from './plan-action-type.table'; export const axeTable = pgTable('axe', { id: serial('id').primaryKey(), @@ -20,12 +24,20 @@ export const axeTable = pgTable('axe', { .references(() => collectiviteTable.id), parent: integer('parent').references((): AnyPgColumn => axeTable.id), plan: integer('plan').references((): AnyPgColumn => axeTable.id), - type: integer('type').references(() => planActionTypeTable.id), + typeId: integer('type').references(() => planActionTypeTable.id), createdAt, modifiedAt, modifiedBy, panierId: integer('panier_id').references(() => panierTable.id), }); + export type CreateAxeType = InferInsertModel; -export const axeSchema = createSelectSchema(axeTable); +export const axeTableSchema = createSelectSchema(axeTable); + +export const axeSchema = axeTableSchema.extend({ + axes: axeTableSchema.array().nullish(), + type: planActionTypeSchema.nullable(), +}); + +export type Axe = z.input; diff --git a/backend/src/fiches/models/action-impact-fiche-action.table.ts b/backend/src/plans/fiches/shared/models/fiche-action-action-impact.table.ts similarity index 77% rename from backend/src/fiches/models/action-impact-fiche-action.table.ts rename to backend/src/plans/fiches/shared/models/fiche-action-action-impact.table.ts index 667d297653..e641bd8481 100644 --- a/backend/src/fiches/models/action-impact-fiche-action.table.ts +++ b/backend/src/plans/fiches/shared/models/fiche-action-action-impact.table.ts @@ -1,8 +1,8 @@ +import { actionImpactTable } from '@/domain/plans/paniers'; import { integer, pgTable, primaryKey } from 'drizzle-orm/pg-core'; -import { actionImpactTable } from '../../panier/models/action-impact.table'; import { ficheActionTable } from './fiche-action.table'; -export const actionImpactFicheActionTable = pgTable( +export const ficheActionActionImpactTable = pgTable( 'action_impact_fiche_action', { ficheId: integer('fiche_id').references(() => ficheActionTable.id), diff --git a/backend/src/fiches/models/fiche-action-action.table.ts b/backend/src/plans/fiches/shared/models/fiche-action-action.table.ts similarity index 84% rename from backend/src/fiches/models/fiche-action-action.table.ts rename to backend/src/plans/fiches/shared/models/fiche-action-action.table.ts index a2b16c57f3..7b4494fd0d 100644 --- a/backend/src/fiches/models/fiche-action-action.table.ts +++ b/backend/src/plans/fiches/shared/models/fiche-action-action.table.ts @@ -1,5 +1,5 @@ +import { actionRelationTable } from '@/domain/referentiels'; import { integer, pgTable, primaryKey, varchar } from 'drizzle-orm/pg-core'; -import { actionRelationTable } from '../../referentiels/models/action-relation.table'; import { ficheActionTable } from './fiche-action.table'; export const ficheActionActionTable = pgTable( diff --git a/backend/src/fiches/models/fiche-action-axe.table.ts b/backend/src/plans/fiches/shared/models/fiche-action-axe.table.ts similarity index 100% rename from backend/src/fiches/models/fiche-action-axe.table.ts rename to backend/src/plans/fiches/shared/models/fiche-action-axe.table.ts index bbb9dd425a..88d316e46f 100644 --- a/backend/src/fiches/models/fiche-action-axe.table.ts +++ b/backend/src/plans/fiches/shared/models/fiche-action-axe.table.ts @@ -1,6 +1,6 @@ import { integer, pgTable, primaryKey } from 'drizzle-orm/pg-core'; -import { ficheActionTable } from './fiche-action.table'; import { axeTable } from './axe.table'; +import { ficheActionTable } from './fiche-action.table'; export const ficheActionAxeTable = pgTable( 'fiche_action_axe', diff --git a/backend/src/fiches/models/fiche-action-effet-attendu.table.ts b/backend/src/plans/fiches/shared/models/fiche-action-effet-attendu.table.ts similarity index 93% rename from backend/src/fiches/models/fiche-action-effet-attendu.table.ts rename to backend/src/plans/fiches/shared/models/fiche-action-effet-attendu.table.ts index fe09ffcea7..065a080499 100644 --- a/backend/src/fiches/models/fiche-action-effet-attendu.table.ts +++ b/backend/src/plans/fiches/shared/models/fiche-action-effet-attendu.table.ts @@ -1,7 +1,7 @@ +import { effetAttenduTable } from '@/domain/shared'; import { sql } from 'drizzle-orm'; import { integer, pgPolicy, pgTable, primaryKey } from 'drizzle-orm/pg-core'; import { authenticatedRole } from 'drizzle-orm/supabase'; -import { effetAttenduTable } from '../../taxonomie/models/effet-attendu.table'; import { ficheActionTable } from './fiche-action.table'; export const ficheActionEffetAttenduTable = pgTable( diff --git a/backend/src/plans/fiches/shared/models/fiche-action-financeur-tag.table.ts b/backend/src/plans/fiches/shared/models/fiche-action-financeur-tag.table.ts new file mode 100644 index 0000000000..e8d6841df8 --- /dev/null +++ b/backend/src/plans/fiches/shared/models/fiche-action-financeur-tag.table.ts @@ -0,0 +1,36 @@ +import { integer, pgTable, serial } from 'drizzle-orm/pg-core'; +import { createInsertSchema, createSelectSchema } from 'drizzle-zod'; +import z from 'zod'; +import { + financeurTagSchema, + financeurTagTable, +} from '../../../../collectivites/shared/models/financeur-tag.table'; +import { ficheActionTable } from './fiche-action.table'; + +export const ficheActionFinanceurTagTable = pgTable( + 'fiche_action_financeur_tag', + { + id: serial('id').primaryKey(), + ficheId: integer('fiche_id') + .notNull() + .references(() => ficheActionTable.id), + financeurTagId: integer('financeur_tag_id') + .notNull() + .references(() => financeurTagTable.id), + montantTtc: integer('montant_ttc'), + } +); + +export const financeurSchema = createSelectSchema( + ficheActionFinanceurTagTable +).extend({ + financeurTag: financeurTagSchema, +}); +export type Financeur = z.infer; + +export const financeurSchemaUpdate = createInsertSchema( + ficheActionFinanceurTagTable +).extend({ + financeurTag: financeurTagSchema, +}); +export type FinanceurUpdate = z.infer; diff --git a/backend/src/fiches/models/fiche-action-indicateur.table.ts b/backend/src/plans/fiches/shared/models/fiche-action-indicateur.table.ts similarity index 83% rename from backend/src/fiches/models/fiche-action-indicateur.table.ts rename to backend/src/plans/fiches/shared/models/fiche-action-indicateur.table.ts index 78534ae02b..cec0085d97 100644 --- a/backend/src/fiches/models/fiche-action-indicateur.table.ts +++ b/backend/src/plans/fiches/shared/models/fiche-action-indicateur.table.ts @@ -1,5 +1,5 @@ +import { indicateurDefinitionTable } from '@/domain/indicateurs'; import { integer, pgTable, primaryKey } from 'drizzle-orm/pg-core'; -import { indicateurDefinitionTable } from '../../indicateurs/models/indicateur-definition.table'; import { ficheActionTable } from './fiche-action.table'; export const ficheActionIndicateurTable = pgTable( diff --git a/backend/src/fiches/models/fiche-action-libre-tag.table.ts b/backend/src/plans/fiches/shared/models/fiche-action-libre-tag.table.ts similarity index 81% rename from backend/src/fiches/models/fiche-action-libre-tag.table.ts rename to backend/src/plans/fiches/shared/models/fiche-action-libre-tag.table.ts index f62188990f..e081215f87 100644 --- a/backend/src/fiches/models/fiche-action-libre-tag.table.ts +++ b/backend/src/plans/fiches/shared/models/fiche-action-libre-tag.table.ts @@ -1,6 +1,6 @@ -import { createdAt, createdBy } from '@/backend/utils'; +import { libreTagTable } from '@/domain/collectivites'; +import { createdAt, createdBy } from '@/domain/utils'; import { integer, pgTable, primaryKey } from 'drizzle-orm/pg-core'; -import { libreTagTable } from '../../taxonomie/models/libre-tag.table'; import { ficheActionTable } from './fiche-action.table'; export const ficheActionLibreTagTable = pgTable( diff --git a/backend/src/fiches/models/fiche-action-lien.table.ts b/backend/src/plans/fiches/shared/models/fiche-action-lien.table.ts similarity index 100% rename from backend/src/fiches/models/fiche-action-lien.table.ts rename to backend/src/plans/fiches/shared/models/fiche-action-lien.table.ts diff --git a/backend/src/fiches/models/fiche-action-note.table.ts b/backend/src/plans/fiches/shared/models/fiche-action-note.table.ts similarity index 92% rename from backend/src/fiches/models/fiche-action-note.table.ts rename to backend/src/plans/fiches/shared/models/fiche-action-note.table.ts index 9238be94f1..331bfbc2d3 100644 --- a/backend/src/fiches/models/fiche-action-note.table.ts +++ b/backend/src/plans/fiches/shared/models/fiche-action-note.table.ts @@ -1,13 +1,8 @@ +import { createdAt, createdBy, modifiedAt, modifiedBy } from '@/domain/utils'; import { InferSelectModel } from 'drizzle-orm'; import { date, integer, pgTable, serial, text } from 'drizzle-orm/pg-core'; import { createInsertSchema, createSelectSchema } from 'drizzle-zod'; import { z } from 'zod'; -import { - createdAt, - createdBy, - modifiedAt, - modifiedBy, -} from '../../utils/column.utils'; import { ficheActionTable } from './fiche-action.table'; export const ficheActionNoteTable = pgTable('fiche_action_note', { diff --git a/backend/src/fiches/models/fiche-action-partenaire-tag.table.ts b/backend/src/plans/fiches/shared/models/fiche-action-partenaire-tag.table.ts similarity index 87% rename from backend/src/fiches/models/fiche-action-partenaire-tag.table.ts rename to backend/src/plans/fiches/shared/models/fiche-action-partenaire-tag.table.ts index d254d1f89a..5063515b23 100644 --- a/backend/src/fiches/models/fiche-action-partenaire-tag.table.ts +++ b/backend/src/plans/fiches/shared/models/fiche-action-partenaire-tag.table.ts @@ -1,5 +1,5 @@ +import { partenaireTagTable } from '@/domain/collectivites'; import { integer, pgTable, primaryKey } from 'drizzle-orm/pg-core'; -import { partenaireTagTable } from '../../taxonomie/models/partenaire-tag.table'; import { ficheActionTable } from './fiche-action.table'; export const ficheActionPartenaireTagTable = pgTable( diff --git a/backend/src/fiches/models/fiche-action-pilote.table.ts b/backend/src/plans/fiches/shared/models/fiche-action-pilote.table.ts similarity index 90% rename from backend/src/fiches/models/fiche-action-pilote.table.ts rename to backend/src/plans/fiches/shared/models/fiche-action-pilote.table.ts index 873afc9bfb..4fb46f4744 100644 --- a/backend/src/fiches/models/fiche-action-pilote.table.ts +++ b/backend/src/plans/fiches/shared/models/fiche-action-pilote.table.ts @@ -6,7 +6,7 @@ import { uniqueIndex, uuid, } from 'drizzle-orm/pg-core'; -import { personneTagTable } from '../../taxonomie/models/personne-tag.table'; +import { personneTagTable } from '../../../../collectivites/shared/models/personne-tag.table'; import { ficheActionTable } from './fiche-action.table'; export const ficheActionPiloteTable = pgTable( diff --git a/backend/src/fiches/models/fiche-action-referent.table.ts b/backend/src/plans/fiches/shared/models/fiche-action-referent.table.ts similarity index 88% rename from backend/src/fiches/models/fiche-action-referent.table.ts rename to backend/src/plans/fiches/shared/models/fiche-action-referent.table.ts index 96ef37f5ba..449606ef43 100644 --- a/backend/src/fiches/models/fiche-action-referent.table.ts +++ b/backend/src/plans/fiches/shared/models/fiche-action-referent.table.ts @@ -1,6 +1,6 @@ +import { personneTagTable } from '@/domain/collectivites'; import { integer, pgTable, uniqueIndex, uuid } from 'drizzle-orm/pg-core'; import { ficheActionTable } from './fiche-action.table'; -import { personneTagTable } from '../../taxonomie/models/personne-tag.table'; export const ficheActionReferentTable = pgTable( 'fiche_action_referent', diff --git a/backend/src/fiches/models/fiche-action-service-tag.table.ts b/backend/src/plans/fiches/shared/models/fiche-action-service-tag.table.ts similarity index 88% rename from backend/src/fiches/models/fiche-action-service-tag.table.ts rename to backend/src/plans/fiches/shared/models/fiche-action-service-tag.table.ts index c673d87326..4f4926ec1c 100644 --- a/backend/src/fiches/models/fiche-action-service-tag.table.ts +++ b/backend/src/plans/fiches/shared/models/fiche-action-service-tag.table.ts @@ -1,5 +1,5 @@ +import { serviceTagTable } from '@/domain/collectivites'; import { integer, pgTable, primaryKey } from 'drizzle-orm/pg-core'; -import { serviceTagTable } from '../../taxonomie/models/service-tag.table'; import { ficheActionTable } from './fiche-action.table'; export const ficheActionServiceTagTable = pgTable( diff --git a/backend/src/fiches/models/fiche-action-sous-thematique.table.ts b/backend/src/plans/fiches/shared/models/fiche-action-sous-thematique.table.ts similarity index 85% rename from backend/src/fiches/models/fiche-action-sous-thematique.table.ts rename to backend/src/plans/fiches/shared/models/fiche-action-sous-thematique.table.ts index 5cbbde2198..843ea92d62 100644 --- a/backend/src/fiches/models/fiche-action-sous-thematique.table.ts +++ b/backend/src/plans/fiches/shared/models/fiche-action-sous-thematique.table.ts @@ -1,6 +1,6 @@ +import { sousThematiqueTable } from '@/domain/shared'; import { integer, pgTable, primaryKey } from 'drizzle-orm/pg-core'; import { ficheActionTable } from './fiche-action.table'; -import { sousThematiqueTable } from '../../taxonomie/models/sous-thematique.table'; export const ficheActionSousThematiqueTable = pgTable( 'fiche_action_sous_thematique', diff --git a/backend/src/fiches/models/fiche-action-structure-tag.table.ts b/backend/src/plans/fiches/shared/models/fiche-action-structure-tag.table.ts similarity index 87% rename from backend/src/fiches/models/fiche-action-structure-tag.table.ts rename to backend/src/plans/fiches/shared/models/fiche-action-structure-tag.table.ts index b1ec5236dd..dd374909fe 100644 --- a/backend/src/fiches/models/fiche-action-structure-tag.table.ts +++ b/backend/src/plans/fiches/shared/models/fiche-action-structure-tag.table.ts @@ -1,5 +1,5 @@ +import { structureTagTable } from '@/domain/collectivites'; import { integer, pgTable, primaryKey } from 'drizzle-orm/pg-core'; -import { structureTagTable } from '../../taxonomie/models/structure-tag.table'; import { ficheActionTable } from './fiche-action.table'; export const ficheActionStructureTagTable = pgTable( diff --git a/backend/src/fiches/models/fiche-action-thematique.table.ts b/backend/src/plans/fiches/shared/models/fiche-action-thematique.table.ts similarity index 86% rename from backend/src/fiches/models/fiche-action-thematique.table.ts rename to backend/src/plans/fiches/shared/models/fiche-action-thematique.table.ts index f6b1ab2453..1da3b05952 100644 --- a/backend/src/fiches/models/fiche-action-thematique.table.ts +++ b/backend/src/plans/fiches/shared/models/fiche-action-thematique.table.ts @@ -1,5 +1,5 @@ import { integer, pgTable, primaryKey } from 'drizzle-orm/pg-core'; -import { thematiqueTable } from '../../taxonomie/models/thematique.table'; +import { thematiqueTable } from '../../../../shared/models/thematique.table'; import { ficheActionTable } from './fiche-action.table'; export const ficheActionThematiqueTable = pgTable( diff --git a/backend/src/fiches/models/fiche-action.table.ts b/backend/src/plans/fiches/shared/models/fiche-action.table.ts similarity index 65% rename from backend/src/fiches/models/fiche-action.table.ts rename to backend/src/plans/fiches/shared/models/fiche-action.table.ts index 8934561a22..300a3c4a42 100644 --- a/backend/src/fiches/models/fiche-action.table.ts +++ b/backend/src/plans/fiches/shared/models/fiche-action.table.ts @@ -1,4 +1,3 @@ -import { getEnumValues } from '@/backend/utils/enum.utils'; import { InferInsertModel } from 'drizzle-orm'; import { boolean, @@ -13,14 +12,14 @@ import { } from 'drizzle-orm/pg-core'; import { createInsertSchema, createSelectSchema } from 'drizzle-zod'; import { z } from 'zod'; -import { collectiviteTable } from '../../collectivites/models/collectivite.table'; -import { tempsDeMiseEnOeuvreTable } from '../../taxonomie/models/temps-de-mise-en-oeuvre.table'; +import { collectiviteTable } from '../../../../collectivites/shared/models/collectivite.table'; +import { tempsDeMiseEnOeuvreTable } from '../../../../shared/models/temps-de-mise-en-oeuvre.table'; import { createdAt, modifiedAt, modifiedBy, TIMESTAMP_OPTIONS, -} from '../../utils/column.utils'; +} from '../../../../utils/column.utils'; export enum piliersEciEnumType { APPROVISIONNEMENT_DURABLE = 'Approvisionnement durable', @@ -66,49 +65,40 @@ export const ficheActionResultatsAttendusEnum = pgEnum( ] ); -export enum FicheActionStatutsEnumType { - A_VENIR = 'À venir', - EN_COURS = 'En cours', - REALISE = 'Réalisé', - EN_PAUSE = 'En pause', - ABANDONNE = 'Abandonné', - BLOQUE = 'Bloqué', - EN_RETARD = 'En retard', - A_DISCUTER = 'A discuter', -} - export const SANS_STATUT_FICHE_ACTION_SYNTHESE_KEY = 'Sans statut'; -export const statutsEnumValues = getEnumValues(FicheActionStatutsEnumType); +export const statutsEnumValues = [ + 'À venir', + 'En cours', + 'Réalisé', + 'En pause', + 'Abandonné', + 'Bloqué', + 'En retard', + 'A discuter', +] as const; export const statutsEnumSchema = z.enum(statutsEnumValues); export const statutsPgEnum = pgEnum('fiche_action_statuts', statutsEnumValues); - -export enum FicheActionCiblesEnumType { - GRAND_PUBLIC = 'Grand public', - ASSOCIATIONS = 'Associations', - GRAND_PUBLIC_ET_ASSOCIATIONS = 'Grand public et associations', - PUBLIC_SCOLAIRE = 'Public Scolaire', - AUTRES_COLLECTIVITES_DU_TERRITOIRE = 'Autres collectivités du territoire', - ACTEURS_ECONOMIQUES = 'Acteurs économiques', - ACTEURS_ECONOMIQUES_DU_SECTEUR_PRIMAIRE = 'Acteurs économiques du secteur primaire', - ACTEURS_ECONOMIQUES_DU_SECTEUR_SECONDAIRE = 'Acteurs économiques du secteur secondaire', - ACTEURS_ECONOMIQUES_DU_SECTEUR_TERTIAIRE = 'Acteurs économiques du secteur tertiaire', - PARTENAIRES = 'Partenaires', - COLLECTIVITE_ELLE_MEME = 'Collectivité elle-même', - ELUS_LOCAUX = 'Elus locaux', - AGENTS = 'Agents', -} - -export const ficheActionCiblesEnumValues = Object.values( - FicheActionCiblesEnumType -) as [FicheActionCiblesEnumType, ...FicheActionCiblesEnumType[]]; - -export const ficheActionCiblesEnumSchema = z.enum(ficheActionCiblesEnumValues); - -export const ficheActionCiblesEnum = pgEnum( - 'fiche_action_cibles', - ficheActionCiblesEnumValues -); +export type Statut = z.infer; + +export const ciblesEnumValues = [ + 'Grand public', + 'Associations', + 'Grand public et associations', + 'Public Scolaire', + 'Autres collectivités du territoire', + 'Acteurs économiques', + 'Acteurs économiques du secteur primaire', + 'Acteurs économiques du secteur secondaire', + 'Acteurs économiques du secteur tertiaire', + 'Partenaires', + 'Collectivité elle-même', + 'Elus locaux', + 'Agents', +] as const; +export const ciblesEnumSchema = z.enum(ciblesEnumValues); +export const ciblesPgEnum = pgEnum('fiche_action_cibles', ciblesEnumValues); +export type Cible = z.infer; export const prioriteEnumValues = ['Élevé', 'Moyen', 'Bas'] as const; export const prioriteEnumSchema = z.enum(prioriteEnumValues); @@ -116,14 +106,21 @@ export const prioritePgEnum = pgEnum( 'fiche_action_niveaux_priorite', prioriteEnumValues ); +export type Priorite = z.infer; -export const ficheActionParticipationCitoyenneTypeEnumValues = [ +export const participationCitoyenneEnumValues = [ 'pas-de-participation', 'information', 'consultation', 'concertation', 'co-construction', ] as const; +export const participationCitoyenneEnumSchema = z.enum( + participationCitoyenneEnumValues +); +export type ParticipationCitoyenne = z.infer< + typeof participationCitoyenneEnumSchema +>; export const ficheActionTable = pgTable('fiche_action', { id: serial('id').primaryKey().notNull(), @@ -132,7 +129,7 @@ export const ficheActionTable = pgTable('fiche_action', { piliersEci: piliersEciPgEnum('piliers_eci').array(), objectifs: varchar('objectifs', { length: 10000 }), cibles: text('cibles', { - enum: ficheActionCiblesEnumValues, + enum: ciblesEnumValues, }).array(), ressources: varchar('ressources', { length: 10000 }), financements: text('financements'), @@ -140,7 +137,7 @@ export const ficheActionTable = pgTable('fiche_action', { precision: 12, scale: 0, }), - statut: statutsPgEnum('statut').default(FicheActionStatutsEnumType.A_VENIR), + statut: statutsPgEnum('statut').default(statutsEnumSchema.enum['À venir']), priorite: prioritePgEnum('niveau_priorite'), dateDebut: timestamp('date_debut', TIMESTAMP_OPTIONS), dateFin: timestamp('date_fin_provisoire', TIMESTAMP_OPTIONS), @@ -151,10 +148,10 @@ export const ficheActionTable = pgTable('fiche_action', { participationCitoyenne: text('participation_citoyenne'), participationCitoyenneType: varchar('participation_citoyenne_type', { length: 30, - enum: ficheActionParticipationCitoyenneTypeEnumValues, + enum: participationCitoyenneEnumValues, }), tempsDeMiseEnOeuvre: integer('temps_de_mise_en_oeuvre_id').references( - () => tempsDeMiseEnOeuvreTable.niveau + () => tempsDeMiseEnOeuvreTable.id ), majTermine: boolean('maj_termine'), collectiviteId: integer('collectivite_id') @@ -166,24 +163,22 @@ export const ficheActionTable = pgTable('fiche_action', { restreint: boolean('restreint').default(false), }); -export type CreateFicheActionType = InferInsertModel; - -export const ficheActionSchema = createSelectSchema(ficheActionTable, { +export const ficheSchema = createSelectSchema(ficheActionTable, { // Overriding array types as a workaround for drizzle-zod parsing issue // See https://github.com/drizzle-team/drizzle-orm/issues/1609 piliersEci: z.array(piliersEciEnumSchema), - cibles: z.array(ficheActionCiblesEnumSchema), + cibles: z.array(ciblesEnumSchema), }); -export const createFicheActionSchema = createInsertSchema(ficheActionTable, { +export const ficheSchemaCreate = createInsertSchema(ficheActionTable, { // Overriding array types as a workaround for drizzle-zod parsing issue // See https://github.com/drizzle-team/drizzle-orm/issues/1609 piliersEci: z.array(piliersEciEnumSchema), - cibles: z.array(ficheActionCiblesEnumSchema), + cibles: z.array(ciblesEnumSchema), }); -export const updateFicheActionSchema = createFicheActionSchema +export type FicheCreate = InferInsertModel; + +export const ficheSchemaUpdate = ficheSchemaCreate .omit({ id: true, createdAt: true, modifiedAt: true, modifiedBy: true }) .partial(); - -export type UpdateFicheActionType = z.infer; diff --git a/backend/src/fiches/models/plan-action-type-categorie.table.ts b/backend/src/plans/fiches/shared/models/plan-action-type-categorie.table.ts similarity index 100% rename from backend/src/fiches/models/plan-action-type-categorie.table.ts rename to backend/src/plans/fiches/shared/models/plan-action-type-categorie.table.ts diff --git a/backend/src/fiches/models/plan-action-type.table.ts b/backend/src/plans/fiches/shared/models/plan-action-type.table.ts similarity index 74% rename from backend/src/fiches/models/plan-action-type.table.ts rename to backend/src/plans/fiches/shared/models/plan-action-type.table.ts index 36089114b6..03c4957b45 100644 --- a/backend/src/fiches/models/plan-action-type.table.ts +++ b/backend/src/plans/fiches/shared/models/plan-action-type.table.ts @@ -1,4 +1,6 @@ import { pgTable, serial, text, uniqueIndex } from 'drizzle-orm/pg-core'; +import { createSelectSchema } from 'drizzle-zod'; +import z from 'zod'; import { planActionTypeCategorieTable } from './plan-action-type-categorie.table'; export const planActionTypeTable = pgTable( @@ -19,3 +21,7 @@ export const planActionTypeTable = pgTable( }; } ); + +export const planActionTypeSchema = createSelectSchema(planActionTypeTable); + +export type PlanActionType = z.infer; diff --git a/backend/src/fiches/models/upsert-fiche-action-note.request.ts b/backend/src/plans/fiches/shared/upsert-fiche-action-note.request.ts similarity index 94% rename from backend/src/fiches/models/upsert-fiche-action-note.request.ts rename to backend/src/plans/fiches/shared/upsert-fiche-action-note.request.ts index bebd14a5f2..f85eef522d 100644 --- a/backend/src/fiches/models/upsert-fiche-action-note.request.ts +++ b/backend/src/plans/fiches/shared/upsert-fiche-action-note.request.ts @@ -1,9 +1,9 @@ -import { extendApi } from '@anatine/zod-openapi'; -import { z } from 'zod'; import { deleteFicheActionNoteSchema, upsertFicheActionNoteSchema, -} from './fiche-action-note.table'; +} from '@/backend/plans/fiches'; +import { extendApi } from '@anatine/zod-openapi'; +import { z } from 'zod'; export const upsertFicheActionNotesRequestSchema = extendApi( z diff --git a/backend/src/plans/paniers/index-domain.ts b/backend/src/plans/paniers/index-domain.ts new file mode 100644 index 0000000000..745028455c --- /dev/null +++ b/backend/src/plans/paniers/index-domain.ts @@ -0,0 +1,4 @@ +// `index-domain.ts` file must only contain exports that are shareable with client-side apps. +// Exports from this file can be imported with `@/domain/*` alias path. + +export * from './models/action-impact.table'; diff --git a/backend/src/plans/paniers/index.ts b/backend/src/plans/paniers/index.ts new file mode 100644 index 0000000000..81ce45f809 --- /dev/null +++ b/backend/src/plans/paniers/index.ts @@ -0,0 +1 @@ +export * from './index-domain'; diff --git a/backend/src/panier/models/action-impact-action.table.ts b/backend/src/plans/paniers/models/action-impact-action.table.ts similarity index 75% rename from backend/src/panier/models/action-impact-action.table.ts rename to backend/src/plans/paniers/models/action-impact-action.table.ts index 6cb1162297..250c4c526e 100644 --- a/backend/src/panier/models/action-impact-action.table.ts +++ b/backend/src/plans/paniers/models/action-impact-action.table.ts @@ -1,8 +1,7 @@ -import { integer, pgTable, primaryKey } from 'drizzle-orm/pg-core'; -import { actionRelationTable } from '../../referentiels/models/action-relation.table'; -import { actionImpactTable } from './action-impact.table'; -import { text } from 'drizzle-orm/pg-core'; +import { actionRelationTable } from '@/domain/referentiels'; import { InferSelectModel } from 'drizzle-orm'; +import { integer, pgTable, primaryKey, text } from 'drizzle-orm/pg-core'; +import { actionImpactTable } from './action-impact.table'; export const actionImpactActionTable = pgTable( 'action_impact_action', diff --git a/backend/src/panier/models/action-impact-banatic-competence.table.ts b/backend/src/plans/paniers/models/action-impact-banatic-competence.table.ts similarity index 76% rename from backend/src/panier/models/action-impact-banatic-competence.table.ts rename to backend/src/plans/paniers/models/action-impact-banatic-competence.table.ts index 4576428c79..cd49d67c50 100644 --- a/backend/src/panier/models/action-impact-banatic-competence.table.ts +++ b/backend/src/plans/paniers/models/action-impact-banatic-competence.table.ts @@ -1,7 +1,6 @@ -import { integer, pgTable } from 'drizzle-orm/pg-core'; -import { primaryKey } from 'drizzle-orm/pg-core'; +import { banaticCompetenceTable } from '@/domain/shared'; +import { integer, pgTable, primaryKey } from 'drizzle-orm/pg-core'; import { actionImpactTable } from './action-impact.table'; -import { banaticCompetenceTable } from '../../taxonomie/models/banatic-competence.table'; export const actionImpactBanaticCompetenceTable = pgTable( 'action_impact_banatic_competence', diff --git a/backend/src/panier/models/action-impact-categorie.table.ts b/backend/src/plans/paniers/models/action-impact-categorie.table.ts similarity index 100% rename from backend/src/panier/models/action-impact-categorie.table.ts rename to backend/src/plans/paniers/models/action-impact-categorie.table.ts diff --git a/backend/src/panier/models/action-impact-cateorie-fnv.table.ts b/backend/src/plans/paniers/models/action-impact-cateorie-fnv.table.ts similarity index 87% rename from backend/src/panier/models/action-impact-cateorie-fnv.table.ts rename to backend/src/plans/paniers/models/action-impact-cateorie-fnv.table.ts index a1b6498c9e..cda3bc21cd 100644 --- a/backend/src/panier/models/action-impact-cateorie-fnv.table.ts +++ b/backend/src/plans/paniers/models/action-impact-cateorie-fnv.table.ts @@ -1,6 +1,6 @@ +import { categorieFNVTable } from '@/domain/shared'; import { integer, pgTable, primaryKey } from 'drizzle-orm/pg-core'; import { actionImpactTable } from './action-impact.table'; -import { categorieFNVTable } from '../../taxonomie/models/categorie-fnv.table'; export const actionImpactCategorieFNVTable = pgTable( 'action_impact_categorie_fnv', diff --git a/backend/src/panier/models/action-impact-effet-attendu.table.ts b/backend/src/plans/paniers/models/action-impact-effet-attendu.table.ts similarity index 90% rename from backend/src/panier/models/action-impact-effet-attendu.table.ts rename to backend/src/plans/paniers/models/action-impact-effet-attendu.table.ts index 5f65e001e0..cb5e8fde2e 100644 --- a/backend/src/panier/models/action-impact-effet-attendu.table.ts +++ b/backend/src/plans/paniers/models/action-impact-effet-attendu.table.ts @@ -1,7 +1,7 @@ +import { effetAttenduTable } from '@/domain/shared'; +import { InferSelectModel } from 'drizzle-orm'; import { integer, pgTable, primaryKey } from 'drizzle-orm/pg-core'; -import { effetAttenduTable } from '../../taxonomie/models/effet-attendu.table'; import { actionImpactTable } from './action-impact.table'; -import { InferSelectModel } from 'drizzle-orm'; export const actionImpactEffetAttenduTable = pgTable( 'action_impact_effet_attendu', diff --git a/backend/src/panier/models/action-impact-fourchette-budgetaire.table.ts b/backend/src/plans/paniers/models/action-impact-fourchette-budgetaire.table.ts similarity index 100% rename from backend/src/panier/models/action-impact-fourchette-budgetaire.table.ts rename to backend/src/plans/paniers/models/action-impact-fourchette-budgetaire.table.ts diff --git a/backend/src/panier/models/action-impact-indicateur.table.ts b/backend/src/plans/paniers/models/action-impact-indicateur.table.ts similarity index 88% rename from backend/src/panier/models/action-impact-indicateur.table.ts rename to backend/src/plans/paniers/models/action-impact-indicateur.table.ts index fc44a9a54d..2b12b683e8 100644 --- a/backend/src/panier/models/action-impact-indicateur.table.ts +++ b/backend/src/plans/paniers/models/action-impact-indicateur.table.ts @@ -1,7 +1,7 @@ +import { indicateurDefinitionTable } from '@/domain/indicateurs'; +import { InferSelectModel } from 'drizzle-orm'; import { integer, pgTable, primaryKey } from 'drizzle-orm/pg-core'; import { actionImpactTable } from './action-impact.table'; -import { indicateurDefinitionTable } from '../../indicateurs/models/indicateur-definition.table'; -import { InferSelectModel } from 'drizzle-orm'; export const actionImpactIndicateurTable = pgTable( 'action_impact_indicateur', diff --git a/backend/src/panier/models/action-impact-panier.table.ts b/backend/src/plans/paniers/models/action-impact-panier.table.ts similarity index 100% rename from backend/src/panier/models/action-impact-panier.table.ts rename to backend/src/plans/paniers/models/action-impact-panier.table.ts diff --git a/backend/src/panier/models/action-impact-partenaire.table.ts b/backend/src/plans/paniers/models/action-impact-partenaire.table.ts similarity index 86% rename from backend/src/panier/models/action-impact-partenaire.table.ts rename to backend/src/plans/paniers/models/action-impact-partenaire.table.ts index 87add19f28..781de1198c 100644 --- a/backend/src/panier/models/action-impact-partenaire.table.ts +++ b/backend/src/plans/paniers/models/action-impact-partenaire.table.ts @@ -1,6 +1,6 @@ import { integer, pgTable, primaryKey } from 'drizzle-orm/pg-core'; -import { panierPartenaireTable } from '../../taxonomie/models/panier-partenaire.table'; import { actionImpactTable } from './action-impact.table'; +import { panierPartenaireTable } from './panier-partenaire.table'; export const actionImpactPartenaireTable = pgTable( 'action_impact_partenaire', diff --git a/backend/src/panier/models/action-impact-sous-thematique.table.ts b/backend/src/plans/paniers/models/action-impact-sous-thematique.table.ts similarity index 89% rename from backend/src/panier/models/action-impact-sous-thematique.table.ts rename to backend/src/plans/paniers/models/action-impact-sous-thematique.table.ts index 239e2315d4..f8a07d7bc6 100644 --- a/backend/src/panier/models/action-impact-sous-thematique.table.ts +++ b/backend/src/plans/paniers/models/action-impact-sous-thematique.table.ts @@ -1,7 +1,7 @@ +import { sousThematiqueTable } from '@/domain/shared'; +import { InferSelectModel } from 'drizzle-orm'; import { integer, pgTable, primaryKey } from 'drizzle-orm/pg-core'; -import { sousThematiqueTable } from '../../taxonomie/models/sous-thematique.table'; import { actionImpactTable } from './action-impact.table'; -import { InferSelectModel } from 'drizzle-orm'; export const actionImpactSousThematiqueTable = pgTable( 'action_impact_sous_thematique', diff --git a/backend/src/panier/models/action-impact-statut.table.ts b/backend/src/plans/paniers/models/action-impact-statut.table.ts similarity index 100% rename from backend/src/panier/models/action-impact-statut.table.ts rename to backend/src/plans/paniers/models/action-impact-statut.table.ts diff --git a/backend/src/panier/models/action-impact-thematique.table.ts b/backend/src/plans/paniers/models/action-impact-thematique.table.ts similarity index 82% rename from backend/src/panier/models/action-impact-thematique.table.ts rename to backend/src/plans/paniers/models/action-impact-thematique.table.ts index a8f4e44a2c..b3771648b4 100644 --- a/backend/src/panier/models/action-impact-thematique.table.ts +++ b/backend/src/plans/paniers/models/action-impact-thematique.table.ts @@ -1,8 +1,7 @@ +import { thematiqueTable } from '@/domain/shared'; +import { InferSelectModel } from 'drizzle-orm'; import { integer, pgTable, primaryKey } from 'drizzle-orm/pg-core'; -import { thematiqueTable } from '../../taxonomie/models/thematique.table'; import { actionImpactTable } from './action-impact.table'; -import { InferSelectModel } from 'drizzle-orm'; -import { actionImpactIndicateurTable } from './action-impact-indicateur.table'; export const actionImpactThematiqueTable = pgTable( 'action_impact_thematique', diff --git a/backend/src/panier/models/action-impact-tier.table.ts b/backend/src/plans/paniers/models/action-impact-tier.table.ts similarity index 100% rename from backend/src/panier/models/action-impact-tier.table.ts rename to backend/src/plans/paniers/models/action-impact-tier.table.ts diff --git a/backend/src/panier/models/action-impact.table.ts b/backend/src/plans/paniers/models/action-impact.table.ts similarity index 90% rename from backend/src/panier/models/action-impact.table.ts rename to backend/src/plans/paniers/models/action-impact.table.ts index 05391e2bd5..778c93d5b7 100644 --- a/backend/src/panier/models/action-impact.table.ts +++ b/backend/src/plans/paniers/models/action-impact.table.ts @@ -1,3 +1,11 @@ +import { + categorieFNVSchema, + CategorieFNVType, + tempsDeMiseEnOeuvreTable, + thematiqueSchema, + ThematiqueType, +} from '@/domain/shared'; +import { createZodDto } from '@anatine/zod-nestjs'; import { InferSelectModel } from 'drizzle-orm'; import { boolean, @@ -7,21 +15,14 @@ import { serial, text, } from 'drizzle-orm/pg-core'; +import { createSelectSchema } from 'drizzle-zod'; +import { z } from 'zod'; import { - thematiqueSchema, - ThematiqueType, -} from '../../taxonomie/models/thematique.table'; -import { - categorieFNVSchema, - CategorieFNVType, -} from '../../taxonomie/models/categorie-fnv.table'; -import { tempsDeMiseEnOeuvreTable } from '../../taxonomie/models/temps-de-mise-en-oeuvre.table'; + lienSchema, + lienType, +} from '../../../documents/models/document-lien.dto'; import { actionImpactFourchetteBudgetaireTable } from './action-impact-fourchette-budgetaire.table'; import { actionImpactTierTable } from './action-impact-tier.table'; -import { createSelectSchema } from 'drizzle-zod'; -import { lienSchema, lienType } from '../../documents/models/document-lien.dto'; -import { z } from 'zod'; -import { createZodDto } from '@anatine/zod-nestjs'; export const actionImpactTable = pgTable('action_impact', { id: serial('id').primaryKey(), @@ -40,7 +41,7 @@ export const actionImpactTable = pgTable('action_impact', { tempsDeMiseEnOeuvre: integer('temps_de_mise_en_oeuvre') .notNull() .default(1) - .references(() => tempsDeMiseEnOeuvreTable.niveau), + .references(() => tempsDeMiseEnOeuvreTable.id), fourchetteBudgetaire: integer('fourchette_budgetaire') .notNull() .default(1) diff --git a/backend/src/taxonomie/models/panier-partenaire.table.ts b/backend/src/plans/paniers/models/panier-partenaire.table.ts similarity index 100% rename from backend/src/taxonomie/models/panier-partenaire.table.ts rename to backend/src/plans/paniers/models/panier-partenaire.table.ts diff --git a/backend/src/panier/models/panier.table.ts b/backend/src/plans/paniers/models/panier.table.ts similarity index 83% rename from backend/src/panier/models/panier.table.ts rename to backend/src/plans/paniers/models/panier.table.ts index 73b78dfe9c..274d34aa8d 100644 --- a/backend/src/panier/models/panier.table.ts +++ b/backend/src/plans/paniers/models/panier.table.ts @@ -1,4 +1,4 @@ -import { createZodDto } from '@anatine/zod-nestjs'; +import { collectiviteTable } from '@/domain/collectivites'; import { InferSelectModel, SQL, sql } from 'drizzle-orm'; import { boolean, @@ -8,7 +8,6 @@ import { uuid, } from 'drizzle-orm/pg-core'; import { createSelectSchema } from 'drizzle-zod'; -import { collectiviteTable } from '../../collectivites/models/collectivite.table'; export const panierTable = pgTable('panier', { id: uuid('id').primaryKey().defaultRandom(), @@ -37,5 +36,3 @@ export const panierTable = pgTable('panier', { export type PanierType = InferSelectModel; export const panierSchema = createSelectSchema(panierTable); - -export class PanierClass extends createZodDto(panierSchema) {} diff --git a/backend/src/referentiels/compute-score/compute-score.router.ts b/backend/src/referentiels/compute-score/compute-score.router.ts index 26b3ae1205..8f50b4ed8f 100644 --- a/backend/src/referentiels/compute-score/compute-score.router.ts +++ b/backend/src/referentiels/compute-score/compute-score.router.ts @@ -1,6 +1,6 @@ import { Injectable } from '@nestjs/common'; import z from 'zod'; -import { TrpcService } from '../../trpc/trpc.service'; +import { TrpcService } from '@/backend/utils/trpc/trpc.service'; import { getReferentielScoresRequestSchema } from '../models/get-referentiel-scores.request'; import { ReferentielType } from '../models/referentiel.enum'; import ReferentielsScoringService from '../services/referentiels-scoring.service'; diff --git a/backend/src/referentiels/controllers/referentiels-scoring.e2e-spec.ts b/backend/src/referentiels/controllers/referentiels-scoring.e2e-spec.ts index 023504f9b9..431f7fe40a 100644 --- a/backend/src/referentiels/controllers/referentiels-scoring.e2e-spec.ts +++ b/backend/src/referentiels/controllers/referentiels-scoring.e2e-spec.ts @@ -3,7 +3,7 @@ import { default as request } from 'supertest'; import { getTestApp } from '../../../test/app-utils'; import { getAuthToken } from '../../../test/auth-utils'; import { getCollectiviteIdBySiren } from '../../../test/collectivites-utils'; -import { HttpErrorResponse } from '../../common/models/http-error.response'; +import { HttpErrorResponse } from '../../utils/nest/http-error.response'; import { ActionScoreType } from '../models/action-score.dto'; import { ActionStatutType } from '../models/action-statut.table'; import { ActionType } from '../models/action-type.enum'; diff --git a/backend/src/referentiels/controllers/referentiels.e2e-spec.ts b/backend/src/referentiels/controllers/referentiels.e2e-spec.ts index e3069f4264..84831228a7 100644 --- a/backend/src/referentiels/controllers/referentiels.e2e-spec.ts +++ b/backend/src/referentiels/controllers/referentiels.e2e-spec.ts @@ -3,6 +3,7 @@ import { INestApplication } from '@nestjs/common'; import { default as request } from 'supertest'; import { ActionType } from '../models/action-type.enum'; import { GetReferentielResponseType } from '../models/get-referentiel.response'; +import { ReferentielActionType } from '../models/referentiel-action.dto'; describe('Referentiels routes', () => { let app: INestApplication; diff --git a/backend/src/referentiels/index-domain.ts b/backend/src/referentiels/index-domain.ts new file mode 100644 index 0000000000..b429561207 --- /dev/null +++ b/backend/src/referentiels/index-domain.ts @@ -0,0 +1,4 @@ +// `index-domain.ts` file must only contain exports that are shareable with client-side apps. +// Exports from this file can be imported with `@/domain/*` alias path. + +export * from './models/action-relation.table'; diff --git a/backend/src/referentiels/index.ts b/backend/src/referentiels/index.ts new file mode 100644 index 0000000000..81ce45f809 --- /dev/null +++ b/backend/src/referentiels/index.ts @@ -0,0 +1 @@ +export * from './index-domain'; diff --git a/backend/src/referentiels/models/action-commentaire.table.ts b/backend/src/referentiels/models/action-commentaire.table.ts index 82e6ca22b1..5c98b5d376 100644 --- a/backend/src/referentiels/models/action-commentaire.table.ts +++ b/backend/src/referentiels/models/action-commentaire.table.ts @@ -1,4 +1,4 @@ -import { modifiedAt, modifiedBy } from '@/backend/utils'; +import { modifiedAt, modifiedBy } from '@/domain/utils'; import { InferInsertModel, InferSelectModel } from 'drizzle-orm'; import { foreignKey, @@ -9,7 +9,7 @@ import { } from 'drizzle-orm/pg-core'; import { createInsertSchema, createSelectSchema } from 'drizzle-zod'; import { authUsersTable } from '../../auth/models/auth-users.table'; -import { collectiviteTable } from '../../collectivites/models/collectivite.table'; +import { collectiviteTable } from '../../collectivites/shared/models/collectivite.table'; import { actionIdVarchar } from './action-definition.table'; import { actionRelationTable } from './action-relation.table'; diff --git a/backend/src/referentiels/models/action-computed-points.table.ts b/backend/src/referentiels/models/action-computed-points.table.ts index e9c40c4612..b60a319ef4 100644 --- a/backend/src/referentiels/models/action-computed-points.table.ts +++ b/backend/src/referentiels/models/action-computed-points.table.ts @@ -1,4 +1,4 @@ -import { modifiedAt } from '@/backend/utils'; +import { modifiedAt } from '@/domain/utils'; import { InferInsertModel, InferSelectModel } from 'drizzle-orm'; import { doublePrecision, pgTable } from 'drizzle-orm/pg-core'; import { createInsertSchema, createSelectSchema } from 'drizzle-zod'; diff --git a/backend/src/referentiels/models/action-definition.table.ts b/backend/src/referentiels/models/action-definition.table.ts index 38d46bc07b..1199cb1677 100644 --- a/backend/src/referentiels/models/action-definition.table.ts +++ b/backend/src/referentiels/models/action-definition.table.ts @@ -1,4 +1,4 @@ -import { modifiedAt } from '@/backend/utils'; +import { modifiedAt } from '@/domain/utils'; import { InferInsertModel, InferSelectModel } from 'drizzle-orm'; import { doublePrecision, diff --git a/backend/src/referentiels/models/action-statut.table.ts b/backend/src/referentiels/models/action-statut.table.ts index 742da7a863..3409611752 100644 --- a/backend/src/referentiels/models/action-statut.table.ts +++ b/backend/src/referentiels/models/action-statut.table.ts @@ -1,4 +1,4 @@ -import { modifiedAt, modifiedBy } from '@/backend/utils'; +import { modifiedAt, modifiedBy } from '@/domain/utils'; import { InferInsertModel, InferSelectModel } from 'drizzle-orm'; import { boolean, @@ -8,7 +8,7 @@ import { pgTable, } from 'drizzle-orm/pg-core'; import { createInsertSchema, createSelectSchema } from 'drizzle-zod'; -import { collectiviteTable } from '../../collectivites/models/collectivite.table'; +import { collectiviteTable } from '../../collectivites/shared/models/collectivite.table'; import { actionIdReference } from './action-definition.table'; export const avancementEnum = pgEnum('avancement', [ diff --git a/backend/src/referentiels/models/client-scores.table.ts b/backend/src/referentiels/models/client-scores.table.ts index a8fc7aa69a..31dbf20a28 100644 --- a/backend/src/referentiels/models/client-scores.table.ts +++ b/backend/src/referentiels/models/client-scores.table.ts @@ -8,7 +8,7 @@ import { timestamp, } from 'drizzle-orm/pg-core'; import { createInsertSchema, createSelectSchema } from 'drizzle-zod'; -import { collectiviteTable } from '../../collectivites/models/collectivite.table'; +import { collectiviteTable } from '../../collectivites/shared/models/collectivite.table'; import { referentielEnum } from './referentiel.enum'; export const clientScoresTable = pgTable( diff --git a/backend/src/referentiels/models/get-referentiel-scores.response.ts b/backend/src/referentiels/models/get-referentiel-scores.response.ts index 0e0856274f..e71e5d8a48 100644 --- a/backend/src/referentiels/models/get-referentiel-scores.response.ts +++ b/backend/src/referentiels/models/get-referentiel-scores.response.ts @@ -1,6 +1,6 @@ import { extendApi } from '@anatine/zod-openapi'; import { z } from 'zod'; -import { collectiviteAvecTypeSchema } from '../../collectivites/models/identite-collectivite.dto'; +import { collectiviteAvecTypeSchema } from '../../collectivites/identite-collectivite.dto'; import { ComputeScoreMode } from './compute-scores-mode.enum'; import { referentielActionAvecScoreDtoSchema } from './referentiel-action-avec-score.dto'; import { ReferentielType } from './referentiel.enum'; diff --git a/backend/src/referentiels/models/historique-action-statut.table.ts b/backend/src/referentiels/models/historique-action-statut.table.ts index c91e15e2ec..6daa45fe6a 100644 --- a/backend/src/referentiels/models/historique-action-statut.table.ts +++ b/backend/src/referentiels/models/historique-action-statut.table.ts @@ -7,7 +7,7 @@ import { uuid, } from 'drizzle-orm/pg-core'; import { createInsertSchema, createSelectSchema } from 'drizzle-zod'; -import { collectiviteTable } from '../../collectivites/models/collectivite.table'; +import { collectiviteTable } from '../../collectivites/shared/models/collectivite.table'; import { historiqueSchema } from '../../personnalisations/models/historique-reponse-choix.table'; import { actionIdReference } from './action-definition.table'; import { avancementEnum } from './action-statut.table'; diff --git a/backend/src/referentiels/models/labellisation-action-audit-state.table.ts b/backend/src/referentiels/models/labellisation-action-audit-state.table.ts index 5b1dba7709..2524ec4ec3 100644 --- a/backend/src/referentiels/models/labellisation-action-audit-state.table.ts +++ b/backend/src/referentiels/models/labellisation-action-audit-state.table.ts @@ -1,4 +1,4 @@ -import { modifiedAt } from '@/backend/utils'; +import { modifiedAt } from '@/domain/utils'; import { sql } from 'drizzle-orm'; import { boolean, @@ -11,7 +11,7 @@ import { uuid, } from 'drizzle-orm/pg-core'; import { authUsersTable } from '../../auth/models/auth-users.table'; -import { collectiviteTable } from '../../collectivites/models/collectivite.table'; +import { collectiviteTable } from '../../collectivites/shared/models/collectivite.table'; import { actionIdReference } from './action-definition.table'; import { labellisationAuditTable } from './labellisation-audit.table'; import { labellisationSchema } from './labellisation.schema'; diff --git a/backend/src/referentiels/models/labellisation-audit.table.ts b/backend/src/referentiels/models/labellisation-audit.table.ts index efbb04db9a..039a59a572 100644 --- a/backend/src/referentiels/models/labellisation-audit.table.ts +++ b/backend/src/referentiels/models/labellisation-audit.table.ts @@ -1,4 +1,4 @@ -import { TIMESTAMP_OPTIONS } from '@/backend/utils'; +import { TIMESTAMP_OPTIONS } from '@/domain/utils'; import { InferInsertModel, InferSelectModel, sql } from 'drizzle-orm'; import { boolean, @@ -9,7 +9,7 @@ import { uniqueIndex, } from 'drizzle-orm/pg-core'; import { createInsertSchema, createSelectSchema } from 'drizzle-zod'; -import { collectiviteTable } from '../../collectivites/models/collectivite.table'; +import { collectiviteTable } from '../../collectivites/shared/models/collectivite.table'; import { labellisationDemandeTable } from './labellisation-demande.table'; import { labellisationSchema } from './labellisation.schema'; import { referentielEnum } from './referentiel.enum'; diff --git a/backend/src/referentiels/models/labellisation-bibliotheque-fichier.table.ts b/backend/src/referentiels/models/labellisation-bibliotheque-fichier.table.ts index c23960665a..93e9f7e3d9 100644 --- a/backend/src/referentiels/models/labellisation-bibliotheque-fichier.table.ts +++ b/backend/src/referentiels/models/labellisation-bibliotheque-fichier.table.ts @@ -7,7 +7,7 @@ import { unique, varchar, } from 'drizzle-orm/pg-core'; -import { collectiviteTable } from '../../collectivites/models/collectivite.table'; +import { collectiviteTable } from '../../collectivites/shared/models/collectivite.table'; import { labellisationSchema } from './labellisation.schema'; export const labellisationBibliothequeFichierTable = labellisationSchema.table( diff --git a/backend/src/referentiels/models/labellisation-demande.table.ts b/backend/src/referentiels/models/labellisation-demande.table.ts index e9980da56a..bfa1098ade 100644 --- a/backend/src/referentiels/models/labellisation-demande.table.ts +++ b/backend/src/referentiels/models/labellisation-demande.table.ts @@ -1,4 +1,4 @@ -import { TIMESTAMP_OPTIONS } from '@/backend/utils'; +import { TIMESTAMP_OPTIONS } from '@/domain/utils'; import { boolean, foreignKey, @@ -8,7 +8,7 @@ import { uuid, } from 'drizzle-orm/pg-core'; import { authUsersTable } from '../../auth/models/auth-users.table'; -import { collectiviteTable } from '../../collectivites/models/collectivite.table'; +import { collectiviteTable } from '../../collectivites/shared/models/collectivite.table'; import { labellisationEtoileEnum } from './labellisation-etoile.table'; import { labellisationSchema } from './labellisation.schema'; import { referentielEnum } from './referentiel.enum'; diff --git a/backend/src/referentiels/models/labellisation-preuve-base.table.ts b/backend/src/referentiels/models/labellisation-preuve-base.table.ts index 97b1fd808e..3e3244c680 100644 --- a/backend/src/referentiels/models/labellisation-preuve-base.table.ts +++ b/backend/src/referentiels/models/labellisation-preuve-base.table.ts @@ -1,8 +1,8 @@ -import { modifiedAt, modifiedBy } from '@/backend/utils'; +import { modifiedAt, modifiedBy } from '@/domain/utils'; import { sql } from 'drizzle-orm'; import { foreignKey, integer, jsonb, text } from 'drizzle-orm/pg-core'; import { authUsersTable } from '../../auth/models/auth-users.table'; -import { collectiviteTable } from '../../collectivites/models/collectivite.table'; +import { collectiviteTable } from '../../collectivites/shared/models/collectivite.table'; import { labellisationBibliothequeFichierTable } from './labellisation-bibliotheque-fichier.table'; import { labellisationSchema } from './labellisation.schema'; diff --git a/backend/src/referentiels/models/referentiel-definition.table.ts b/backend/src/referentiels/models/referentiel-definition.table.ts index b50531c827..7eff77303c 100644 --- a/backend/src/referentiels/models/referentiel-definition.table.ts +++ b/backend/src/referentiels/models/referentiel-definition.table.ts @@ -1,4 +1,4 @@ -import { createdAt, modifiedAt } from '@/backend/utils'; +import { createdAt, modifiedAt } from '@/domain/utils'; import { InferSelectModel } from 'drizzle-orm'; import { pgTable, varchar } from 'drizzle-orm/pg-core'; import { createInsertSchema, createSelectSchema } from 'drizzle-zod'; diff --git a/backend/src/referentiels/models/score-snapshot.table.ts b/backend/src/referentiels/models/score-snapshot.table.ts index c81e7cb31a..74e831211d 100644 --- a/backend/src/referentiels/models/score-snapshot.table.ts +++ b/backend/src/referentiels/models/score-snapshot.table.ts @@ -12,7 +12,7 @@ import { } from 'drizzle-orm/pg-core'; import { createInsertSchema, createSelectSchema } from 'drizzle-zod'; import z from 'zod'; -import { collectiviteTable } from '../../collectivites/models/collectivite.table'; +import { collectiviteTable } from '../../collectivites/shared/models/collectivite.table'; import { getPersonnalitionReponsesResponseSchema } from '../../personnalisations/models/get-personnalisation-reponses.response'; import { createdAt, diff --git a/backend/src/referentiels/referentiels.module.ts b/backend/src/referentiels/referentiels.module.ts index dd2652333c..7e0f13c2f6 100644 --- a/backend/src/referentiels/referentiels.module.ts +++ b/backend/src/referentiels/referentiels.module.ts @@ -1,10 +1,8 @@ import { Module } from '@nestjs/common'; import { AuthModule } from '../auth/auth.module'; import { CollectivitesModule } from '../collectivites/collectivites.module'; -import { CommonModule } from '../common/common.module'; -import { ConfigurationModule } from '../config/configuration.module'; import { PersonnalisationsModule } from '../personnalisations/personnalisations.module'; -import { SheetModule } from '../spreadsheets/sheet.module'; +import { SheetModule } from '../utils/google-sheets/sheet.module'; import { ComputeScoreRouter } from './compute-score/compute-score.router'; import { ReferentielsScoringController } from './controllers/referentiels-scoring.controller'; import { ReferentielsController } from './controllers/referentiels.controller'; @@ -20,8 +18,6 @@ import { UpdateActionStatutService } from './update-action-statut/update-action- imports: [ AuthModule, CollectivitesModule, - CommonModule, - ConfigurationModule, SheetModule, PersonnalisationsModule, ], diff --git a/backend/src/referentiels/services/labellisation.service.ts b/backend/src/referentiels/services/labellisation.service.ts index 89fbfca4fe..c2c7ac7385 100644 --- a/backend/src/referentiels/services/labellisation.service.ts +++ b/backend/src/referentiels/services/labellisation.service.ts @@ -1,6 +1,6 @@ +import { DatabaseService } from '@/backend/utils'; import { Injectable, Logger } from '@nestjs/common'; import { and, desc, eq, isNotNull, SQL, SQLWrapper } from 'drizzle-orm'; -import DatabaseService from '../../common/services/database.service'; import { labellisationAuditTable, LabellisationAuditType, diff --git a/backend/src/referentiels/services/referentiels-scoring-snapshots.service.ts b/backend/src/referentiels/services/referentiels-scoring-snapshots.service.ts index 17bd58b4c5..296f0c3f2d 100644 --- a/backend/src/referentiels/services/referentiels-scoring-snapshots.service.ts +++ b/backend/src/referentiels/services/referentiels-scoring-snapshots.service.ts @@ -1,3 +1,6 @@ +import { PermissionOperation } from '@/backend/auth/authorizations/permission-operation.enum'; +import { PermissionService } from '@/backend/auth/authorizations/permission.service'; +import { ResourceType } from '@/backend/auth/authorizations/resource-type.enum'; import { BadRequestException, Injectable, @@ -10,10 +13,10 @@ import { and, asc, eq, inArray, sql } from 'drizzle-orm'; import { DateTime } from 'luxon'; import slugify from 'slugify'; import { AuthRole, AuthUser } from '../../auth/models/auth.models'; -import { PgIntegrityConstraintViolation } from '../../common/models/postgresql-error-codes.enum'; -import DatabaseService from '../../common/services/database.service'; -import { getErrorWithCode } from '../../common/services/errors.helper'; import { GetPersonnalisationReponsesResponseType } from '../../personnalisations/models/get-personnalisation-reponses.response'; +import { DatabaseService } from '../../utils/database/database.service'; +import { getErrorWithCode } from '../../utils/nest/errors.utils'; +import { PgIntegrityConstraintViolation } from '../../utils/postgresql-error-codes.enum'; import { GetReferentielScoresResponseType } from '../models/get-referentiel-scores.response'; import { GetScoreSnapshotsRequestType } from '../models/get-score-snapshots.request'; import { @@ -28,9 +31,6 @@ import { scoreSnapshotTable, ScoreSnapshotType, } from '../models/score-snapshot.table'; -import { PermissionService } from '@/backend/auth/authorizations/permission.service'; -import { PermissionOperation } from '@/backend/auth/authorizations/permission-operation.enum'; -import { ResourceType } from '@/backend/auth/authorizations/resource-type.enum'; @Injectable() export default class ReferentielsScoringSnapshotsService { diff --git a/backend/src/referentiels/services/referentiels-scoring.service.spec.ts b/backend/src/referentiels/services/referentiels-scoring.service.spec.ts index ca47a5c2ea..55fe1a87c4 100644 --- a/backend/src/referentiels/services/referentiels-scoring.service.spec.ts +++ b/backend/src/referentiels/services/referentiels-scoring.service.spec.ts @@ -1,19 +1,20 @@ +import { PermissionService } from '@/backend/auth/authorizations/permission.service'; import { Test } from '@nestjs/testing'; import { CollectiviteTypeEnum, IdentiteCollectivite, -} from '../../collectivites/models/identite-collectivite.dto'; +} from '../../collectivites/identite-collectivite.dto'; import CollectivitesService from '../../collectivites/services/collectivites.service'; -import DatabaseService from '../../common/services/database.service'; -import MattermostNotificationService from '../../common/services/mattermost-notification.service'; -import { roundTo } from '../../common/services/number.helper'; -import ConfigurationService from '../../config/configuration.service'; import { GetPersonnalitionConsequencesResponseType } from '../../personnalisations/models/get-personnalisation-consequences.response'; import { GetPersonnalisationReponsesResponseType } from '../../personnalisations/models/get-personnalisation-reponses.response'; import { caePersonnalisationRegles } from '../../personnalisations/models/samples/cae-personnalisation-regles.sample'; import ExpressionParserService from '../../personnalisations/services/expression-parser.service'; import PersonnalisationsService from '../../personnalisations/services/personnalisations-service'; -import SheetService from '../../spreadsheets/services/sheet.service'; +import ConfigurationService from '../../utils/config/configuration.service'; +import { DatabaseService } from '../../utils/database/database.service'; +import SheetService from '../../utils/google-sheets/sheet.service'; +import MattermostNotificationService from '../../utils/mattermost-notification.service'; +import { roundTo } from '../../utils/number.helper'; import { ActionPointScoreType } from '../models/action-point-score.dto'; import { ActionType } from '../models/action-type.enum'; import { GetActionStatutsResponseType } from '../models/get-action-statuts.response'; @@ -26,7 +27,6 @@ import LabellisationService from './labellisation.service'; import ReferentielsScoringSnapshotsService from './referentiels-scoring-snapshots.service'; import ReferentielsScoringService from './referentiels-scoring.service'; import ReferentielsService from './referentiels.service'; -import { PermissionService } from '@/backend/auth/authorizations/permission.service'; describe('ReferentielsScoringService', () => { let referentielsScoringService: ReferentielsScoringService; diff --git a/backend/src/referentiels/services/referentiels-scoring.service.ts b/backend/src/referentiels/services/referentiels-scoring.service.ts index 1165903de1..b133e2ae5b 100644 --- a/backend/src/referentiels/services/referentiels-scoring.service.ts +++ b/backend/src/referentiels/services/referentiels-scoring.service.ts @@ -1,3 +1,7 @@ +import { PermissionOperation } from '@/backend/auth/authorizations/permission-operation.enum'; +import { PermissionService } from '@/backend/auth/authorizations/permission.service'; +import { ResourceType } from '@/backend/auth/authorizations/resource-type.enum'; +import { NiveauAcces } from '@/backend/auth/authorizations/roles/niveau-acces.enum'; import { HttpException, Injectable, @@ -20,18 +24,17 @@ import { chunk, isNil } from 'es-toolkit'; import * as _ from 'lodash'; import { DateTime } from 'luxon'; import { AuthenticatedUser } from '../../auth/models/auth.models'; -import { NiveauAcces } from '@/backend/auth/authorizations/roles/niveau-acces.enum'; -import { CollectiviteAvecType } from '../../collectivites/models/identite-collectivite.dto'; +import { CollectiviteAvecType } from '../../collectivites/identite-collectivite.dto'; import CollectivitesService from '../../collectivites/services/collectivites.service'; -import DatabaseService from '../../common/services/database.service'; -import { getErrorMessage } from '../../common/services/errors.helper'; -import MattermostNotificationService from '../../common/services/mattermost-notification.service'; -import { roundTo } from '../../common/services/number.helper'; -import { sleep } from '../../common/services/sleep.helper'; -import ConfigurationService from '../../config/configuration.service'; import { GetPersonnalitionConsequencesResponseType } from '../../personnalisations/models/get-personnalisation-consequences.response'; import ExpressionParserService from '../../personnalisations/services/expression-parser.service'; import PersonnalisationsService from '../../personnalisations/services/personnalisations-service'; +import ConfigurationService from '../../utils/config/configuration.service'; +import { DatabaseService } from '../../utils/database/database.service'; +import MattermostNotificationService from '../../utils/mattermost-notification.service'; +import { getErrorMessage } from '../../utils/nest/errors.utils'; +import { roundTo } from '../../utils/number.helper'; +import { sleep } from '../../utils/sleep.utils'; import { actionCommentaireTable } from '../models/action-commentaire.table'; import { ActionPointScoreType, @@ -76,9 +79,6 @@ import { ScoreJalon } from '../models/score-jalon.enum'; import LabellisationService from './labellisation.service'; import ReferentielsScoringSnapshotsService from './referentiels-scoring-snapshots.service'; import ReferentielsService from './referentiels.service'; -import { ResourceType } from '@/backend/auth/authorizations/resource-type.enum'; -import { PermissionService } from '@/backend/auth/authorizations/permission.service'; -import { PermissionOperation } from '@/backend/auth/authorizations/permission-operation.enum'; @Injectable() export default class ReferentielsScoringService { diff --git a/backend/src/referentiels/services/referentiels.service.spec.ts b/backend/src/referentiels/services/referentiels.service.spec.ts index f7dbf31155..9b13db9e58 100644 --- a/backend/src/referentiels/services/referentiels.service.spec.ts +++ b/backend/src/referentiels/services/referentiels.service.spec.ts @@ -1,8 +1,8 @@ +import { DatabaseService } from '@/backend/utils'; import { Test } from '@nestjs/testing'; -import DatabaseService from '../../common/services/database.service'; -import ConfigurationService from '../../config/configuration.service'; import ExpressionParserService from '../../personnalisations/services/expression-parser.service'; -import SheetService from '../../spreadsheets/services/sheet.service'; +import ConfigurationService from '../../utils/config/configuration.service'; +import SheetService from '../../utils/google-sheets/sheet.service'; import { ActionDefinitionAvecParentType } from '../models/action-definition.table'; import { CreateActionOrigineType } from '../models/action-origine.table'; import { ActionType } from '../models/action-type.enum'; diff --git a/backend/src/referentiels/services/referentiels.service.ts b/backend/src/referentiels/services/referentiels.service.ts index 252491dfef..70dec62743 100644 --- a/backend/src/referentiels/services/referentiels.service.ts +++ b/backend/src/referentiels/services/referentiels.service.ts @@ -1,3 +1,4 @@ +import { DatabaseService } from '@/backend/utils'; import { HttpException, HttpStatus, @@ -10,9 +11,6 @@ import { and, asc, eq, getTableColumns, inArray, sql } from 'drizzle-orm'; import { isNil } from 'es-toolkit'; import * as _ from 'lodash'; import * as semver from 'semver'; -import DatabaseService from '../../common/services/database.service'; -import { getErrorMessage } from '../../common/services/errors.helper'; -import ConfigurationService from '../../config/configuration.service'; import { CreatePersonnalisationRegleType, personnalisationRegleTable, @@ -22,7 +20,9 @@ import { PersonnalisationType, } from '../../personnalisations/models/personnalisation.table'; import ExpressionParserService from '../../personnalisations/services/expression-parser.service'; -import SheetService from '../../spreadsheets/services/sheet.service'; +import ConfigurationService from '../../utils/config/configuration.service'; +import SheetService from '../../utils/google-sheets/sheet.service'; +import { getErrorMessage } from '../../utils/nest/errors.utils'; import { actionDefinitionTagTable, CreateActionDefinitionTagType, diff --git a/backend/src/referentiels/snapshots/score-snaphots.router.ts b/backend/src/referentiels/snapshots/score-snaphots.router.ts index 67ef327643..69340bfbe4 100644 --- a/backend/src/referentiels/snapshots/score-snaphots.router.ts +++ b/backend/src/referentiels/snapshots/score-snaphots.router.ts @@ -1,6 +1,6 @@ import { Injectable } from '@nestjs/common'; import z from 'zod'; -import { TrpcService } from '../../trpc/trpc.service'; +import { TrpcService } from '@/backend/utils/trpc/trpc.service'; import { ReferentielType } from '../models/referentiel.enum'; import { ScoreJalon } from '../models/score-jalon.enum'; import ReferentielsScoringSnapshotsService from '../services/referentiels-scoring-snapshots.service'; diff --git a/backend/src/referentiels/snapshots/score-snapshots.router.e2e-spec.ts b/backend/src/referentiels/snapshots/score-snapshots.router.e2e-spec.ts index 405b120c33..a66a6f7952 100644 --- a/backend/src/referentiels/snapshots/score-snapshots.router.e2e-spec.ts +++ b/backend/src/referentiels/snapshots/score-snapshots.router.e2e-spec.ts @@ -4,7 +4,7 @@ import { getTestRouter } from '../../../test/app-utils'; import { getAuthUser } from '../../../test/auth-utils'; import { getCollectiviteIdBySiren } from '../../../test/collectivites-utils'; import { AuthenticatedUser } from '../../auth/models/auth.models'; -import { AppRouter, TrpcRouter } from '../../trpc/trpc.router'; +import { AppRouter, TrpcRouter } from '../../utils/trpc/trpc.router'; import { ScoreSnapshotInfoType } from '../models/get-score-snapshots.response'; import { ReferentielType } from '../models/referentiel.enum'; import { ScoreJalon } from '../models/score-jalon.enum'; diff --git a/backend/src/referentiels/update-action-statut/update-action-statut.router.e2e-spec.ts b/backend/src/referentiels/update-action-statut/update-action-statut.router.e2e-spec.ts index fcc99e352b..e783e091d5 100644 --- a/backend/src/referentiels/update-action-statut/update-action-statut.router.e2e-spec.ts +++ b/backend/src/referentiels/update-action-statut/update-action-statut.router.e2e-spec.ts @@ -2,7 +2,7 @@ import { inferProcedureInput } from '@trpc/server'; import { getTestRouter } from '../../../test/app-utils'; import { getAuthUser } from '../../../test/auth-utils'; import { getCollectiviteIdBySiren } from '../../../test/collectivites-utils'; -import { AppRouter, TrpcRouter } from '../../trpc/trpc.router'; +import { AppRouter, TrpcRouter } from '../../utils/trpc/trpc.router'; import { ActionScoreType } from '../models/action-score.dto'; import { ReferentielType } from '../models/referentiel.enum'; import { AuthenticatedUser } from './../../auth/models/auth.models'; @@ -26,7 +26,6 @@ describe('UpdateActionStatutRouter', () => { const caller = router.createCaller({ user: null }); const input: Input = { - referentielId: ReferentielType.CAE, actionStatut: { collectiviteId: 1, actionId: 'cae_1.1.1.2', @@ -47,7 +46,6 @@ describe('UpdateActionStatutRouter', () => { const caller = router.createCaller({ user: yoloDodoUser }); const input: Input = { - referentielId: ReferentielType.CAE, actionStatut: { collectiviteId: rhoneAggloCollectiviteId, actionId: 'cae_1.1.1.2', @@ -68,7 +66,6 @@ describe('UpdateActionStatutRouter', () => { const caller = router.createCaller({ user: yoloDodoUser }); const input: Input = { - referentielId: ReferentielType.CAE, actionStatut: { collectiviteId: 1, actionId: 'cae_1.1.1.11', @@ -91,7 +88,6 @@ describe('UpdateActionStatutRouter', () => { const caller = router.createCaller({ user: yoloDodoUser }); const input: Input = { - referentielId: ReferentielType.CAE, actionStatut: { collectiviteId: 1, actionId: 'cae_1.1.1.1.2', @@ -140,7 +136,6 @@ describe('UpdateActionStatutRouter', () => { // Restore the previous state const actionNonFaite: Input = { - referentielId: ReferentielType.CAE, actionStatut: { collectiviteId: 1, actionId: 'cae_1.1.1.1.2', diff --git a/backend/src/referentiels/update-action-statut/update-action-statut.router.ts b/backend/src/referentiels/update-action-statut/update-action-statut.router.ts index c5ae56e61f..2650aa8560 100644 --- a/backend/src/referentiels/update-action-statut/update-action-statut.router.ts +++ b/backend/src/referentiels/update-action-statut/update-action-statut.router.ts @@ -1,5 +1,5 @@ import { Injectable } from '@nestjs/common'; -import { TrpcService } from '../../trpc/trpc.service'; +import { TrpcService } from '@/backend/utils/trpc/trpc.service'; import { UpdateActionStatutService, upsertActionStatutRequestSchema, diff --git a/backend/src/referentiels/update-action-statut/update-action-statut.service.ts b/backend/src/referentiels/update-action-statut/update-action-statut.service.ts index 3034ae3c37..28a92cd0e0 100644 --- a/backend/src/referentiels/update-action-statut/update-action-statut.service.ts +++ b/backend/src/referentiels/update-action-statut/update-action-statut.service.ts @@ -1,11 +1,14 @@ +import { PermissionOperation } from '@/backend/auth/authorizations/permission-operation.enum'; +import { PermissionService } from '@/backend/auth/authorizations/permission.service'; +import { ResourceType } from '@/backend/auth/authorizations/resource-type.enum'; +import { DatabaseService } from '@/backend/utils'; import { Injectable, Logger, NotFoundException } from '@nestjs/common'; import { sql } from 'drizzle-orm'; import { PostgresError } from 'postgres'; import z from 'zod'; import { AuthenticatedUser } from '../../auth/models/auth.models'; -import { PgIntegrityConstraintViolation } from '../../common/models/postgresql-error-codes.enum'; -import DatabaseService from '../../common/services/database.service'; -import { getErrorWithCode } from '../../common/services/errors.helper'; +import { getErrorWithCode } from '../../utils/nest/errors.utils'; +import { PgIntegrityConstraintViolation } from '../../utils/postgresql-error-codes.enum'; import { actionStatutTable, createActionStatutSchema, @@ -14,9 +17,6 @@ import { ComputeScoreMode } from '../models/compute-scores-mode.enum'; import { GetReferentielScoresRequestType } from '../models/get-referentiel-scores.request'; import ReferentielsScoringService from '../services/referentiels-scoring.service'; import ReferentielsService from '../services/referentiels.service'; -import { PermissionService } from '@/backend/auth/authorizations/permission.service'; -import { PermissionOperation } from '@/backend/auth/authorizations/permission-operation.enum'; -import { ResourceType } from '@/backend/auth/authorizations/resource-type.enum'; export const upsertActionStatutRequestSchema = z.object({ actionStatut: createActionStatutSchema, diff --git a/backend/src/shared/index-domain.ts b/backend/src/shared/index-domain.ts new file mode 100644 index 0000000000..50fb079a2c --- /dev/null +++ b/backend/src/shared/index-domain.ts @@ -0,0 +1,9 @@ +// `index-domain.ts` file must only contain exports that are shareable with client-side apps. +// Exports from this file can be imported with `@/domain/*` alias path. + +export * from './models/banatic-competence.table'; +export * from './models/categorie-fnv.table'; +export * from './models/effet-attendu.table'; +export * from './models/sous-thematique.table'; +export * from './models/temps-de-mise-en-oeuvre.table'; +export * from './models/thematique.table'; diff --git a/backend/src/shared/index.ts b/backend/src/shared/index.ts new file mode 100644 index 0000000000..81ce45f809 --- /dev/null +++ b/backend/src/shared/index.ts @@ -0,0 +1 @@ +export * from './index-domain'; diff --git a/backend/src/taxonomie/models/banatic-competence.table.ts b/backend/src/shared/models/banatic-competence.table.ts similarity index 100% rename from backend/src/taxonomie/models/banatic-competence.table.ts rename to backend/src/shared/models/banatic-competence.table.ts diff --git a/backend/src/taxonomie/models/categorie-fnv.table.ts b/backend/src/shared/models/categorie-fnv.table.ts similarity index 100% rename from backend/src/taxonomie/models/categorie-fnv.table.ts rename to backend/src/shared/models/categorie-fnv.table.ts diff --git a/backend/src/taxonomie/models/effet-attendu.table.ts b/backend/src/shared/models/effet-attendu.table.ts similarity index 80% rename from backend/src/taxonomie/models/effet-attendu.table.ts rename to backend/src/shared/models/effet-attendu.table.ts index 5d32944f64..042a5139ee 100644 --- a/backend/src/taxonomie/models/effet-attendu.table.ts +++ b/backend/src/shared/models/effet-attendu.table.ts @@ -1,5 +1,6 @@ import { pgTable, serial, text } from 'drizzle-orm/pg-core'; import { createSelectSchema } from 'drizzle-zod'; +import z from 'zod'; export const effetAttenduTable = pgTable('effet_attendu', { id: serial('id').primaryKey(), @@ -8,3 +9,4 @@ export const effetAttenduTable = pgTable('effet_attendu', { }); export const effetAttenduSchema = createSelectSchema(effetAttenduTable); +export type EffetAttendu = z.infer; diff --git a/backend/src/taxonomie/models/sous-thematique.table.ts b/backend/src/shared/models/sous-thematique.table.ts similarity index 66% rename from backend/src/taxonomie/models/sous-thematique.table.ts rename to backend/src/shared/models/sous-thematique.table.ts index 69cd34bc00..bcd7ac253a 100644 --- a/backend/src/taxonomie/models/sous-thematique.table.ts +++ b/backend/src/shared/models/sous-thematique.table.ts @@ -5,26 +5,28 @@ import { text, uniqueIndex, } from 'drizzle-orm/pg-core'; -import { InferSelectModel } from 'drizzle-orm'; -import { thematiqueTable } from './thematique.table'; import { createSelectSchema } from 'drizzle-zod'; +import z from 'zod'; +import { thematiqueTable } from './thematique.table'; export const sousThematiqueTable = pgTable( 'sous_thematique', { id: serial('id').primaryKey(), + nom: text('sous_thematique').notNull(), thematiqueId: integer('thematique_id') .notNull() .references(() => thematiqueTable.id), - sousThematique: text('sous_thematique').notNull(), }, (table) => { return { - sousThematiqueSousThematiqueThematiqueIdKey: uniqueIndex( + sousThematiqueNonThematiqueIdKey: uniqueIndex( 'sous_thematique_sous_thematique_thematique_id_key ' - ).on(table.sousThematique, table.thematiqueId), + ).on(table.nom, table.thematiqueId), }; } ); -export type SousThematiqueType = InferSelectModel; + export const sousThematiqueSchema = createSelectSchema(sousThematiqueTable); + +export type SousThematique = z.infer; diff --git a/backend/src/shared/models/temps-de-mise-en-oeuvre.table.ts b/backend/src/shared/models/temps-de-mise-en-oeuvre.table.ts new file mode 100644 index 0000000000..539e967136 --- /dev/null +++ b/backend/src/shared/models/temps-de-mise-en-oeuvre.table.ts @@ -0,0 +1,17 @@ +import { pgTable, serial, text } from 'drizzle-orm/pg-core'; +import { createSelectSchema } from 'drizzle-zod'; +import z from 'zod'; + +export const tempsDeMiseEnOeuvreTable = pgTable( + 'action_impact_temps_de_mise_en_oeuvre', + { + id: serial('niveau').primaryKey(), + nom: text('nom').notNull(), + } +); + +export const tempsDeMiseEnOeuvreSchema = createSelectSchema( + tempsDeMiseEnOeuvreTable +); + +export type TempsDeMiseEnOeuvre = z.infer; diff --git a/backend/src/taxonomie/models/thematique.table.ts b/backend/src/shared/models/thematique.table.ts similarity index 89% rename from backend/src/taxonomie/models/thematique.table.ts rename to backend/src/shared/models/thematique.table.ts index 7cb290c822..d73cf31f3e 100644 --- a/backend/src/taxonomie/models/thematique.table.ts +++ b/backend/src/shared/models/thematique.table.ts @@ -1,6 +1,7 @@ import { InferSelectModel } from 'drizzle-orm'; import { pgTable, serial, text, varchar } from 'drizzle-orm/pg-core'; import { createSelectSchema } from 'drizzle-zod'; +import z from 'zod'; export const thematiqueTable = pgTable('thematique', { id: serial('id').primaryKey(), @@ -20,3 +21,5 @@ export const thematiqueSchema = thematiqueAvecAncienIdentifiantSchema.pick({ id: true, nom: true, }); + +export type Thematique = z.infer; diff --git a/backend/src/taxonomie/models/tag.table-base.ts b/backend/src/taxonomie/models/tag.table-base.ts deleted file mode 100644 index 8a28b1024c..0000000000 --- a/backend/src/taxonomie/models/tag.table-base.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { integer, serial, text } from 'drizzle-orm/pg-core'; -import { collectiviteTable } from '../../collectivites/models/collectivite.table'; - -export const tagTableBase = { - id: serial('id').primaryKey(), - nom: text('nom').notNull(), - collectiviteId: integer('collectivite_id') - .notNull() - .references(() => collectiviteTable.id), -}; - -export type TagType = { - id : number, - nom : string, - collectiviteId : number -} diff --git a/backend/src/taxonomie/models/temps-de-mise-en-oeuvre.table.ts b/backend/src/taxonomie/models/temps-de-mise-en-oeuvre.table.ts deleted file mode 100644 index 9092f85e55..0000000000 --- a/backend/src/taxonomie/models/temps-de-mise-en-oeuvre.table.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { pgTable, serial, text } from 'drizzle-orm/pg-core'; - -export const tempsDeMiseEnOeuvreTable = pgTable( - 'action_impact_temps_de_mise_en_oeuvre', - { - niveau: serial('niveau').primaryKey(), - nom: text('nom').notNull(), - } -); diff --git a/backend/src/taxonomie/services/thematique.service.ts b/backend/src/taxonomie/services/thematique.service.ts deleted file mode 100644 index ff4ada0f83..0000000000 --- a/backend/src/taxonomie/services/thematique.service.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { Injectable, Logger } from '@nestjs/common'; -import DatabaseService from '../../common/services/database.service'; -import { - sousThematiqueTable, - SousThematiqueType, -} from '../models/sous-thematique.table'; - -@Injectable() -export default class ThematiqueService { - private readonly logger = new Logger(ThematiqueService.name); - - constructor(private readonly databaseService: DatabaseService) {} - - /** - * Récupère les sous thématiques provenant de la BDD - * @return une map de sous thématiques avec en clé le nom de la sous thématique - */ - async getSousThematiquesMap(): Promise> { - const result = await this.databaseService.db - .select() - .from(sousThematiqueTable); - const toReturn = new Map(); - for (let i = 0; i < result.length; i++) { - const thematique = result[i]; - toReturn.set(thematique.sousThematique, thematique); - } - return toReturn; - } -} diff --git a/backend/src/taxonomie/taxonomie.module.ts b/backend/src/taxonomie/taxonomie.module.ts deleted file mode 100644 index 0d70fd5f62..0000000000 --- a/backend/src/taxonomie/taxonomie.module.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { Module } from '@nestjs/common'; -import { AuthModule } from '../auth/auth.module'; -import { CollectivitesModule } from '../collectivites/collectivites.module'; -import { CommonModule } from '../common/common.module'; -import { ConfigurationModule } from '../config/configuration.module'; -import TagService from '../taxonomie/services/tag.service'; -import { - GetCategoriesByCollectiviteRouter -} from '../taxonomie/routers/get-categories-by-collectivite.router'; - -@Module({ - imports: [ - ConfigurationModule, - CommonModule, - AuthModule, - CollectivitesModule, - ], - providers: [ - TagService, - GetCategoriesByCollectiviteRouter - ], - exports: [TagService, GetCategoriesByCollectiviteRouter], - controllers: [], -}) -export class TaxonomieModule {} - diff --git a/backend/src/config/configuration.model.ts b/backend/src/utils/config/configuration.model.ts similarity index 100% rename from backend/src/config/configuration.model.ts rename to backend/src/utils/config/configuration.model.ts diff --git a/backend/src/config/configuration.module.ts b/backend/src/utils/config/configuration.module.ts similarity index 81% rename from backend/src/config/configuration.module.ts rename to backend/src/utils/config/configuration.module.ts index f6a34547f9..440337dc0e 100644 --- a/backend/src/config/configuration.module.ts +++ b/backend/src/utils/config/configuration.module.ts @@ -1,7 +1,8 @@ -import { Module } from '@nestjs/common'; +import { Global, Module } from '@nestjs/common'; import { ConfigModule } from '@nestjs/config'; import ConfigurationService from './configuration.service'; +@Global() @Module({ imports: [ConfigModule.forRoot()], providers: [ConfigurationService], diff --git a/backend/src/config/configuration.service.ts b/backend/src/utils/config/configuration.service.ts similarity index 100% rename from backend/src/config/configuration.service.ts rename to backend/src/utils/config/configuration.service.ts diff --git a/backend/src/config/configuration.ts b/backend/src/utils/config/configuration.ts similarity index 100% rename from backend/src/config/configuration.ts rename to backend/src/utils/config/configuration.ts diff --git a/backend/src/common/models/count-synthese.dto.ts b/backend/src/utils/count-by.dto.ts similarity index 100% rename from backend/src/common/models/count-synthese.dto.ts rename to backend/src/utils/count-by.dto.ts diff --git a/backend/src/common/services/conflict.helper.ts b/backend/src/utils/database/conflict.utils.ts similarity index 100% rename from backend/src/common/services/conflict.helper.ts rename to backend/src/utils/database/conflict.utils.ts diff --git a/backend/src/utils/database/database.module.ts b/backend/src/utils/database/database.module.ts new file mode 100644 index 0000000000..cb10e22ac7 --- /dev/null +++ b/backend/src/utils/database/database.module.ts @@ -0,0 +1,10 @@ +import { Global, Module } from '@nestjs/common'; +import { DatabaseService } from './database.service'; +import SupabaseService from './supabase.service'; + +@Global() +@Module({ + providers: [DatabaseService, SupabaseService], + exports: [DatabaseService, SupabaseService], +}) +export class DatabaseModule {} diff --git a/backend/src/common/services/database.service.ts b/backend/src/utils/database/database.service.ts similarity index 93% rename from backend/src/common/services/database.service.ts rename to backend/src/utils/database/database.service.ts index 591ba41e59..94a125585b 100644 --- a/backend/src/common/services/database.service.ts +++ b/backend/src/utils/database/database.service.ts @@ -3,10 +3,10 @@ import { Injectable, Logger, OnApplicationShutdown } from '@nestjs/common'; import { sql } from 'drizzle-orm'; import { drizzle } from 'drizzle-orm/postgres-js'; import { default as postgres } from 'postgres'; -import ConfigurationService from '../../config/configuration.service'; +import ConfigurationService from '../config/configuration.service'; @Injectable() -export default class DatabaseService implements OnApplicationShutdown { +export class DatabaseService implements OnApplicationShutdown { private readonly logger = new Logger(DatabaseService.name); private readonly client = postgres( diff --git a/backend/src/common/services/supabase.service.ts b/backend/src/utils/database/supabase.service.ts similarity index 72% rename from backend/src/common/services/supabase.service.ts rename to backend/src/utils/database/supabase.service.ts index b2a9b4352b..1646953aa7 100644 --- a/backend/src/common/services/supabase.service.ts +++ b/backend/src/utils/database/supabase.service.ts @@ -1,18 +1,17 @@ -import { Database, DBClient } from '@/api'; import { Injectable, Logger } from '@nestjs/common'; import { createClient } from '@supabase/supabase-js'; -import ConfigurationService from '../../config/configuration.service'; +import ConfigurationService from '../config/configuration.service'; @Injectable() export default class SupabaseService { private readonly logger = new Logger(SupabaseService.name); - public readonly client: DBClient; + public readonly client: ReturnType; constructor(configService: ConfigurationService) { const supabaseUrl = configService.get('SUPABASE_URL'); this.logger.log(`Initializing supabase service with url: ${supabaseUrl}`); - this.client = createClient( + this.client = createClient( supabaseUrl, configService.get('SUPABASE_SERVICE_ROLE_KEY') ); diff --git a/backend/src/utils/enum.utils.ts b/backend/src/utils/enum.utils.ts index d44a300441..ec2241276f 100644 --- a/backend/src/utils/enum.utils.ts +++ b/backend/src/utils/enum.utils.ts @@ -4,3 +4,29 @@ export function getEnumValues( // Returns as a non-empty array return Object.values(enumObj) as [Enum, ...Enum[]]; } + +/** + * Permet de créer un objet jouant le rôle d'enum à partir d'une liste de chaînes + * + * Usage : + * ``` + * const Color = [ "Red", "Green", "Blue" ] as const + * const ColorEnum = createEnumObject(Color); + * + * const colorEnum = pgEnum("color", Color); + * const colorSchema = z.enum(Color); + * const table = pgTable("table",{enum: colorEnum("enum")}); + * db.insert(table).values({enum: ColorEnum.BLUE}); + * ``` + * + * Ref: https://github.com/drizzle-team/drizzle-orm/discussions/1914#discussioncomment-8816193 + */ +export const createEnumObject = ( + values: T +): Record, T[number]> => { + const obj: Record = {}; + for (const value of values) { + obj[value.toUpperCase()] = value; + } + return obj; +}; diff --git a/backend/src/common/services/xlsx.helper.ts b/backend/src/utils/excel/excel.utils.ts similarity index 100% rename from backend/src/common/services/xlsx.helper.ts rename to backend/src/utils/excel/excel.utils.ts diff --git a/backend/src/common/services/gcloud.helper.ts b/backend/src/utils/google-sheets/gcloud.helper.ts similarity index 81% rename from backend/src/common/services/gcloud.helper.ts rename to backend/src/utils/google-sheets/gcloud.helper.ts index a4d39c8ae4..bfae96e5dc 100644 --- a/backend/src/common/services/gcloud.helper.ts +++ b/backend/src/utils/google-sheets/gcloud.helper.ts @@ -3,7 +3,7 @@ import * as fs from 'fs'; const logger = new Logger('gcloud.helper'); -export const initApplicationCredentials = () => { +export const initGoogleCloudCredentials = () => { if ( process.env.GCLOUD_SERVICE_ACCOUNT_KEY && !process.env.GOOGLE_APPLICATION_CREDENTIALS @@ -15,13 +15,12 @@ export const initApplicationCredentials = () => { let credentialsJson = process.env.GCLOUD_SERVICE_ACCOUNT_KEY; if (!credentialsJson.includes('{')) { // Assume it's a base64 encoded string - credentialsJson = Buffer.from(credentialsJson, 'base64').toString('utf-8'); + credentialsJson = Buffer.from(credentialsJson, 'base64').toString( + 'utf-8' + ); } - - fs.writeFileSync( - serviceAccountFile, - credentialsJson - ); + + fs.writeFileSync(serviceAccountFile, credentialsJson); process.env.GOOGLE_APPLICATION_CREDENTIALS = serviceAccountFile; } }; diff --git a/backend/src/spreadsheets/models/sheetoptions.models.ts b/backend/src/utils/google-sheets/sheet-options.models.ts similarity index 100% rename from backend/src/spreadsheets/models/sheetoptions.models.ts rename to backend/src/utils/google-sheets/sheet-options.models.ts diff --git a/backend/src/spreadsheets/sheet.module.ts b/backend/src/utils/google-sheets/sheet.module.ts similarity index 74% rename from backend/src/spreadsheets/sheet.module.ts rename to backend/src/utils/google-sheets/sheet.module.ts index 48a4c66e41..13ef788548 100644 --- a/backend/src/spreadsheets/sheet.module.ts +++ b/backend/src/utils/google-sheets/sheet.module.ts @@ -1,5 +1,5 @@ import { Module } from '@nestjs/common'; -import SheetService from './services/sheet.service'; +import SheetService from './sheet.service'; @Module({ providers: [SheetService], diff --git a/backend/src/spreadsheets/services/sheet.service.ts b/backend/src/utils/google-sheets/sheet.service.ts similarity index 97% rename from backend/src/spreadsheets/services/sheet.service.ts rename to backend/src/utils/google-sheets/sheet.service.ts index df00854aae..7ff70fc816 100644 --- a/backend/src/spreadsheets/services/sheet.service.ts +++ b/backend/src/utils/google-sheets/sheet.service.ts @@ -4,14 +4,14 @@ import { Response } from 'express'; import * as gaxios from 'gaxios'; import * as auth from 'google-auth-library'; import { drive_v3, google, sheets_v4 } from 'googleapis'; -import { default as _ } from 'lodash'; +import * as _ from 'lodash'; import { z } from 'zod'; -import { initApplicationCredentials } from '../../common/services/gcloud.helper'; -import { getPropertyPaths } from '../../common/services/zod.helper'; +import { getPropertyPaths } from '../zod.utils'; +import { initGoogleCloudCredentials } from './gcloud.helper'; import { SheetValueInputOption, SheetValueRenderOption, -} from '../models/sheetoptions.models'; +} from './sheet-options.models'; const sheets = google.sheets({ version: 'v4' }); const drive = google.drive({ version: 'v3' }); @@ -43,7 +43,7 @@ export default class SheetService { | auth.Impersonated > { if (!this.authClient) { - initApplicationCredentials(); + initGoogleCloudCredentials(); this.authClient = await google.auth.getClient({ scopes: [ 'https://www.googleapis.com/auth/spreadsheets', diff --git a/backend/src/utils/index-domain.ts b/backend/src/utils/index-domain.ts new file mode 100644 index 0000000000..b8a8135053 --- /dev/null +++ b/backend/src/utils/index-domain.ts @@ -0,0 +1,8 @@ +// `index-domain.ts` file must only contain exports that are shareable with client-side apps. +// Exports from this file can be imported with `@/domain/*` alias path. + +export * from './column.utils'; +export * from './enum.utils'; +export * from './pagination.schema'; + +export type { AppRouter } from './trpc/trpc.router'; diff --git a/backend/src/utils/index.ts b/backend/src/utils/index.ts index dc308c60a0..ac2e13e9a5 100644 --- a/backend/src/utils/index.ts +++ b/backend/src/utils/index.ts @@ -1,2 +1,2 @@ -export * from './column.utils'; -export * from './enum.utils'; +export * from './database/database.service'; +export * from './index-domain'; diff --git a/backend/src/common/services/mattermost-notification.service.ts b/backend/src/utils/mattermost-notification.service.ts similarity index 91% rename from backend/src/common/services/mattermost-notification.service.ts rename to backend/src/utils/mattermost-notification.service.ts index 8456a4b338..90f7b125a3 100644 --- a/backend/src/common/services/mattermost-notification.service.ts +++ b/backend/src/utils/mattermost-notification.service.ts @@ -1,6 +1,6 @@ import { Injectable, Logger } from '@nestjs/common'; -import ConfigurationService from '../../config/configuration.service'; -import { getErrorMessage } from './errors.helper'; +import ConfigurationService from './config/configuration.service'; +import { getErrorMessage } from './nest/errors.utils'; @Injectable() export default class MattermostNotificationService { diff --git a/backend/src/common/models/modified-since.enum.ts b/backend/src/utils/modified-since.enum.ts similarity index 100% rename from backend/src/common/models/modified-since.enum.ts rename to backend/src/utils/modified-since.enum.ts diff --git a/backend/src/common/filters/all-exceptions.filter.ts b/backend/src/utils/nest/all-exceptions.filter.ts similarity index 92% rename from backend/src/common/filters/all-exceptions.filter.ts rename to backend/src/utils/nest/all-exceptions.filter.ts index 58c97fd2dc..3dadb4e499 100644 --- a/backend/src/common/filters/all-exceptions.filter.ts +++ b/backend/src/utils/nest/all-exceptions.filter.ts @@ -3,8 +3,8 @@ import { ArgumentsHost, Catch, HttpException, Logger } from '@nestjs/common'; import { BaseExceptionFilter } from '@nestjs/core'; import { SentryExceptionCaptured } from '@sentry/nestjs'; import { Request, Response } from 'express'; -import { HttpErrorResponse } from '../models/http-error.response'; -import { getErrorWithCode } from '../services/errors.helper'; +import { getErrorWithCode } from './errors.utils'; +import { HttpErrorResponse } from './http-error.response'; export const getHttpErrorResponse = (exception: unknown): HttpErrorResponse => { const errorWithCode = getErrorWithCode(exception); diff --git a/backend/src/common/services/errors.helper.ts b/backend/src/utils/nest/errors.utils.ts similarity index 100% rename from backend/src/common/services/errors.helper.ts rename to backend/src/utils/nest/errors.utils.ts diff --git a/backend/src/common/models/http-error.response.ts b/backend/src/utils/nest/http-error.response.ts similarity index 100% rename from backend/src/common/models/http-error.response.ts rename to backend/src/utils/nest/http-error.response.ts diff --git a/backend/src/common/services/number.helper.spec.ts b/backend/src/utils/number.helper.spec.ts similarity index 100% rename from backend/src/common/services/number.helper.spec.ts rename to backend/src/utils/number.helper.spec.ts diff --git a/backend/src/common/services/number.helper.ts b/backend/src/utils/number.helper.ts similarity index 100% rename from backend/src/common/services/number.helper.ts rename to backend/src/utils/number.helper.ts diff --git a/packages/api/src/shared/domain/query_options.schema.ts b/backend/src/utils/pagination.schema.ts similarity index 73% rename from packages/api/src/shared/domain/query_options.schema.ts rename to backend/src/utils/pagination.schema.ts index 9adbe7aba3..5c27a766cb 100644 --- a/packages/api/src/shared/domain/query_options.schema.ts +++ b/backend/src/utils/pagination.schema.ts @@ -1,21 +1,21 @@ import { z } from 'zod'; -export const sortSchema = z.object({ +const sortSchema = z.object({ field: z.string(), direction: z.enum(['asc', 'desc']).default('desc'), }); -export const queryOptionsSchema = z.object({ +const paginationSchema = z.object({ sort: sortSchema.array().optional(), page: z.number().optional().default(1), limit: z.number().min(1).max(1000).default(1000), }); -export function getQueryOptionsSchema< +export function getPaginationSchema< U extends string, T extends Readonly<[U, ...U[]]> >(sortFields: T) { - return queryOptionsSchema.extend({ + return paginationSchema.extend({ sort: sortSchema .extend({ field: z.enum(sortFields), diff --git a/backend/src/common/models/postgresql-error-codes.enum.ts b/backend/src/utils/postgresql-error-codes.enum.ts similarity index 100% rename from backend/src/common/models/postgresql-error-codes.enum.ts rename to backend/src/utils/postgresql-error-codes.enum.ts diff --git a/backend/src/common/services/sentry.service.ts b/backend/src/utils/sentry-init.ts similarity index 100% rename from backend/src/common/services/sentry.service.ts rename to backend/src/utils/sentry-init.ts diff --git a/backend/src/common/services/sleep.helper.ts b/backend/src/utils/sleep.utils.ts similarity index 100% rename from backend/src/common/services/sleep.helper.ts rename to backend/src/utils/sleep.utils.ts diff --git a/backend/src/trpc/trpc.module.ts b/backend/src/utils/trpc/trpc.module.ts similarity index 100% rename from backend/src/trpc/trpc.module.ts rename to backend/src/utils/trpc/trpc.module.ts index 7f81c8ffa5..5edcd67ce6 100644 --- a/backend/src/trpc/trpc.module.ts +++ b/backend/src/utils/trpc/trpc.module.ts @@ -1,5 +1,5 @@ -import { Global, Module } from '@nestjs/common'; import { TrpcService } from './trpc.service'; +import { Global, Module } from '@nestjs/common'; @Global() @Module({ diff --git a/backend/src/trpc/trpc.router.ts b/backend/src/utils/trpc/trpc.router.ts similarity index 63% rename from backend/src/trpc/trpc.router.ts rename to backend/src/utils/trpc/trpc.router.ts index 5279f7a2c2..09ee01c91c 100644 --- a/backend/src/trpc/trpc.router.ts +++ b/backend/src/utils/trpc/trpc.router.ts @@ -1,17 +1,17 @@ +import { BulkEditRouter } from '@/backend/plans/fiches/bulk-edit/bulk-edit.router'; +import { CountByStatutRouter } from '@/backend/plans/fiches/count-by-statut/count-by-statut.router'; +import { FicheActionEtapeRouter } from '@/backend/plans/fiches/fiche-action-etape/fiche-action-etape.router'; import { INestApplication, Injectable, Logger } from '@nestjs/common'; import { createExpressMiddleware } from '@trpc/server/adapters/express'; -import { CollectiviteMembresRouter } from '../collectivites/membres/membres.router'; -import { PersonnesRouter } from '../collectivites/personnes.router'; -import SupabaseService from '../common/services/supabase.service'; -import { BulkEditRouter } from '../fiches/bulk-edit/bulk-edit.router'; -import { CountByStatutRouter } from '../fiches/count-by-statut/count-by-statut.router'; -import { FicheActionEtapeRouter } from '../fiches/fiche-action-etape/fiche-action-etape.router'; -import { IndicateurFiltreRouter } from '../indicateurs/indicateur-filtre/indicateur-filtre.router'; -import { TrajectoiresRouter } from '../indicateurs/routers/trajectoires.router'; -import { ComputeScoreRouter } from '../referentiels/compute-score/compute-score.router'; -import { ScoreSnapshotsRouter } from '../referentiels/snapshots/score-snaphots.router'; -import { UpdateActionStatutRouter } from '../referentiels/update-action-statut/update-action-statut.router'; -import { GetCategoriesByCollectiviteRouter } from '../taxonomie/routers/get-categories-by-collectivite.router'; +import { ListCategoriesRouter } from '../../collectivites/handle-categories/list-categories.router'; +import { CollectiviteMembresRouter } from '../../collectivites/membres/membres.router'; +import { PersonnesRouter } from '../../collectivites/personnes.router'; +import { IndicateurFiltreRouter } from '../../indicateurs/indicateur-filtre/indicateur-filtre.router'; +import { TrajectoiresRouter } from '../../indicateurs/routers/trajectoires.router'; +import { ComputeScoreRouter } from '../../referentiels/compute-score/compute-score.router'; +import { ScoreSnapshotsRouter } from '../../referentiels/snapshots/score-snaphots.router'; +import { UpdateActionStatutRouter } from '../../referentiels/update-action-statut/update-action-statut.router'; +import SupabaseService from '../database/supabase.service'; import { createContext, TrpcService } from './trpc.service'; @Injectable() @@ -23,7 +23,7 @@ export class TrpcRouter { private readonly supabase: SupabaseService, private readonly trajectoiresRouter: TrajectoiresRouter, private readonly countByStatutRouter: CountByStatutRouter, - private readonly getCategoriesByCollectiviteRouter: GetCategoriesByCollectiviteRouter, + private readonly getCategoriesByCollectiviteRouter: ListCategoriesRouter, private readonly personnes: PersonnesRouter, private readonly ficheActionEtapeRouter: FicheActionEtapeRouter, private readonly indicateurFiltreRouter: IndicateurFiltreRouter, @@ -37,7 +37,7 @@ export class TrpcRouter { appRouter = this.trpc.router({ indicateurs: { trajectoires: this.trajectoiresRouter.router, - filtre: this.indicateurFiltreRouter.router, + list: this.indicateurFiltreRouter.router.list, }, plans: { fiches: this.trpc.mergeRouters( @@ -49,8 +49,6 @@ export class TrpcRouter { collectivites: { personnes: this.personnes.router, membres: this.membresRouter.router, - }, - tags: { categories: this.getCategoriesByCollectiviteRouter.router, }, referentiels: { diff --git a/backend/src/trpc/trpc.service.ts b/backend/src/utils/trpc/trpc.service.ts similarity index 98% rename from backend/src/trpc/trpc.service.ts rename to backend/src/utils/trpc/trpc.service.ts index e6bf12b314..942e90867d 100644 --- a/backend/src/trpc/trpc.service.ts +++ b/backend/src/utils/trpc/trpc.service.ts @@ -6,7 +6,7 @@ import { AuthUser, isAnonymousUser, isAuthenticatedUser, -} from '../auth/models/auth.models'; +} from '../../auth/models/auth.models'; @Injectable() export class TrpcService { diff --git a/backend/src/utils/utils.module.ts b/backend/src/utils/utils.module.ts new file mode 100644 index 0000000000..f8e13ea85c --- /dev/null +++ b/backend/src/utils/utils.module.ts @@ -0,0 +1,11 @@ +import { Global, Module } from '@nestjs/common'; +import MattermostNotificationService from './mattermost-notification.service'; +import { VersionController } from './version/version.controller'; + +@Global() +@Module({ + providers: [MattermostNotificationService], + exports: [MattermostNotificationService], + controllers: [VersionController], +}) +export class UtilsModule {} diff --git a/backend/src/common/controllers/version.controller.ts b/backend/src/utils/version/version.controller.ts similarity index 94% rename from backend/src/common/controllers/version.controller.ts rename to backend/src/utils/version/version.controller.ts index 2cc07c830d..12fb2dc33d 100644 --- a/backend/src/common/controllers/version.controller.ts +++ b/backend/src/utils/version/version.controller.ts @@ -2,7 +2,7 @@ import { createZodDto } from '@anatine/zod-nestjs'; import { Controller, Get } from '@nestjs/common'; import { ApiOkResponse, ApiTags } from '@nestjs/swagger'; import { AllowPublicAccess } from '../../auth/decorators/allow-public-access.decorator'; -import { versionResponseSchema } from '../models/version.models'; +import { versionResponseSchema } from './version.models'; /** * Création des classes de réponse à partir du schema pour générer automatiquement la documentation OpenAPI diff --git a/backend/src/common/models/version.models.ts b/backend/src/utils/version/version.models.ts similarity index 100% rename from backend/src/common/models/version.models.ts rename to backend/src/utils/version/version.models.ts diff --git a/backend/src/common/services/zod.helper.ts b/backend/src/utils/zod.utils.ts similarity index 100% rename from backend/src/common/services/zod.helper.ts rename to backend/src/utils/zod.utils.ts diff --git a/backend/test/app-utils.ts b/backend/test/app-utils.ts index d2617d68e6..9f42d5c913 100644 --- a/backend/test/app-utils.ts +++ b/backend/test/app-utils.ts @@ -2,8 +2,8 @@ import { ZodValidationPipe } from '@anatine/zod-nestjs/src/lib/zod-validation-pi import { INestApplication } from '@nestjs/common'; import { Test } from '@nestjs/testing'; import { AppModule } from '../src/app.module'; -import DatabaseService from '../src/common/services/database.service'; -import { TrpcRouter } from '../src/trpc/trpc.router'; +import { DatabaseService } from '../src/utils/database/database.service'; +import { TrpcRouter } from '../src/utils/trpc/trpc.router'; export const getTestApp = async (): Promise => { const moduleRef = await Test.createTestingModule({ diff --git a/packages/api/src/index.ts b/packages/api/src/index.ts index e03d35bbc8..6b110f54f4 100644 --- a/packages/api/src/index.ts +++ b/packages/api/src/index.ts @@ -1,12 +1,10 @@ -export * from './typeUtils'; +export * as CollectiviteEngagee from './collectiviteEngagees'; export type { Database, Json } from './database.types'; -export { unaccent } from './utils/unaccent'; -export * from './utils/authTokens'; -export * from './utils/pathUtils'; -export * from './utils/makeSearchString'; -export * from './utils/isAllowedOrigin'; export * as Indicateurs from './indicateurs'; -export * as CollectiviteEngagee from './collectiviteEngagees'; export * from './panier_action_impact'; - -export * as SharedDomain from './shared/domain'; +export * from './typeUtils'; +export * from './utils/authTokens'; +export * from './utils/isAllowedOrigin'; +export * from './utils/makeSearchString'; +export * from './utils/pathUtils'; +export { unaccent } from './utils/unaccent'; diff --git a/packages/api/src/indicateurs/actions/indicateur.fetch.ts b/packages/api/src/indicateurs/actions/indicateur.fetch.ts index 37cbc642bb..9b955622e8 100644 --- a/packages/api/src/indicateurs/actions/indicateur.fetch.ts +++ b/packages/api/src/indicateurs/actions/indicateur.fetch.ts @@ -7,7 +7,6 @@ import { Groupement } from '../../collectivites/shared/domain/groupement.schema' import { Tables } from '../../database.types'; import { FicheResume } from '../../plan-actions/domain/fiche-action.schema'; import { Action } from '../../referentiel/domain/action.schema'; -import { Thematique } from '../../shared/domain'; import { Personne } from '../../collectivites/shared/domain/personne.schema'; import { DBClient } from '../../typeUtils'; import { Source, SourceMetadonnee } from '../domain'; @@ -20,6 +19,7 @@ import { ValeurComparaison, ValeurComparaisonLigne, } from '../domain/valeur.schema'; +import { Thematique } from '@/domain/shared'; // cas spécial pour cet indicateur TODO: utiliser un champ distinct dans les markdowns plutôt que cet ID "en dur" const ID_COMPACITE_FORMES_URBAINES = 'cae_9'; diff --git a/packages/api/src/indicateurs/actions/indicateur.save.test.ts b/packages/api/src/indicateurs/actions/indicateur.save.test.ts index 2c563d9f9e..39c8188328 100644 --- a/packages/api/src/indicateurs/actions/indicateur.save.test.ts +++ b/packages/api/src/indicateurs/actions/indicateur.save.test.ts @@ -1,9 +1,9 @@ +import { TagInsert } from '@/domain/collectivites'; +import { Thematique } from '@/domain/shared'; import { beforeAll, describe, expect, test } from 'vitest'; import { Personne } from '../../collectivites/shared/domain/personne.schema'; import { FicheResume } from '../../plan-actions/domain/fiche-action.schema'; import { Action } from '../../referentiel/domain/action.schema'; -import { TagInsert } from '../../shared/domain/tag.schema'; -import { Thematique } from '../../shared/domain/thematique.schema'; import { signIn, signOut } from '../../tests/auth'; import { dbAdmin, supabase } from '../../tests/supabase'; import { testReset } from '../../tests/testReset'; diff --git a/packages/api/src/indicateurs/actions/indicateur.save.ts b/packages/api/src/indicateurs/actions/indicateur.save.ts index a5be817933..28f3b506c8 100644 --- a/packages/api/src/indicateurs/actions/indicateur.save.ts +++ b/packages/api/src/indicateurs/actions/indicateur.save.ts @@ -1,11 +1,11 @@ +import { Tag, TagInsert } from '@/domain/collectivites'; +import { Thematique } from '@/domain/shared'; import { isNil } from 'es-toolkit/predicate'; import { objectToSnake } from 'ts-case-convert'; +import { Personne } from '../../collectivites/shared/domain/personne.schema'; import { Action } from '../../referentiel/domain/action.schema'; import { selectTags } from '../../shared/actions/tag.fetch'; import { insertTags } from '../../shared/actions/tag.save'; -import { Personne } from '../../collectivites/shared/domain/personne.schema'; -import { Tag, TagInsert } from '../../shared/domain/tag.schema'; -import { Thematique } from '../../shared/domain/thematique.schema'; import { DBClient, TablesInsert } from '../../typeUtils'; import { IndicateurDefinition, diff --git a/packages/api/src/indicateurs/domain/definition.schema.ts b/packages/api/src/indicateurs/domain/definition.schema.ts index e310441019..c0832cc909 100644 --- a/packages/api/src/indicateurs/domain/definition.schema.ts +++ b/packages/api/src/indicateurs/domain/definition.schema.ts @@ -1,6 +1,6 @@ +import { thematiqueSchema } from '@/domain/shared'; import { z } from 'zod'; import { actionSchema } from '../../referentiel/domain/action.schema'; -import { thematiqueSchema } from '../../shared/domain/thematique.schema'; import { categorieSchema } from './categorie.schema'; /** @@ -138,4 +138,4 @@ export const definitionPredefiniSchema = definitionSchema.omit({ */ export type IndicateurDefinitionPredefini = z.input< typeof definitionPredefiniSchema ->; \ No newline at end of file +>; diff --git a/packages/api/src/indicateurs/domain/fetch-options.schema.ts b/packages/api/src/indicateurs/domain/fetch-options.schema.ts index e32ef3c000..6106407c09 100644 --- a/packages/api/src/indicateurs/domain/fetch-options.schema.ts +++ b/packages/api/src/indicateurs/domain/fetch-options.schema.ts @@ -1,6 +1,6 @@ +import { getPaginationSchema } from '@/domain/utils'; import { z } from 'zod'; import { filtreRessourceLieesSchema } from '../../collectivites/shared/domain/filtre-ressource-liees.schema'; -import { getQueryOptionsSchema } from '../../shared/domain/query_options.schema'; export const filtreSpecifiqueSchema = z.object({ actionId: z.string().optional(), @@ -35,7 +35,7 @@ export const filtreSchema = filtreRessourceLieesSchema export type FetchFiltre = z.infer; -export const fetchOptionsSchema = getQueryOptionsSchema([ +export const fetchOptionsSchema = getPaginationSchema([ 'text', 'estComplet', ]).extend({ diff --git a/packages/api/src/indicateurs/domain/indicateur-definition-extended.schema.ts b/packages/api/src/indicateurs/domain/indicateur-definition-extended.schema.ts deleted file mode 100644 index f36b75444a..0000000000 --- a/packages/api/src/indicateurs/domain/indicateur-definition-extended.schema.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { ficheResumeSchema } from '@/api/plan-actions'; -import { personneSchema, tagSchema } from '@/api/shared/domain'; -import { z } from 'zod'; -import { definitionSchema } from './definition.schema'; -import { valeurSchema } from './valeur.schema'; - -/** - * Schéma zod à fusionner à une définition pour avoir les valeurs - */ -const plusValeur = z.object({ - valeurs: valeurSchema.array(), -}); - -/** - * Schéma zod à fusionner à une définition pour avoir les données annexes aux indicateurs - */ -const plusDetailsCollectivite = z.object({ - services: z.number().array(), // Lise d'id - pilotes: personneSchema.array(), - fiches: ficheResumeSchema.array(), - fichesNonClassees: ficheResumeSchema.array(), - categoriesUtilisateur: tagSchema.array(), -}); - -/** - * Schéma zod d'un indicateur avec toutes les informations annexes liées - */ -export const definitionCompleteSchema = definitionSchema - .merge(plusValeur) - .merge(plusDetailsCollectivite); -/** - * Type TS d'un indicateur avec toutes les informations annexes liées - */ -export type IndicateurDefinitionComplet = z.input< - typeof definitionCompleteSchema ->; diff --git a/packages/api/src/plan-actions/domain/axe.schema.ts b/packages/api/src/plan-actions/domain/axe.schema.ts deleted file mode 100644 index ff53d89c6e..0000000000 --- a/packages/api/src/plan-actions/domain/axe.schema.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { z } from 'zod'; -import { planActionTypeSchema } from './plan-action-type.schema'; - -export const baseAxeSchema = z.object({ - id: z.number(), - collectiviteId: z.number(), - nom: z.string().nullable().optional(), - parent: z.number().nullable(), - plan: z.number().nullable(), - type: planActionTypeSchema.nullable(), - createdAt: z.string().date().optional(), - modifiedAt: z.string().date().optional(), - modifiedBy: z.string().nullable(), -}); - -export const axeSchema = baseAxeSchema.extend({ - axes: z.array(baseAxeSchema).optional(), -}); - -export type Axe = z.input; - -export const axeInsertSchema = baseAxeSchema.extend({ - id: z.number().optional(), -}); - -export type AxeInsert = z.input; diff --git a/packages/api/src/plan-actions/domain/fiche-action.schema.ts b/packages/api/src/plan-actions/domain/fiche-action.schema.ts index 13b1980a45..0144343604 100644 --- a/packages/api/src/plan-actions/domain/fiche-action.schema.ts +++ b/packages/api/src/plan-actions/domain/fiche-action.schema.ts @@ -1,120 +1,44 @@ import { personneSchema } from '@/api/collectivites'; import { indicateurListItemSchema } from '@/api/indicateurs/domain'; import { actionSchema } from '@/api/referentiel'; +import { authorSchema } from '@/domain/auth'; +import { tagSchema } from '@/domain/collectivites'; import { - sousThematiqueSchemaId, - tagSchema, + axeSchema, + ciblesEnumSchema, + financeurSchemaUpdate, + participationCitoyenneEnumSchema, + prioriteEnumSchema, + statutsEnumSchema, +} from '@/domain/plans/fiches'; +import { + effetAttenduSchema, + sousThematiqueSchema, + tempsDeMiseEnOeuvreSchema, thematiqueSchema, -} from '@/api/shared/domain'; +} from '@/domain/shared'; import { z } from 'zod'; -import { axeSchema } from './axe.schema'; - -// Enums - -export const statutSchema = z.enum([ - 'À venir', - 'En cours', - 'Réalisé', - 'En pause', - 'Abandonné', - 'Bloqué', - 'En retard', - 'A discuter', -]); - -export type Statut = z.infer; - -export const niveauPrioriteSchema = z.enum(['Élevé', 'Moyen', 'Bas']); - -export type NiveauPriorite = z.infer; - -export const cibleSchema = z.enum([ - 'Grand public', - 'Associations', - 'Grand public et associations', - 'Public Scolaire', - 'Autres collectivités du territoire', - 'Acteurs économiques', - 'Acteurs économiques du secteur primaire', - 'Acteurs économiques du secteur secondaire', - 'Acteurs économiques du secteur tertiaire', - 'Partenaires', - 'Collectivité elle-même', - 'Elus locaux', - 'Agents', -]); - -export type Cible = z.infer; - -export const participationCitoyenneTypeSchema = z.enum([ - 'pas-de-participation', - 'information', - 'consultation', - 'concertation', - 'co-construction', -]); - -export type ParticipationCitoyenne = z.infer< - typeof participationCitoyenneTypeSchema ->; - -export const effetsAttendus = z.object({ - id: z.number(), - nom: z.string(), - notice: z.string().nullish(), -}); - -export type EffetsAttendus = z.infer; - -export const financeurSchema = z.object({ - financeurTag: tagSchema, - montantTtc: z.number().nullish(), -}); - -export type Financeur = z.infer; - -export const tempsDeMiseEnOeuvreSchema = z.object({ - id: z.number(), - nom: z.string(), -}); - -export type TempsDeMiseEnOeuvre = z.infer; - -const auteur = z.object({ - userId: z.string(), - prenom: z.string(), - nom: z.string(), - email: z.string(), -}); - -const libreTagSchema = z.object({ - id: z.number().nullish(), - nom: z.string(), - collectivitedId: z.number().nullish(), - createdAt: z.string().date().nullish(), - createdBy: z.string().nullish(), -}); export const ficheActionSchema = z.object({ id: z.number(), collectiviteId: z.number(), modifiedAt: z.string().datetime().nullish(), createdAt: z.string().datetime().nullish(), - createdBy: auteur.nullable(), - modifiedBy: auteur.nullable(), + createdBy: authorSchema.nullable(), + modifiedBy: authorSchema.nullable(), titre: z.string().nullable(), description: z.string().nullish(), - statut: statutSchema.nullish(), + statut: statutsEnumSchema.nullish(), ameliorationContinue: z.boolean().nullish(), dateFinProvisoire: z .string() .date() .or(z.string().datetime({ offset: true })) .nullish(), - priorite: niveauPrioriteSchema.nullish(), - cibles: cibleSchema.array().nullish(), + priorite: prioriteEnumSchema.nullish(), + cibles: ciblesEnumSchema.array().nullish(), restreint: z.boolean().nullish(), - resultatsAttendus: effetsAttendus.array().nullish(), + resultatsAttendus: effetAttenduSchema.array().nullish(), objectifs: z.string().nullish(), budgetPrevisionnel: z.number().nullish(), calendrier: z.string().nullish(), @@ -128,7 +52,7 @@ export const ficheActionSchema = z.object({ financements: z.string().nullish(), instanceGouvernance: z.string().nullish(), participationCitoyenne: z.string().nullish(), - participationCitoyenneType: participationCitoyenneTypeSchema.nullish(), + participationCitoyenneType: participationCitoyenneEnumSchema.nullish(), tempsDeMiseEnOeuvre: tempsDeMiseEnOeuvreSchema.nullish(), actionImpactId: z.number().nullish(), @@ -138,7 +62,7 @@ export const ficheActionSchema = z.object({ // Tables liées thematiques: thematiqueSchema.array().nullish(), - sousThematiques: sousThematiqueSchemaId.array().nullish(), + sousThematiques: sousThematiqueSchema.array().nullish(), pilotes: personneSchema.array().nullish(), referents: personneSchema.array().nullish(), services: tagSchema.array().nullish(), @@ -147,9 +71,12 @@ export const ficheActionSchema = z.object({ plans: axeSchema.array().nullish(), axes: axeSchema.array().nullish(), actions: actionSchema.array().nullish(), - financeurs: financeurSchema.array().nullish(), + financeurs: financeurSchemaUpdate + // .extend({ id: financeurSchema.shape.id.optional() }) + .array() + .nullish(), indicateurs: indicateurListItemSchema.array().nullish(), - libresTag: libreTagSchema.array().nullish(), + libresTag: tagSchema.array().nullish(), }); export type FicheAction = z.infer; diff --git a/packages/api/src/plan-actions/domain/index.ts b/packages/api/src/plan-actions/domain/index.ts index 1129dc91fd..8b8065b931 100644 --- a/packages/api/src/plan-actions/domain/index.ts +++ b/packages/api/src/plan-actions/domain/index.ts @@ -1,2 +1 @@ -export * from './axe.schema'; export * from './fiche-action.schema'; diff --git a/packages/api/src/plan-actions/domain/plan-action-type.schema.ts b/packages/api/src/plan-actions/domain/plan-action-type.schema.ts deleted file mode 100644 index cea8732829..0000000000 --- a/packages/api/src/plan-actions/domain/plan-action-type.schema.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { z } from 'zod'; - -export const planActionTypeSchema = z.object({ - id: z.number(), - categorie: z.string(), - type: z.string(), - detail: z.string().nullable(), -}); - -export type PlanActionType = z.input; diff --git a/packages/api/src/plan-actions/fiche-resumes.list/data-access/fiche-action.fetch.ts b/packages/api/src/plan-actions/fiche-resumes.list/data-access/fiche-action.fetch.ts index 8a92c2a40e..e419289f2b 100644 --- a/packages/api/src/plan-actions/fiche-resumes.list/data-access/fiche-action.fetch.ts +++ b/packages/api/src/plan-actions/fiche-resumes.list/data-access/fiche-action.fetch.ts @@ -95,6 +95,15 @@ export async function ficheActionFetch({ dbClient, ficheActionId }: Props) { ...rawFicheAction, planId: rawFicheAction.plans?.[0]?.plan, indicateurs: indicateurs.data, + + // Transforme les sous-thématiques pour matcher avec le schema officiel + sousThematiques: rawFicheAction.sousThematiques + ? rawFicheAction.sousThematiques.map((t) => ({ + ...t, + // @ts-expect-error forcing temporaire pour matcher le schema le temps de passer le fetch côté backend + nom: t.sousThematique, + })) + : null, }; return ficheAction as FicheAction; diff --git a/packages/api/src/plan-actions/fiche-resumes.list/domain/fetch-options.schema.ts b/packages/api/src/plan-actions/fiche-resumes.list/domain/fetch-options.schema.ts index 95eaac80ca..a26e11fb3c 100644 --- a/packages/api/src/plan-actions/fiche-resumes.list/domain/fetch-options.schema.ts +++ b/packages/api/src/plan-actions/fiche-resumes.list/domain/fetch-options.schema.ts @@ -1,7 +1,11 @@ +import { + ciblesEnumSchema, + prioriteEnumSchema, + statutsEnumSchema, +} from '@/domain/plans/fiches'; +import { getPaginationSchema } from '@/domain/utils'; import { z } from 'zod'; import { filtreRessourceLieesSchema } from '../../../collectivites/shared/domain/filtre-ressource-liees.schema'; -import { getQueryOptionsSchema } from '../../../shared/domain/query_options.schema'; -import { cibleSchema, niveauPrioriteSchema, statutSchema } from '../../domain'; export const modifiedSinceSchema = z.enum([ 'last-90-days', @@ -13,9 +17,9 @@ export const modifiedSinceSchema = z.enum([ export type ModifiedSince = z.infer; export const filtreSpecifiqueSchema = z.object({ - statuts: statutSchema.array().optional(), - priorites: niveauPrioriteSchema.array().optional(), - cibles: cibleSchema.array().optional(), + statuts: statutsEnumSchema.array().optional(), + priorites: prioriteEnumSchema.array().optional(), + cibles: ciblesEnumSchema.array().optional(), modifiedSince: modifiedSinceSchema.optional(), texteNomOuDescription: z.string().optional(), budgetPrevisionnel: z.coerce.boolean().default(false).optional(), @@ -68,7 +72,7 @@ const sortFicheSchema = z.object({ export type SortFichesAction = z.infer; -export const fetchOptionsSchema = getQueryOptionsSchema(sortValues).extend({ +export const fetchOptionsSchema = getPaginationSchema(sortValues).extend({ filtre: filtreSchema, }); diff --git a/packages/api/src/plan-actions/index.ts b/packages/api/src/plan-actions/index.ts index 05424383d4..8307c7d45c 100644 --- a/packages/api/src/plan-actions/index.ts +++ b/packages/api/src/plan-actions/index.ts @@ -1,9 +1,8 @@ -export * from './domain/axe.schema'; export * from './domain/fiche-action.schema'; export * from './fiche-resumes.list/data-access/fiche-action.fetch'; export * from './fiche-resumes.list/data-access/fiche-action.save'; export * from './fiche-resumes.list/data-access/fiche-resumes.fetch'; +export * from './plan-actions.list/data-access/plan-actions-pilotable.fetch'; export * from './plan-actions.list/data-access/plan-actions.count'; export * from './plan-actions.list/data-access/plan-actions.fetch'; -export * from './plan-actions.list/data-access/plan-actions-pilotable.fetch'; export * from './plan-actions.list/domain/fetch-options.schema'; diff --git a/packages/api/src/plan-actions/plan-actions.list/data-access/plan-actions.fetch.ts b/packages/api/src/plan-actions/plan-actions.list/data-access/plan-actions.fetch.ts index ae4c270c87..872d38fbc0 100644 --- a/packages/api/src/plan-actions/plan-actions.list/data-access/plan-actions.fetch.ts +++ b/packages/api/src/plan-actions/plan-actions.list/data-access/plan-actions.fetch.ts @@ -1,15 +1,16 @@ import { DBClient } from '@/api/typeUtils'; +import { Axe, PlanActionType } from '@/domain/plans/fiches'; import { objectToCamel } from 'ts-case-convert'; -import { Axe } from '../../domain'; import { FetchOptions, fetchOptionsSchema, FetchSort, } from '../domain/fetch-options.schema'; -type FetchedPlanAction = Axe & { +interface FetchedPlanAction extends Omit { axes?: Axe[]; -}; + type: PlanActionType | null; +} type TFetchedData = { plans: FetchedPlanAction[]; diff --git a/packages/api/src/plan-actions/plan-actions.list/domain/fetch-options.schema.ts b/packages/api/src/plan-actions/plan-actions.list/domain/fetch-options.schema.ts index 9742c614f9..1442d87d95 100644 --- a/packages/api/src/plan-actions/plan-actions.list/domain/fetch-options.schema.ts +++ b/packages/api/src/plan-actions/plan-actions.list/domain/fetch-options.schema.ts @@ -1,5 +1,5 @@ +import { getPaginationSchema } from '@/domain/utils'; import { z } from 'zod'; -import { getQueryOptionsSchema } from '../../../shared/domain/query_options.schema'; import { filtreRessourceLieesSchema } from '../../../collectivites/shared/domain/filtre-ressource-liees.schema'; /** @@ -24,7 +24,7 @@ const fetchSortSchema = z.object({ export type FetchSort = z.infer; -export const fetchOptionsSchema = getQueryOptionsSchema(sortValues).extend({ +export const fetchOptionsSchema = getPaginationSchema(sortValues).extend({ filtre: fetchFilterSchema.optional(), }); diff --git a/packages/api/src/shared/actions/tag.fetch.test.ts b/packages/api/src/shared/actions/tag.fetch.test.ts index 421fa81fa9..902b75de36 100644 --- a/packages/api/src/shared/actions/tag.fetch.test.ts +++ b/packages/api/src/shared/actions/tag.fetch.test.ts @@ -1,20 +1,19 @@ -import {beforeAll, expect, test} from "vitest"; -import {signIn, signOut} from "../../tests/auth"; -import {testReset} from "../../tests/testReset"; -import {selectCategories} from "../../indicateurs/actions/categorie.fetch"; -import {supabase} from "../../tests/supabase"; -import {selectTags} from "./tag.fetch"; +import { beforeAll, expect, test } from 'vitest'; +import { signIn, signOut } from '../../tests/auth'; +import { supabase } from '../../tests/supabase'; +import { testReset } from '../../tests/testReset'; +import { selectTags } from './tag.fetch'; beforeAll(async () => { - await signIn('yolododo'); - await testReset(); + await signIn('yolododo'); + await testReset(); - return async () => { - await signOut(); - }; + return async () => { + await signOut(); + }; }); test('Test selectTags', async () => { - const def = await selectTags(supabase, 1, 'service'); - expect(def!).not.toHaveLength(0); -}); \ No newline at end of file + const def = await selectTags(supabase, 1, 'service'); + expect(def).not.toHaveLength(0); +}); diff --git a/packages/api/src/shared/actions/tag.fetch.ts b/packages/api/src/shared/actions/tag.fetch.ts index c8ae7e35e5..f984bc740d 100644 --- a/packages/api/src/shared/actions/tag.fetch.ts +++ b/packages/api/src/shared/actions/tag.fetch.ts @@ -1,23 +1,23 @@ -import {DBClient} from "../../typeUtils"; -import {Tag, TypeTag} from "../domain/tag.schema"; -import {objectToCamel} from "ts-case-convert"; +import { Tag, TagType } from '@/domain/collectivites'; +import { objectToCamel } from 'ts-case-convert'; +import { DBClient } from '../../typeUtils'; /** * Récupère les tags d'une collectivité * @param dbClient client supabase * @param collectiviteId identifiant de la collectivité - * @param typeTag type de tag + * @param tagType type de tag * @return liste de tags */ export async function selectTags( - dbClient : DBClient, - collectiviteId : number, - typeTag : TypeTag -): Promise{ - const {data, error} = await dbClient - .from(`${typeTag}_tag` as const) - .select('id, nom, collectivite_id') - .eq('collectivite_id', collectiviteId); + dbClient: DBClient, + collectiviteId: number, + tagType: TagType +): Promise { + const { data } = await dbClient + .from(`${tagType}_tag` as const) + .select('id, nom, collectivite_id') + .eq('collectivite_id', collectiviteId); - return data ? objectToCamel(data) as Tag[] : []; -} \ No newline at end of file + return data ? (objectToCamel(data) as Tag[]) : []; +} diff --git a/packages/api/src/shared/actions/tag.save.test.ts b/packages/api/src/shared/actions/tag.save.test.ts index c304bae215..792302263f 100644 --- a/packages/api/src/shared/actions/tag.save.test.ts +++ b/packages/api/src/shared/actions/tag.save.test.ts @@ -1,29 +1,30 @@ -import {beforeAll, expect, test} from "vitest"; -import {signIn, signOut} from "../../tests/auth"; -import {testReset} from "../../tests/testReset"; -import {selectCategories} from "../../indicateurs/actions/categorie.fetch"; -import {supabase} from "../../tests/supabase"; -import {insertTags} from "./tag.save"; -import {Tag} from "../domain/tag.schema"; +import { TagInsert } from '@/domain/collectivites'; +import { beforeAll, expect, test } from 'vitest'; +import { signIn, signOut } from '../../tests/auth'; +import { supabase } from '../../tests/supabase'; +import { testReset } from '../../tests/testReset'; +import { insertTags } from './tag.save'; beforeAll(async () => { - await signIn('yolododo'); - await testReset(); + await signIn('yolododo'); + await testReset(); - return async () => { - await signOut(); - }; + return async () => { + await signOut(); + }; }); test('Test insertTags', async () => { - const toInsert : Tag[] = [{ - nom : 'test', - collectiviteId: 1 + const toInsert: TagInsert[] = [ + { + nom: 'test', + collectiviteId: 1, }, - { - nom : 'test2', - collectiviteId: 1 - }]; - const def = await insertTags(supabase, 'categorie', toInsert); - expect(def!).toHaveLength(2); -}); \ No newline at end of file + { + nom: 'test2', + collectiviteId: 1, + }, + ]; + const def = await insertTags(supabase, 'categorie', toInsert); + expect(def).toHaveLength(2); +}); diff --git a/packages/api/src/shared/actions/tag.save.ts b/packages/api/src/shared/actions/tag.save.ts index 214c2e2ff9..f1b283af1e 100644 --- a/packages/api/src/shared/actions/tag.save.ts +++ b/packages/api/src/shared/actions/tag.save.ts @@ -1,21 +1,21 @@ -import { DBClient } from '../../typeUtils'; -import { Tag, TagInsert, TypeTag } from '../domain/tag.schema'; +import { Tag, TagInsert, TagType } from '@/domain/collectivites'; import { objectToCamel, objectToSnake } from 'ts-case-convert'; +import { DBClient } from '../../typeUtils'; /** * Ajoute des tags * @param dbClient client supabase - * @param typeTag type de tag + * @param tagType type de tag * @param tags listes des tags à ajouter * @return liste de tags ajoutés avec leur identifiant */ export async function insertTags( dbClient: DBClient, - typeTag: TypeTag, + tagType: TagType, tags: TagInsert[] ): Promise { const { data } = await dbClient - .from(`${typeTag}_tag` as const) + .from(`${tagType}_tag` as const) .insert(objectToSnake(tags)) .select(); diff --git a/packages/api/src/shared/actions/thematique.fetch.test.ts b/packages/api/src/shared/actions/thematique.fetch.test.ts index a682d25656..77c85dad52 100644 --- a/packages/api/src/shared/actions/thematique.fetch.test.ts +++ b/packages/api/src/shared/actions/thematique.fetch.test.ts @@ -1,26 +1,20 @@ -import {beforeAll, expect, test} from "vitest"; -import {signIn, signOut} from "../../tests/auth"; -import {testReset} from "../../tests/testReset"; -import {supabase} from "../../tests/supabase"; -import {selectSousThematiques, selectThematiques} from "./thematique.fetch"; +import { beforeAll, expect, test } from 'vitest'; +import { signIn, signOut } from '../../tests/auth'; +import { supabase } from '../../tests/supabase'; +import { testReset } from '../../tests/testReset'; +import { selectThematiques } from './thematique.fetch'; beforeAll(async () => { - await signIn('yolododo'); - await testReset(); + await signIn('yolododo'); + await testReset(); - return async () => { - await signOut(); - }; + return async () => { + await signOut(); + }; }); test('Test selectThematiques', async () => { - const data = await selectThematiques(supabase); - expect(data!).not.toBeNull(); - expect(data!).not.toHaveLength(0); + const data = await selectThematiques(supabase); + expect(data).not.toBeNull(); + expect(data).not.toHaveLength(0); }); - -test('Test selectSousThematiques', async () => { - const data = await selectSousThematiques(supabase, null, true); - expect(data!).not.toBeNull(); - expect(data!).not.toHaveLength(0); -}); \ No newline at end of file diff --git a/packages/api/src/shared/actions/thematique.fetch.ts b/packages/api/src/shared/actions/thematique.fetch.ts index e75d18b1c9..ebd19c06b9 100644 --- a/packages/api/src/shared/actions/thematique.fetch.ts +++ b/packages/api/src/shared/actions/thematique.fetch.ts @@ -1,9 +1,5 @@ +import { Thematique } from '@/domain/shared'; import { DBClient } from '../../typeUtils'; -import { - SousThematique, - SousThematiqueId, - Thematique, -} from '../domain/thematique.schema'; /** * Recupère les thématiques @@ -13,40 +9,7 @@ import { export async function selectThematiques( dbClient: DBClient ): Promise { - const { data, error } = await dbClient.from('thematique').select('id, nom'); + const { data } = await dbClient.from('thematique').select('id, nom'); return data ? (data as Thematique[]) : []; } - -/** - * Recupère les sous thématiques - * @param dbClient client supabase - * @param thematiqueId identifiant de la thématique parent, null pour récupérer toutes les sous thématiques - * @param lienThematiqueId vrai pour avoir le lien vers la thématique parente sous forme d'identifiant, - * faux pour avoir l'objet complet - * @return liste de sous thématiques - */ -export async function selectSousThematiques( - dbClient: DBClient, - thematiqueId: number | null, - lienThematiqueId: boolean -): Promise { - const colonnes = - 'id, nom:sous_thematique, thematique:' + - (thematiqueId ? 'thematique_id' : 'thematique(*)'); - - const query = dbClient.from('sous_thematique').select(colonnes); - - if (thematiqueId) { - query.eq('thematique_id', thematiqueId!); - } - const { data } = await query.returns(); - - if (!data) { - return []; - } - - return lienThematiqueId - ? (data as SousThematiqueId[]) - : (data as SousThematique[]); -} diff --git a/packages/api/src/shared/domain/index.ts b/packages/api/src/shared/domain/index.ts deleted file mode 100644 index 89690034f2..0000000000 --- a/packages/api/src/shared/domain/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './query_options.schema'; -export * from './tag.schema'; -export * from './thematique.schema'; diff --git a/packages/api/src/shared/domain/thematique.schema.ts b/packages/api/src/shared/domain/thematique.schema.ts deleted file mode 100644 index dc27e333a1..0000000000 --- a/packages/api/src/shared/domain/thematique.schema.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { z } from 'zod'; - -/** - * Schéma zod d'une thématique - */ -export const thematiqueSchema = z.object({ - id: z.number(), - nom: z.string(), -}); - -/** - * Type TS d'une thématique - */ -export type Thematique = z.input; - -/** - * Schéma zod d'une sous thématique avec l'objet de la thématique - */ -export const sousThematiqueSchema = z.object({ - id: z.number(), - sousThematique: z.string(), - thematique: thematiqueSchema, -}); - -/** - * Type TS d'une sous thématique avec l'objet de la thématique - */ -export type SousThematique = z.input; - -/** - * Schéma zod d'une sous thématique avec l'id de la thématique - */ -export const sousThematiqueSchemaId = z.object({ - id: z.number(), - sousThematique: z.string(), - thematiqueId: z.number(), -}); - -/** - * Type TS d'une sous thématique avec l'id de la thématique - */ -export type SousThematiqueId = z.input; diff --git a/packages/api/src/utils/trpc/client.tsx b/packages/api/src/utils/trpc/client.tsx index e72ce4e71f..12457d49bd 100644 --- a/packages/api/src/utils/trpc/client.tsx +++ b/packages/api/src/utils/trpc/client.tsx @@ -14,7 +14,7 @@ import { makeQueryClient } from './query-client'; // By using `import type` you ensure that the reference will be stripped at compile-time, meaning you don't inadvertently import server-side code into your client. // For more information, see the Typescript docs: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export // eslint-disable-next-line @nx/enforce-module-boundaries -import type { AppRouter } from '@/backend/trpc/trpc.router'; +import type { AppRouter } from '@/domain/utils'; import { getAuthHeaders } from '../authTokens'; export type RouterInput = inferRouterInputs; diff --git a/packages/auth/next.config.mjs b/packages/auth/next.config.mjs index 21ab7c2eeb..c0b1da5be8 100644 --- a/packages/auth/next.config.mjs +++ b/packages/auth/next.config.mjs @@ -1,4 +1,4 @@ -import {composePlugins, withNx} from '@nx/next'; +import { composePlugins, withNx } from '@nx/next'; /** * @type {import('@nx/next/plugins/with-nx').WithNxOptions} @@ -10,6 +10,10 @@ const nextConfig = { svgr: false, }, + typescript: { + tsconfigPath: './tsconfig.json', + }, + // active le mode strict pour détecter les problèmes en dev reactStrictMode: true, // active la minification @@ -19,7 +23,7 @@ const nextConfig = { esmExternals: 'loose', }, // surcharge la config webpack - webpack: config => { + webpack: (config) => { // pour le chargement des fontes au format woff2 config.module.rules.push({ test: /\.woff2$/, diff --git a/packages/auth/tsconfig.json b/packages/auth/tsconfig.json index 80647ecaf5..74ef3720ca 100644 --- a/packages/auth/tsconfig.json +++ b/packages/auth/tsconfig.json @@ -2,15 +2,11 @@ "extends": "../../tsconfig.base.json", "compilerOptions": { "jsx": "preserve", - "allowJs": true, - "esModuleInterop": true, + "allowJs": false, "allowSyntheticDefaultImports": true, - "strict": true, - "forceConsistentCasingInFileNames": true, "noEmit": true, "resolveJsonModule": true, "isolatedModules": true, - "incremental": true, "plugins": [ { "name": "next" @@ -24,8 +20,6 @@ "**/*.js", "**/*.jsx", "**/*.mjs", - "../../packages/auth/.next/types/**/*.ts", - "../../dist/apps/auth/.next/types/**/*.ts", "next-env.d.ts", ".next/types/**/*.ts" ], diff --git a/tsconfig.base.json b/tsconfig.base.json index 87e8ddda9c..49c70ccaca 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -24,6 +24,7 @@ "@/api/*": ["./packages/api/src/*"], "@/app/*": ["./app.territoiresentransitions.react/src/*"], "@/auth/*": ["./packages/auth/*"], + "@/domain/*": ["./backend/src/*/index-domain.ts"], "@/backend/*": ["./backend/src/*"], "@/backend/test": ["./backend/test/index.ts"], "@/panier/*": ["./packages/panier/*"],