Skip to content

Commit

Permalink
factorise import function and add tcom source
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine Jeanneney committed Sep 4, 2024
1 parent 3c2bbfc commit d6d6861
Show file tree
Hide file tree
Showing 11 changed files with 153 additions and 249 deletions.
4 changes: 2 additions & 2 deletions packages/courDeCassation/src/connector/fetcher/sderFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const sderFetcher = {
}: {
startDate: Date;
endDate: Date;
source: 'jurinet' | 'jurica' | 'juritj';
source: string;
}) {
const courtDecisions = await sderApi.fetchDecisionsToPseudonymiseBetween({
startDate,
Expand All @@ -46,7 +46,7 @@ const sderFetcher = {
}: {
startDate: Date;
endDate: Date;
source: 'jurinet' | 'jurica' | 'juritj';
source: string;
}) {
const courtDecisions = await sderApi.fetchDecisionsToPseudonymiseBetweenDateCreation(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { documentType } from '@label/core';
import { extractRouteForJurica } from './extractRouteForJurica';
import { extractRouteForJurinet } from './extractRouteForJurinet';
import { extractRouteForJuritj } from './extractRouteForJuritj';
import { extractRouteForJuritcom } from './extractRouteForJuritcom';

export { extractRoute };

Expand All @@ -25,31 +26,32 @@ function extractRoute(
): documentType['route'] {
let route: documentType['route'] = 'default';

switch (source) {
case 'jurinet':
try {
route = extractRouteForJurinet({ ...routeInfos });
} catch (e) {
logger.error({ operationName: 'extractRouteForJurinet', msg: `${e}` });
route = 'exhaustive';
}
break;
case 'jurica':
try {
route = extractRouteForJurica({ ...routeInfos });
} catch (e) {
logger.error({ operationName: 'extractRouteForJurica', msg: `${e}` });
route = 'exhaustive';
}
break;
case 'juritj':
try {
route = extractRouteForJuritj({ ...routeInfos });
} catch (e) {
logger.error({ operationName: 'extractRouteForJuritj', msg: `${e}` });
route = 'exhaustive';
}
break;
// TODO : use dbsder-api-types
enum Sources {
CC = 'jurinet',
CA = 'jurica',
TJ = 'juritj',
TCOM = 'juritcom',
}

const extractRouteFunctions = {
[Sources.CC]: extractRouteForJurinet,
[Sources.CA]: extractRouteForJurica,
[Sources.TJ]: extractRouteForJuritj,
[Sources.TCOM]: extractRouteForJuritcom,
};

try {
if (source in extractRouteFunctions) {
route = extractRouteFunctions[source as Sources]({
...routeInfos,
});
} else {
throw new Error('Source non prise en charge');
}
} catch (e) {
logger.error({ operationName: `extractRouteFor ${source}`, msg: `${e}` });
route = 'exhaustive';
}

if (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { documentType } from '@label/core';

export { extractRouteForJuritcom };

function extractRouteForJuritcom({}: {
session: documentType['decisionMetadata']['session'];
solution: documentType['decisionMetadata']['solution'];
parties: documentType['decisionMetadata']['parties'];
publicationCategory: documentType['publicationCategory'];
chamberName: documentType['decisionMetadata']['chamberName'];
civilMatterCode: documentType['decisionMetadata']['civilMatterCode'];
civilCaseCode: documentType['decisionMetadata']['civilCaseCode'];
criminalCaseCode: documentType['decisionMetadata']['criminalCaseCode'];
NACCode: documentType['decisionMetadata']['NACCode'];
endCaseCode: documentType['decisionMetadata']['endCaseCode'];
}): documentType['route'] {
return 'exhaustive';
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function parseArgv() {
sources: {
demandOption: false,
description:
'sources (jurinet, jurica or juritj) of the decisions you want to import',
'sources (jurinet, jurica, juritj or juritcom) of the decisions you want to import',
type: 'string',
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function parseArgv() {
source: {
demandOption: true,
description:
'source (jurinet, jurica or juritj) of the document you want to import',
'source (jurinet, jurica, juritj, juritcom) of the document you want to import',
type: 'string',
},
keepLabelTreatments: {
Expand Down
4 changes: 2 additions & 2 deletions packages/courDeCassation/src/sderApi/sderApiType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ type sderApiType = {
fetchDecisionsToPseudonymiseBetween: (param: {
startDate: Date;
endDate: Date;
source: 'jurinet' | 'jurica' | 'juritj';
source: string;
}) => Promise<Array<decisionType>>;
fetchDecisionsToPseudonymiseBetweenDateCreation: (param: {
startDate: Date;
endDate: Date;
source: 'jurinet' | 'jurica' | 'juritj';
source: string;
}) => Promise<Array<decisionType>>;
fetchCourtDecisionBySourceIdAndSourceName: (param: {
sourceId: decisionType['sourceId'];
Expand Down
Loading

0 comments on commit d6d6861

Please sign in to comment.