-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: idcc using metadata file provided by API (#802)
Co-authored-by: Johan Girod <[email protected]>
- Loading branch information
1 parent
77fcc01
commit 092715a
Showing
14 changed files
with
239 additions
and
3,942 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { HttpNotFound, HttpServerError } from '#clients/exceptions'; | ||
import routes from '#clients/routes'; | ||
import { ICCWithMetadata } from '#models/conventions-collectives-list'; | ||
import { httpGet } from '#utils/network'; | ||
|
||
type IIdccMetadata = { | ||
[idcc: string]: { | ||
'titre de la convention': string; //Convention collective na… des cabinets d'avocats" | ||
id_kali: string; //KALICONT000005635185" | ||
cc_ti: string; //IDCC" | ||
nature: string; //CONVENTION COLLECTIVE NATIONALE" | ||
etat: string; //VIGUEUR_ETEN" | ||
debut: string; //1979-03-01 00:00:00" | ||
fin: string | null; | ||
url: string; //https://www.legifrance.g…/id/KALICONT000005635185" | ||
}; | ||
}; | ||
|
||
class IdCCMetadataClient { | ||
private _idccMetadata = null as { | ||
[idcc: string]: ICCWithMetadata; | ||
} | null; | ||
|
||
get = async (idcc: string) => { | ||
if (!this._idccMetadata) { | ||
const response = await httpGet<IIdccMetadata>( | ||
routes.conventionsCollectives.metadata | ||
); | ||
|
||
this._idccMetadata = this.mapToDomainObject(response); | ||
} | ||
|
||
if (Object.values(this._idccMetadata).length === 0) { | ||
throw new HttpServerError('Empty Idcc metadata list'); | ||
} | ||
|
||
if (idcc in this._idccMetadata) { | ||
return this._idccMetadata[idcc] || {}; | ||
} else { | ||
throw new HttpNotFound('Convention collective not found'); | ||
} | ||
}; | ||
|
||
mapToDomainObject = (response: IIdccMetadata) => { | ||
return Object.entries(response).reduce( | ||
(idccMetadatas, [idcc, metadata]) => { | ||
const { id_kali, url, nature, etat } = metadata; | ||
idccMetadatas[idcc] = { | ||
idKali: id_kali, | ||
legifrance: url, | ||
title: metadata['titre de la convention'], | ||
nature, | ||
etat, | ||
idcc, | ||
}; | ||
return idccMetadatas; | ||
}, | ||
{} as { [idcc: string]: ICCWithMetadata } | ||
); | ||
}; | ||
} | ||
const client = new IdCCMetadataClient(); | ||
|
||
export const clientIdccMetadata = async (idcc: string) => client.get(idcc); |
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.