Skip to content

Commit

Permalink
Merge branch 'main' into 1304-remove-redis
Browse files Browse the repository at this point in the history
Signed-off-by: Xavier Jp <xavier.jouppe@beta.gouv.fr>
  • Loading branch information
XavierJp authored Nov 6, 2024
2 parents 2a6679d + 8d7caca commit a28e4c2
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 33 deletions.
1 change: 0 additions & 1 deletion .env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ MATOMO_SITE_ID=
MATOMO_API_SITE_ID=
ALTERNATIVE_SEARCH_ROUTE=
PROXY_API_KEY=
REDIS_ENABLED=false
AGENTCONNECT_CLIENT_ID=
AGENTCONNECT_CLIENT_SECRET=
AGENTCONNECT_URL_DISCOVER=https://fca.integ01.dev-agentconnect.fr/api/v2/.well-known/openid-configuration
Expand Down
2 changes: 2 additions & 0 deletions clients/rge/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import stubClientWithSnapshots from '#clients/stub-client-with-snaphots';
import { INomCertificat, IRGECertification } from '#models/certifications/rge';
import { Siren } from '#utils/helpers';
import { httpGet } from '#utils/network';
import { getCertificatLogoPath } from '../../utils/helpers/certifications/certificats-logo';

type IRGEResponse = {
results: {
Expand Down Expand Up @@ -90,6 +91,7 @@ const mapToDomainObject = (rge: IRGEResponse) => {
url_qualification = '',
} = result;
certifications.push({
logoPath: getCertificatLogoPath(nom_certificat),
codeQualification: code_qualification,
domaines: [domaine],
nomCertificat: nom_certificat,
Expand Down
8 changes: 2 additions & 6 deletions components/labels-and-certificates/rge/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { IRGECertification } from '#models/certifications/rge';
import { IUniteLegale } from '#models/core/types';
import { ISession } from '#models/user/session';
import React from 'react';
import { certificatLogo } from './map-certicat-to-logo';

const renovLink = (slug: string) => {
try {
Expand Down Expand Up @@ -115,13 +114,10 @@ export const CertificationsRGESection: React.FC<{
head={['Certificat', 'Domaine(s) certifié(s)', 'Lien']}
body={certificationsRGE.certifications.map((certification) => [
<div className="font-small layout-left">
{certification.nomCertificat in certificatLogo && (
{certification.logoPath && (
<div style={{ width: 72 }}>
<img
src={`/images/rge/logo-rge-${
//@ts-ignore
certificatLogo[certification.nomCertificat]
}`}
src={certification.logoPath}
alt={`Logo ${certification.nomCertificat}`}
title={`Logo ${certification.nomCertificat}`}
width="100%"
Expand Down
19 changes: 0 additions & 19 deletions components/labels-and-certificates/rge/map-certicat-to-logo.tsx

This file was deleted.

1 change: 1 addition & 0 deletions data/administrations/qualifelec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ long: Qualifelec
site: https://www.qualifelec.fr/
contact: https://www.qualifelec.fr/contact/
estServicePublic: false
logoType: portrait
dataSources:
- label: Liste des entreprises Qualifelec
apiSlug: api-entreprise
Expand Down
1 change: 1 addition & 0 deletions models/certifications/rge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export interface IRGECertification {
workingWithIndividual: boolean;
};
certifications: {
logoPath: string;
codeQualification: string;
nomCertificat: INomCertificat;
domaines: string[];
Expand Down
4 changes: 1 addition & 3 deletions models/espace-agent/association-protected/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,10 @@ export const getAssociationProtected = async (
maybeSiren: string
): Promise<IAssociationProtected | IAPINotRespondingError> => {
const siren = verifySiren(maybeSiren);
const response = clientApiEntrepriseAssociation(siren).catch((error) =>
return clientApiEntrepriseAssociation(siren).catch((error) =>
handleApiEntrepriseError(error, {
siren,
apiResource: 'AssociationProtected',
})
);

return response;
};
19 changes: 15 additions & 4 deletions models/espace-agent/certificats/qualifelec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { clientApiEntrepriseQualifelec } from '#clients/api-entreprise/qualifelec';
import { IAPINotRespondingError } from '#models/api-not-responding';
import { EAdministration } from '#models/administrations/EAdministration';
import {
APINotRespondingFactory,
IAPINotRespondingError,
} from '#models/api-not-responding';
import { verifySiret } from '#utils/helpers';
import { handleApiEntrepriseError } from '../utils';

export type IQualifelec = Array<{
documentUrl: string;
numero: number;
Expand Down Expand Up @@ -44,7 +49,13 @@ export const getQualifelec = async (
maybeSiret: string
): Promise<IQualifelec | IAPINotRespondingError> => {
const siret = verifySiret(maybeSiret);
return clientApiEntrepriseQualifelec(siret).catch((error) =>
handleApiEntrepriseError(error, { siret, apiResource: 'Qualifelec' })
);
return clientApiEntrepriseQualifelec(siret)
.then((response) =>
response.length === 0
? APINotRespondingFactory(EAdministration.QUALIFELEC, 404)
: response
)
.catch((error) =>
handleApiEntrepriseError(error, { siret, apiResource: 'Qualifelec' })
);
};
1 change: 1 addition & 0 deletions public/images/logos/qualifelec.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
26 changes: 26 additions & 0 deletions utils/helpers/certifications/certificats-logo.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { getCertificatLogoPath } from './certificats-logo';

describe('CertificatLogo works', () => {
test('valid certificatss names', () => {
expect(getCertificatLogoPath('qualifelec +')).toBe(
'/images/rge/logo-rge-qualifelec.jpg'
);
expect(getCertificatLogoPath('qualipv')).toBe(
'/images/rge/logo-rge-qualiPV.jpg'
);
expect(getCertificatLogoPath('chauffage +')).toBe(
'/images/rge/logo-rge-chauffage.jpg'
);
expect(getCertificatLogoPath('habitat')).toBe(
'/images/rge/logo-rge-NF.jpg'
);
});

test('Invalids certificates names', () => {
expect(getCertificatLogoPath('quali')).toBe('');
expect(getCertificatLogoPath('3456')).toBe('');
expect(getCertificatLogoPath('chauffage+')).toBe('');
});
});

export {};
29 changes: 29 additions & 0 deletions utils/helpers/certifications/certificats-logo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const certificatsLogo = {
qualibat: 'qualibat.jpg',
qualifelec: 'qualifelec.jpg',
qualipac: 'qualiPAC.jpg',
qualibois: 'qualiBois.jpg',
opqibi: 'opqibi.jpg',
'chauffage +': 'chauffage.jpg',
qualipv: 'qualiPV.jpg',
ventilation: 'ventillation.jpg',
qualisol: 'qualisol.jpg',
certibat: 'certibat.jpg',
habitat: 'NF.jpg',
qualiforage: 'aualiForage.jpg',
};

/**
* match logo path on partial certificats names as several certificates share the same logo
*
* eg : "Qualibois module Air" and "Qualibois module Eau" => QualiBois.jpg
* */

export const getCertificatLogoPath = (nomCertificat: string) => {
for (let [certificateSub, path] of Object.entries(certificatsLogo)) {
if ((nomCertificat || '').toLowerCase().indexOf(certificateSub) !== -1) {
return `/images/rge/logo-rge-${path}` || '';
}
}
return '';
};

0 comments on commit a28e4c2

Please sign in to comment.