Commit 526d11ea authored by Remi Mélisson's avatar Remi Mélisson
Browse files

fix: use indexed conventions in mapHit

parent e6116e9d
......@@ -17,8 +17,7 @@
"@koa/cors": "^3.1.0",
"@socialgouv/kali-data": "^2.61.0",
"koa": "^2.13.1",
"koa-router": "^10.0.0",
"lodash.pick": "^4.4.0"
"koa-router": "^10.0.0"
},
"devDependencies": {
"@types/jest": "^26.0.22",
......
import kaliConventions from "@socialgouv/kali-data/data/index.json";
import pick from "lodash.pick"
const pre = "<b><u>";
const post = "</b></u>";
const defaultLimit = 20;
const conventionsSet = Object.fromEntries(
kaliConventions.map((c) => {
const { num, etat, id, mtime, texte_de_base, url, title } = c;
return [num, { etat, id, mtime, texte_de_base, url, title }];
})
);
// we remove deduplicate tokens to compose company's label
const formatLabel = (naming: string[]) => {
const labelTokens = naming
......@@ -65,12 +71,11 @@ export const mapHit = ({
fields: { convention, idcc },
}: { fields: { convention: string[]; idcc: string } }
) => {
const kaliConvention = kaliConventions.find(cv => cv.num === parseInt(idcc)) || {}
const kaliData = kaliConvention && pick(kaliConvention, ["etat", "id", "mtime", "texte_de_base", "url", "title"]) || {}
const kaliData = idcc ? conventionsSet[idcc] : undefined;
const o = {
idcc: parseInt(idcc),
shortTitle: convention ? convention[0] : "",
...kaliData
...kaliData,
};
if (!acc.has(o.idcc)) {
acc.set(o.idcc, o);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment