-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
232 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
packages/code-du-travail-frontend/src/api/modules/enterprises/service/fetchEnterprises.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { ENTERPRISE_API_URL } from "../../../../config"; | ||
import { Enterprise } from "../types"; | ||
|
||
export type Convention = { | ||
idcc: number; | ||
shortTitle: string; | ||
id: string; | ||
title: string; | ||
url?: string; | ||
}; | ||
|
||
export type EnterpriseApiResponse = { | ||
entreprises?: (Omit<Enterprise, "conventions"> & { | ||
conventions: Convention[]; | ||
})[]; | ||
}; | ||
|
||
export const fetchEnterprises = async ( | ||
query: string, | ||
address: string | undefined | ||
): Promise<EnterpriseApiResponse> => { | ||
const params: { k: string; v: string }[] = [ | ||
{ k: "ranked", v: "true" }, | ||
{ k: "query", v: encodeURIComponent(query) }, | ||
{ k: "convention", v: "true" }, | ||
{ k: "employer", v: "true" }, | ||
{ k: "open", v: "true" }, | ||
{ k: "matchingLimit", v: "0" }, | ||
]; | ||
if (address) { | ||
params.push({ k: "address", v: encodeURIComponent(address) }); | ||
} | ||
|
||
const flattenParams = params | ||
.map(({ k, v }) => (k && v ? `${k}=${v}` : undefined)) | ||
.filter((qp) => qp) | ||
.join("&"); | ||
|
||
const url = `${ | ||
ENTERPRISE_API_URL ?? | ||
"https://api.recherche-entreprises.fabrique.social.gouv.fr/api/v1" | ||
}/search?${flattenParams}`; | ||
|
||
const fetchReq = await fetch(url, { | ||
headers: { referer: "cdtn-api" }, | ||
}); | ||
|
||
const jsonResponse: EnterpriseApiResponse = await fetchReq.json(); | ||
|
||
return jsonResponse; | ||
}; |
2 changes: 2 additions & 0 deletions
2
packages/code-du-travail-frontend/src/api/modules/enterprises/service/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./fetchEnterprises"; | ||
export * from "./populateAgreements"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
type ErrorResponse = { | ||
message: string; | ||
}; |
Oops, something went wrong.