Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hel 729/nom commune identique #611

Merged
merged 4 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export async function rechercheAvanceeParmiLesEntitésEtÉtablissementsEndpoint(
dependencies: Dependencies,
terme: string,
zone: string,
zoneD: string,
typeZone: string,
type: string,
statutJuridique: string[],
Expand All @@ -21,7 +22,7 @@ export async function rechercheAvanceeParmiLesEntitésEtÉtablissementsEndpoint(
try {
const rechercheAvanceeParmiLesEntitésEtÉtablissementsUseCase = new RechercheAvanceeParmiLesEntitésEtÉtablissementsUseCase(dependencies.rechercheLoader);

return await rechercheAvanceeParmiLesEntitésEtÉtablissementsUseCase.exécute(terme, zone, typeZone, type, statutJuridique, capaciteSMS, orderBy, order, page);
return await rechercheAvanceeParmiLesEntitésEtÉtablissementsUseCase.exécute(terme, zone, zoneD, typeZone, type, statutJuridique, capaciteSMS, orderBy, order, page);
} catch (error) {
dependencies.logger.error(error);
throw error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ describe("La recherche avancée d’entités et d’établissements", () => {
const typeOrmRechercheLoader = new TypeOrmRechercheLoader(orm);

// WHEN
const rechercheAvancee = await typeOrmRechercheLoader.rechercheAvancee(termeRecherche, communeRecherche, "C", "", [], [], "", "ASC", premièrePage);
const rechercheAvancee = await typeOrmRechercheLoader.rechercheAvancee(termeRecherche, communeRecherche, departementRecherche, "C", "", [], [], "", "ASC", premièrePage);


//THEN
expect(rechercheAvancee.nombreDeRésultats).toBe("4");
Expand All @@ -113,7 +114,8 @@ describe("La recherche avancée d’entités et d’établissements", () => {
const typeOrmRechercheLoader = new TypeOrmRechercheLoader(orm);

// WHEN
const rechercheAvancee = await typeOrmRechercheLoader.rechercheAvancee(termeRecherche, departementRecherche, "D", "", [], [], "", "ASC", premièrePage);
const rechercheAvancee = await typeOrmRechercheLoader.rechercheAvancee(termeRecherche, departementRecherche, "", "D", "", [], [], "", "ASC", premièrePage);


//THEN
expect(rechercheAvancee.nombreDeRésultats).toBe("4");
Expand All @@ -124,7 +126,8 @@ describe("La recherche avancée d’entités et d’établissements", () => {
const typeOrmRechercheLoader = new TypeOrmRechercheLoader(orm);

// WHEN
const rechercheAvancee = await typeOrmRechercheLoader.rechercheAvancee(termeRecherche, regionRecherche, "R", "", [], [], "", "ASC", premièrePage);
const rechercheAvancee = await typeOrmRechercheLoader.rechercheAvancee(termeRecherche, regionRecherche, "", "R", "", [], [], "", "ASC", premièrePage);


//THEN
expect(rechercheAvancee.nombreDeRésultats).toBe("3");
Expand All @@ -138,6 +141,7 @@ describe("La recherche avancée d’entités et d’établissements", () => {
const rechercheAvancee = await typeOrmRechercheLoader.rechercheAvancee(
termeRecherche,
communeRecherche,
departementRecherche,
"C",
"Médico-social",
[],
Expand All @@ -156,7 +160,7 @@ describe("La recherche avancée d’entités et d’établissements", () => {
const typeOrmRechercheLoader = new TypeOrmRechercheLoader(orm);

// WHEN
const rechercheAvancee = await typeOrmRechercheLoader.rechercheAvancee("", communeRecherche, "", "Médico-social", [], [], "", "ASC", premièrePage);
const rechercheAvancee = await typeOrmRechercheLoader.rechercheAvancee("", communeRecherche, departementRecherche, "C", "Médico-social", [], [], "", "ASC", premièrePage);

//THEN
expect(rechercheAvancee.nombreDeRésultats).toBe("2");
Expand All @@ -170,6 +174,7 @@ describe("La recherche avancée d’entités et d’établissements", () => {
const rechercheAvancee = await typeOrmRechercheLoader.rechercheAvancee(
termeRecherche,
communeRecherche,
departementRecherche,
"C",
"Entité juridique",
["prive_lucratif"],
Expand All @@ -192,6 +197,7 @@ describe("La recherche avancée d’entités et d’établissements", () => {
termeRecherche,
"",
"",
"",
"Entité juridique",
["prive_lucratif"],
[],
Expand Down Expand Up @@ -230,7 +236,8 @@ describe("La recherche avancée d’entités et d’établissements", () => {
const rechercheAvancee = await typeOrmRechercheLoader.rechercheAvancee(
"",
communeRecherche,
"",
departementRecherche,
"C",
"",
[],
[
Expand All @@ -254,7 +261,8 @@ describe("La recherche avancée d’entités et d’établissements", () => {
const rechercheAvancee = await typeOrmRechercheLoader.rechercheAvancee(
termeRecherche,
communeRecherche,
"",
departementRecherche,
"C",
"",
[],
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export class TypeOrmRechercheLoader implements RechercheLoader {
async rechercheAvancee(
terme: string,
zone: string,
zoneD: string,
typeZone: string,
type: string,
statutJuridique: string[],
Expand All @@ -63,6 +64,7 @@ export class TypeOrmRechercheLoader implements RechercheLoader {
order: OrderDir,
page: number
): Promise<RésultatDeRecherche> {

const termeSansEspaces = terme.replaceAll(/\s/g, "");
const termeSansTirets = terme.replaceAll(/-/g, " ");
const zoneParam = zone
Expand All @@ -74,6 +76,11 @@ export class TypeOrmRechercheLoader implements RechercheLoader {
.replace(/\b(?:-|')\b/gi, " ")
.toLocaleUpperCase()
: "";
const zoneDParam = typeZone === 'C' ? zoneD.normalize("NFD")
.replace(/[\u0300-\u036f]/g, "")
.replace(/\b(?:-|')\b/gi, " ")
.toLocaleUpperCase() : '';

const conditions = [];
let parameters: any = {};

Expand Down Expand Up @@ -112,7 +119,8 @@ export class TypeOrmRechercheLoader implements RechercheLoader {
parameters = { ...parameters, commune: `%${zoneParam}%ARRONDISSEMENT%` };
} else {
conditions.push("recherche.commune = :commune");
parameters = { ...parameters, commune: zoneParam };
conditions.push("recherche.departement = :departement");
parameters = { ...parameters, commune: zoneParam, departement: zoneDParam };
}
}
if (typeZone === "D") {
Expand Down
1 change: 1 addition & 0 deletions src/backend/métier/gateways/RechercheLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface RechercheLoader {
rechercheAvancee(
terme: string,
zone: string,
zoneD: string,
typeZone: string,
type: string,
statutJuridique: string[],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export class RechercheAvanceeParmiLesEntitésEtÉtablissementsUseCase {
async exécute(
terme: string,
zone: string,
zoneD: string,
typeZone: string,
type: string,
statutJuridique: string[],
Expand All @@ -21,6 +22,6 @@ export class RechercheAvanceeParmiLesEntitésEtÉtablissementsUseCase {
order: OrderDir,
page: number
): Promise<RésultatDeRecherche> {
return await this.rechercheLoader.rechercheAvancee(terme, zone, typeZone, type, statutJuridique, capaciteSMS, orderBy, order, page);
return await this.rechercheLoader.rechercheAvancee(terme, zone, zoneD, typeZone, type, statutJuridique, capaciteSMS, orderBy, order, page);
}
}
2 changes: 2 additions & 0 deletions src/frontend/ui/commun/contexts/RechercheAvanceeContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface RechercheAvanceeContextValue {
termeFixe: string;
page: number;
zoneGeo: string;
zoneGeoD: string;
zoneGeoType: string;
zoneGeoLabel: string;
typeStructure: string;
Expand All @@ -18,6 +19,7 @@ export interface RechercheAvanceeContextValue {
setTermeFixe: (terme: string) => void;
setPage: (page: number, shallow?: boolean) => void;
setZoneGeo: (zoneGeo: string) => void;
setZoneGeoD: (zoneGeoD: string) => void;
setZoneGeoType: (zoneGeo: string) => void;
setZoneGeoLabel: (zoneGeo: string) => void;
setTypeStructure: (typeStructure: string) => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface SearchParams {
terme?: string;
page?: number;
zoneGeo?: string;
zoneGeoD?: string;
zoneGeoType?: string;
zoneGeoLabel?: string;
typeStructure?: string;
Expand All @@ -31,6 +32,7 @@ export const RechecheAvanceeContextProvider = ({ children }: RechercheAvanceePro
terme: parseAsString.withDefault(""),
page: parseAsInteger.withDefault(1),
zoneGeo: parseAsString.withDefault(""),
zoneGeoD: parseAsString.withDefault(""),
zoneGeoType: parseAsString.withDefault(""),
zoneGeoLabel: parseAsString.withDefault(""),
typeStructure: parseAsString.withDefault(""),
Expand All @@ -44,6 +46,7 @@ export const RechecheAvanceeContextProvider = ({ children }: RechercheAvanceePro
{
urlKeys: {
zoneGeo: "zone",
zoneGeoD: "zoneD",
zoneGeoType: "typeZone",
zoneGeoLabel: 'zoneLabel',
typeStructure: "type",
Expand All @@ -69,6 +72,7 @@ export const RechecheAvanceeContextProvider = ({ children }: RechercheAvanceePro
...searchParams,
termeFixe,
setZoneGeo: (value) => updateSearchParams({ zoneGeo: value, page: initialPage }),
setZoneGeoD: (value) => updateSearchParams({ zoneGeoD: value, page: initialPage }),
setZoneGeoType: (value) => updateSearchParams({ zoneGeoType: value, page: initialPage }),
setZoneGeoLabel: (value) => updateSearchParams({ zoneGeoLabel: value, page: initialPage }),
setTypeStructure: (value) => updateSearchParams({ typeStructure: value, page: initialPage }),
Expand Down
9 changes: 9 additions & 0 deletions src/frontend/ui/recherche-avancee/FiltreZoneGeographique.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import styles from "./RechercheAvanceeFormulaire.module.css";
type ZoneGeo = Readonly<{
type: string;
nom: string;
departement: {
code: string;
nom: string;
},
code: string;
codeRegion: string;
codesPostaux: string[];
Expand All @@ -23,6 +27,10 @@ export const FiltreZoneGeographique = () => {
const [zoneGeoSelected, setZoneGeoSelected] = useState<ZoneGeo>({
type: "",
nom: "",
departement: {
code: "",
nom: ""
},
code: "",
codeRegion: "",
codesPostaux: [],
Expand Down Expand Up @@ -155,6 +163,7 @@ export const FiltreZoneGeographique = () => {
};

const applyZoneGeoValue = () => {
rechercheAvanceeContext?.setZoneGeoD(zoneGeoType === "C" ? zoneGeoSelected?.departement.nom : '');
rechercheAvanceeContext?.setZoneGeo(zoneGeoType === "R" ? zoneGeoSelected?.codeRegion : zoneGeoValue);
rechercheAvanceeContext?.setZoneGeoType(zoneGeoType);
rechercheAvanceeContext?.setZoneGeoLabel(zoneGeoSelected.codeNum ? `${zoneGeoSelected.nom} (${zoneGeoSelected.codeNum})` : zoneGeoSelected.nom);
Expand Down
4 changes: 2 additions & 2 deletions src/pages/api/recherche-avancee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default async function handler(request: NextApiRequest, response: NextApi
}


const { terme, zone, typeZone, type, statutJuridique, capaciteSMS, orderBy, order, page } = request.body;
const recherche = await rechercheAvanceeParmiLesEntitésEtÉtablissementsEndpoint(dependencies, terme, zone, typeZone, type, statutJuridique, capaciteSMS, order, orderBy, page);
const { terme, zone, zoneD, typeZone, type, statutJuridique, capaciteSMS, orderBy, order, page } = request.body;
const recherche = await rechercheAvanceeParmiLesEntitésEtÉtablissementsEndpoint(dependencies, terme, zone, zoneD, typeZone, type, statutJuridique, capaciteSMS, order, orderBy, page);
response.status(200).json(recherche);
}
3 changes: 3 additions & 0 deletions src/pages/recherche-avancee.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export async function getServerSideProps(context: GetServerSidePropsContext): Pr
query: {
terme = "",
zone = "",
zoneD = "",
typeZone = "",
page = 1,
statuts = [],
Expand All @@ -78,6 +79,7 @@ export async function getServerSideProps(context: GetServerSidePropsContext): Pr
const pageParam = Number(page);
const termeParam = String(terme);
const zoneParam = String(zone);
const zoneDParam = String(zoneD);
const typeZoneParam = String(typeZone);
const typeParam = String(type);
const orderParam = String(order) as OrderDir;
Expand Down Expand Up @@ -108,6 +110,7 @@ export async function getServerSideProps(context: GetServerSidePropsContext): Pr
dependencies,
termeParam,
zoneParam,
zoneDParam,
typeZoneParam,
typeParam,
statutJuridiqueParam,
Expand Down
Loading