Skip to content

Commit

Permalink
feat: deal of field prive conum data (#142)
Browse files Browse the repository at this point in the history
* feat: deal of field prive conum data

* refactor: improve is prive readability

---------

Co-authored-by: Marc Gavanier <marc.gavanier@gmail.com>
  • Loading branch information
abelkhay and marc-gavanier authored Jan 17, 2024
1 parent 877d94c commit 25407b0
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -243,5 +243,8 @@
],
"horaires": {
"osm": "horaires"
},
"prive": {
"colonne": "prive"
}
}
1 change: 1 addition & 0 deletions src/transformer/fields/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ export * from './services/services.field';
export * from './source/source.field';
export * from './typologies/typologies.field';
export * from './accessibilite/accessibilite.field';
export * from './prive/prive.field';
36 changes: 36 additions & 0 deletions src/transformer/fields/prive/prive.field.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* eslint-disable @typescript-eslint/naming-convention, camelcase */

import { LieuxMediationNumeriqueMatching, DataSource } from '../../input';
import { isPrive } from './prive.field';

describe('prive field', (): void => {
it('should get prive field from data source using matching information', (): void => {
const matching: LieuxMediationNumeriqueMatching = {
prive: {
colonne: 'prive'
}
} as LieuxMediationNumeriqueMatching;

const source: DataSource = {
prive: true
};

const prive: boolean | undefined = isPrive(source, matching);

expect(prive).toBe(true);
});

it('should not get any prive field', (): void => {
const matching: LieuxMediationNumeriqueMatching = {
prive: {
colonne: 'prive'
}
} as LieuxMediationNumeriqueMatching;

const source: DataSource = {};

const prive: boolean | undefined = isPrive(source, matching);

expect(prive).toBe(false);
});
});
7 changes: 7 additions & 0 deletions src/transformer/fields/prive/prive.field.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { LieuxMediationNumeriqueMatching, DataSource, Colonne } from '../../input';

const canProcessPrive = (source: DataSource, prive?: Colonne): prive is Colonne =>
prive?.colonne != null && source[prive.colonne] != null;

export const isPrive = (source: DataSource, matching: LieuxMediationNumeriqueMatching): boolean =>
canProcessPrive(source, matching.prive) ? Boolean(source[matching.prive.colonne]) : false;
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export type LieuxMediationNumeriqueMatching = {
prise_rdv?: Colonne;
accessibilite?: Colonne;
semaine_ouverture?: Colonne;
prive?: Colonne;
horaires?: {
jours?: [
{
Expand Down
7 changes: 5 additions & 2 deletions src/transformer/input/to-lieux-mediation-numerique.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ import {
processPublicsAccueillis,
processServices,
processSource,
processTypologies
processTypologies,
isPrive
} from '../fields';
import { TransformationRepository } from '../repositories';
import { DataSource, LieuxMediationNumeriqueMatching } from './lieux-mediation-numerique-matching';
Expand Down Expand Up @@ -85,10 +86,12 @@ const lieuDeMediationNumerique = (
findCommune: FindCommune,
isInQpv: IsInQpv,
isInZrr: IsInZrr
): LieuMediationNumerique => {
): LieuMediationNumerique | undefined => {
const adresse: Adresse = processAdresse(findCommune)(dataSource, matching);
const localistaion: Localisation = processLocalisation(dataSource, matching);

if (isPrive(dataSource, matching)) return undefined;

const lieuMediationNumerique: LieuMediationNumerique = {
id: processId(dataSource, matching, index),
nom: processNom(dataSource, matching),
Expand Down

0 comments on commit 25407b0

Please sign in to comment.