Skip to content

Commit 7f38d45

Browse files
committed
♻️ migrate get_fiche_organization_by_id to repository pattern
- Replace GetFicheOrganizationById usecase with GetOrganizationById repository in API contexts - Eliminate duplicate organization fetching in organizations/:id route - Consolidate organization and organization_fiche into single repository call - Add missing columns for complete organization data (cached_categorie_juridique, etc.) - Maintain backward compatibility while improving performance and consistency
1 parent 9afa4c3 commit 7f38d45

File tree

5 files changed

+35
-22
lines changed

5 files changed

+35
-22
lines changed

sources/moderations/api/src/:id/context.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import {
88
GetModerationWithDetails,
99
type GetModerationWithDetailsDto,
1010
} from "@~/moderations.repository";
11-
import { GetFicheOrganizationById } from "@~/organizations.lib/usecase";
1211
import {
1312
GetDomainCount,
13+
GetOrganizationById,
1414
GetOrganizationMember,
1515
GetOrganizationMembersCount,
1616
} from "@~/organizations.repository";
@@ -49,10 +49,29 @@ export async function loadModerationPageVariables(
4949

5050
//
5151

52-
const get_fiche_organization_by_id = GetFicheOrganizationById({
53-
pg,
52+
const get_organization_by_id = GetOrganizationById(pg, {
53+
columns: {
54+
cached_activite_principale: true,
55+
cached_adresse: true,
56+
cached_categorie_juridique: true,
57+
cached_code_officiel_geographique: true,
58+
cached_code_postal: true,
59+
cached_enseigne: true,
60+
cached_est_active: true,
61+
cached_etat_administratif: true,
62+
cached_libelle_activite_principale: true,
63+
cached_libelle_categorie_juridique: true,
64+
cached_libelle_tranche_effectif: true,
65+
cached_libelle: true,
66+
cached_nom_complet: true,
67+
cached_tranche_effectifs: true,
68+
created_at: true,
69+
id: true,
70+
siret: true,
71+
updated_at: true,
72+
},
5473
});
55-
const organization_fiche = await get_fiche_organization_by_id(
74+
const organization_fiche = await get_organization_by_id(
5675
moderation.organization_id,
5776
);
5877

sources/moderations/api/src/context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export type ContextType = App_Context & ContextVariablesType;
5656

5757
//
5858

59-
export const usePageRequestContext = useRequestContext<ContextType, any, any>();
59+
export const usePageRequestContext = useRequestContext<ContextType, any, any>;
6060

6161
export default createContext({
6262
query_moderations_list: {} as Promise<GetModerationsListDTO>,

sources/organizations/api/src/:id/Fiche.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { usePageRequestContext } from "./context";
88

99
export async function Fiche() {
1010
const {
11-
var: { organization, organization_fiche },
11+
var: { organization },
1212
} = usePageRequestContext();
1313

1414
return (
@@ -17,7 +17,7 @@ export async function Fiche() {
1717
<h1 class="text-(--text-action-high-blue-france)">
1818
« {organization.cached_libelle} »
1919
</h1>
20-
<About organization={organization_fiche} />
20+
<About organization={organization} />
2121
</div>
2222
<div class="fr-card p-6!">
2323
<Investigation organization={organization} />

sources/organizations/api/src/:id/context.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import type { App_Context } from "@~/app.middleware/context";
44
import { urls } from "@~/app.urls";
55
import type { IdentiteProconnect_PgDatabase } from "@~/identite-proconnect.database";
6-
import { GetFicheOrganizationById } from "@~/organizations.lib/usecase";
76
import {
87
GetDomainCount,
98
GetOrganizationById,
@@ -21,9 +20,13 @@ export async function loadOrganizationPageVariables(
2120
columns: {
2221
cached_activite_principale: true,
2322
cached_adresse: true,
23+
cached_categorie_juridique: true,
24+
cached_code_officiel_geographique: true,
2425
cached_code_postal: true,
26+
cached_enseigne: true,
2527
cached_est_active: true,
2628
cached_etat_administratif: true,
29+
cached_libelle_activite_principale: true,
2730
cached_libelle_categorie_juridique: true,
2831
cached_libelle_tranche_effectif: true,
2932
cached_libelle: true,
@@ -38,16 +41,10 @@ export async function loadOrganizationPageVariables(
3841

3942
const organization = await get_organization_by_id(id);
4043

41-
//
42-
43-
const get_fiche_organization_by_id = GetFicheOrganizationById({ pg });
44-
const organization_fiche = await get_fiche_organization_by_id(id);
45-
4644
const query_organization_domains_count = GetDomainCount(pg)(id);
4745
const query_organization_members_count = GetOrganizationMembersCount(pg)(id);
4846

4947
return {
50-
organization_fiche,
5148
organization,
5249
query_organization_domains_count,
5350
query_organization_members_count,

sources/users/api/src/page.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,9 @@ import { Foot } from "@~/app.ui/hx_table";
77
import { row } from "@~/app.ui/table";
88
import { LocalTime } from "@~/app.ui/time";
99
import { hx_urls, urls } from "@~/app.urls";
10+
import type { GetUsersListDto } from "@~/users.repository";
1011
import { match } from "ts-pattern";
11-
import {
12-
PageInput_Schema,
13-
usePageRequestContext,
14-
type get_users_list_dto,
15-
} from "./context";
12+
import { PageInput_Schema, usePageRequestContext } from "./context";
1613

1714
//
1815

@@ -75,7 +72,7 @@ function Filter() {
7572
async function Table() {
7673
const {
7774
req,
78-
var: { query_users, identite_pg },
75+
var: { query_users },
7976
} = usePageRequestContext();
8077

8178
const { q } = req.valid("query");
@@ -85,7 +82,7 @@ async function Table() {
8582
.with({ success: true }, ({ data }) => data)
8683
.otherwise(() => Pagination_Schema.parse({}));
8784

88-
const { count, users } = await query_users(identite_pg, {
85+
const { count, users } = await query_users({
8986
search: q ? String(q) : undefined,
9087
pagination: { ...pagination, page: pagination.page - 1 },
9188
});
@@ -127,7 +124,7 @@ function Row({
127124
user,
128125
}: {
129126
key?: string;
130-
user: get_users_list_dto["users"][number];
127+
user: GetUsersListDto["users"][number];
131128
}) {
132129
return (
133130
<tr

0 commit comments

Comments
 (0)