Skip to content

Commit

Permalink
fix: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
abelkhay committed Jul 25, 2023
1 parent adfb2eb commit 21ef211
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/transformer/fields/typologies/typologies.field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,17 @@ const inferTypologies = (source: DataSource, matching: LieuxMediationNumeriqueMa
const checkingTypologieSourceValues = (source: DataSource, matching: LieuxMediationNumeriqueMatching): boolean[] | undefined =>
matching.typologie?.map(
(typo: Choice<Typologie>): boolean =>
source[typo.colonnes as unknown as string] != null && source[typo.colonnes as unknown as string] !== ''
typo.colonnes != null &&
source[typo.colonnes[0] as keyof DataSource] != null &&

Check failure on line 67 in src/transformer/fields/typologies/typologies.field.ts

View workflow job for this annotation

GitHub Actions / validation-matrix / (lint.all)

Use a ! assertion to more succinctly remove null and undefined from the type
source[typo.colonnes[0] as keyof DataSource] !== ''

Check failure on line 68 in src/transformer/fields/typologies/typologies.field.ts

View workflow job for this annotation

GitHub Actions / validation-matrix / (lint.all)

Use a ! assertion to more succinctly remove null and undefined from the type
);

const typologiesArePreset = (matching: LieuxMediationNumeriqueMatching): boolean =>
!!matching.typologie?.[0]?.cible && !matching.typologie?.[0].colonnes && !matching.typologie?.[0].termes;

Check failure on line 72 in src/transformer/fields/typologies/typologies.field.ts

View workflow job for this annotation

GitHub Actions / validation-matrix / (lint.all)

Unexpected value in conditional. A boolean expression is required

Check failure on line 72 in src/transformer/fields/typologies/typologies.field.ts

View workflow job for this annotation

GitHub Actions / validation-matrix / (lint.all)

Unexpected nullable object value in conditional. An explicit null check is required

Check failure on line 72 in src/transformer/fields/typologies/typologies.field.ts

View workflow job for this annotation

GitHub Actions / validation-matrix / (lint.all)

Unnecessary optional chain on a non-nullish value

Check failure on line 72 in src/transformer/fields/typologies/typologies.field.ts

View workflow job for this annotation

GitHub Actions / validation-matrix / (lint.all)

Unexpected nullable object value in conditional. An explicit null check is required

Check failure on line 72 in src/transformer/fields/typologies/typologies.field.ts

View workflow job for this annotation

GitHub Actions / validation-matrix / (lint.all)

Unnecessary optional chain on a non-nullish value

export const processTypologies = (source: DataSource, matching: LieuxMediationNumeriqueMatching): Typologies =>
((checkingTypologieSourceValues(source, matching) ?? []).some((check: boolean): boolean => !check) &&
matching.typologie?.at(0)?.cible !== Typologie.RFS &&
matching.typologie?.at(0)?.cible !== Typologie.TIERS_LIEUX) ||
!typologiesArePreset(matching)) ||
matching.typologie?.at(0)?.cible == null
? inferTypologies(source, matching)
: Typologies(Array.from(new Set(matching.typologie.reduce(appendTypologies(source), []))));

0 comments on commit 21ef211

Please sign in to comment.