-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: update for mes-adresses-api v2 and linter eslint (#45)
* fix: update for mes-adresses-api v2 * feat: replace co by eslint * fix ci * fix: stats creation url
- Loading branch information
Showing
16 changed files
with
987 additions
and
1,579 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"extends": ["next", "xo", "xo-nextjs"] | ||
"extends": ["next", "prettier"] | ||
} |
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
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
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 |
---|---|---|
@@ -1,54 +1,78 @@ | ||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
import type {BaseLocaleType} from '../types/mes-adresses' | ||
import type {PageType} from '../types/page' | ||
import type { BaseLocaleType } from "../types/mes-adresses"; | ||
import type { PageType } from "../types/page"; | ||
|
||
const NEXT_PUBLIC_API_MES_ADRESSES = process.env.NEXT_PUBLIC_API_MES_ADRESSES || 'https://api-bal.adresse.data.gouv.fr/v1' | ||
const NEXT_PUBLIC_BAL_ADMIN_URL = process.env.NEXT_PUBLIC_BAL_ADMIN_URL || 'http://localhost:3000' | ||
const PROXY_MES_ADRESSES_API = NEXT_PUBLIC_BAL_ADMIN_URL + '/api/proxy-mes-adresses-api' | ||
const NEXT_PUBLIC_API_MES_ADRESSES = | ||
process.env.NEXT_PUBLIC_API_MES_ADRESSES || | ||
"https://api-bal.adresse.data.gouv.fr/v2"; | ||
const NEXT_PUBLIC_BAL_ADMIN_URL = | ||
process.env.NEXT_PUBLIC_BAL_ADMIN_URL || "http://localhost:3000"; | ||
const PROXY_MES_ADRESSES_API = | ||
NEXT_PUBLIC_BAL_ADMIN_URL + "/api/proxy-mes-adresses-api"; | ||
|
||
export type SearchBasesLocalesParams = { | ||
commune: string; | ||
page: number; | ||
limit: number; | ||
deleted?: number; | ||
} | ||
}; | ||
|
||
async function processReponse(res: Response) { | ||
if (!res.ok) { | ||
const error = await res.json() | ||
throw new Error(error.message) | ||
const error = await res.json(); | ||
throw new Error(error.message); | ||
} | ||
|
||
try { | ||
return await res.json() | ||
return await res.json(); | ||
} catch { | ||
return res | ||
return res; | ||
} | ||
} | ||
|
||
export async function getBaseLocale(baseLocaleId: string): Promise<BaseLocaleType> { | ||
const res: Response = await fetch(`${PROXY_MES_ADRESSES_API}/bases-locales/${baseLocaleId}`) | ||
return processReponse(res) | ||
export async function getBaseLocale( | ||
baseLocaleId: string | ||
): Promise<BaseLocaleType> { | ||
const res: Response = await fetch( | ||
`${PROXY_MES_ADRESSES_API}/bases-locales/${baseLocaleId}` | ||
); | ||
return processReponse(res); | ||
} | ||
|
||
export async function removeBaseLocale(baseLocaleId: string) { | ||
const res: Response = await fetch(`${PROXY_MES_ADRESSES_API}/bases-locales/${baseLocaleId}`, { | ||
method: 'DELETE', | ||
}) | ||
return processReponse(res) | ||
const res: Response = await fetch( | ||
`${PROXY_MES_ADRESSES_API}/bases-locales/${baseLocaleId}`, | ||
{ | ||
method: "DELETE", | ||
} | ||
); | ||
return processReponse(res); | ||
} | ||
|
||
export async function searchBasesLocales(query: SearchBasesLocalesParams): Promise<PageType<BaseLocaleType>> { | ||
const {page = 1, limit = 20, deleted = 0} = query | ||
const offset = (page - 1) * limit | ||
const params = {...query, offset, limit, deleted} | ||
const queryString: string = Object.keys(params).map((key: string) => `${key}=${String(params[key])}`).join('&') | ||
export async function searchBasesLocales( | ||
query: SearchBasesLocalesParams | ||
): Promise<PageType<BaseLocaleType>> { | ||
const { page = 1, limit = 20, deleted = 0 } = query; | ||
const offset = (page - 1) * limit; | ||
const params = { ...query, offset, limit, deleted }; | ||
const queryString: string = Object.keys(params) | ||
.map((key: string) => `${key}=${String(params[key])}`) | ||
.join("&"); | ||
|
||
const res: Response = await fetch(`${NEXT_PUBLIC_API_MES_ADRESSES}/bases-locales/search?${queryString}`) | ||
return processReponse(res) | ||
const res: Response = await fetch( | ||
`${NEXT_PUBLIC_API_MES_ADRESSES}/bases-locales/search?${queryString}` | ||
); | ||
return processReponse(res); | ||
} | ||
|
||
export async function getStatCreations({from, to}: {from: string; to: string}) { | ||
const res = await fetch(`${NEXT_PUBLIC_API_MES_ADRESSES}/stats/creations?from=${from}&to=${to}`) | ||
return processReponse(res) | ||
export async function getStatCreations({ | ||
from, | ||
to, | ||
}: { | ||
from: string; | ||
to: string; | ||
}) { | ||
const res = await fetch( | ||
`${NEXT_PUBLIC_API_MES_ADRESSES}/stats/bals/creations?from=${from}&to=${to}` | ||
); | ||
return processReponse(res); | ||
} |
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
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
Oops, something went wrong.