Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: merge RCS and RNE for agents #1092

Merged
merged 9 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions app/(header-default)/dirigeants/_component/sections/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,18 @@ export async function DirigeantInformation({
uniteLegale={uniteLegale}
immatriculationRNE={immatriculationRNE}
/>
<DirigeantsSection
uniteLegale={uniteLegale}
immatriculationRNE={immatriculationRNE}
/>
{mandatairesRCS && (

{mandatairesRCS ? (
<MandatairesRCSSection
immatriculationRNE={immatriculationRNE}
uniteLegale={uniteLegale}
mandatairesRCS={mandatairesRCS}
/>
) : (
<DirigeantsSection
uniteLegale={uniteLegale}
immatriculationRNE={immatriculationRNE}
/>
)}

<BreakPageForPrint />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import routes from '#clients/routes';
import { Warning } from '#components-ui/alerts';
import { Info, Warning } from '#components-ui/alerts';
import { INPI } from '#components/administrations';
import { DataSection } from '#components/section/data-section';
import { EAdministration } from '#models/administrations/EAdministration';
import { IAPILoading, isAPILoading } from '#models/api-loading';
Expand All @@ -10,6 +11,7 @@ import {
import { IUniteLegale } from '#models/core/types';
import { IDirigeant, IImmatriculationRNE } from '#models/immatriculation';
import { DirigeantContent } from './dirigeant-content';
import DirigeantsSection from './rne-dirigeants';

type IProps = {
immatriculationRNE: IImmatriculationRNE | IAPINotRespondingError;
Expand All @@ -31,46 +33,37 @@ async function MandatairesRCSSection({
title="Dirigeant(s)"
isProtected
notFoundInfo={null}
sources={[EAdministration.INFOGREFFE]}
sources={[EAdministration.INPI, EAdministration.INFOGREFFE]}
data={mandatairesRCS}
>
{(mandatairesRCS) =>
mandatairesRCS.length === 0 ? (
<p>Cette entreprise ne possède aucun dirigeant.</p>
<DirigeantsSection
uniteLegale={uniteLegale}
immatriculationRNE={immatriculationRNE}
/>
) : (
<>
{RCSDiffersFromRNE(mandatairesRCS, immatriculationRNE) && (
<Warning>
Le nombre de dirigeants enregistrés sur Infogreffe (ex-RCS)
diffère de celui du RNE. Cette situation est anormale. Pour en
savoir plus vous pouvez consulter la page de cette entreprise
sur{' '}
<a
rel="noopener"
target="_blank"
href={`${routes.rne.portail.entreprise}${uniteLegale.siren}`}
aria-label="Consulter la liste des dirigeants sur le site de l’INPI, nouvelle fenêtre"
>
data.inpi.fr
</a>{' '}
ou sur{' '}
<a
rel="noopener"
target="_blank"
href={`${routes.infogreffe.portail.entreprise}${uniteLegale.siren}`}
aria-label="Consulter la liste des dirigeants sur le site d’Infogreffe, nouvelle fenêtre"
>
Infogreffe
</a>
.
</Warning>
)}
<Info>
Ces informations proviennent d’
<a
rel="noopener"
target="_blank"
href={`${routes.infogreffe.portail.home}`}
aria-label="Visiter le site d’Infogreffe, nouvelle fenêtre"
>
Infogreffe
</a>{' '}
et incluent la date de naissance des dirigeant(e)s.
</Info>
<RCSDiffersFromRNE
mandatairesRCS={mandatairesRCS}
immatriculationRNE={immatriculationRNE}
uniteLegale={uniteLegale}
/>
<p>
Cette entreprise possède {mandatairesRCS.length} mandataire(s)
enregistrés sur <strong>Infogreffe</strong> (ex-RCS). Nous vous
affichons cette liste en complément du RNE car elle permet
d’accèder à la date de naissance complète des personnes physiques
:
Cette entreprise possède {mandatairesRCS.length} dirigeant(s)
enregistré(s) au RNE :
</p>
<DirigeantContent
dirigeants={mandatairesRCS}
Expand All @@ -85,15 +78,45 @@ async function MandatairesRCSSection({
}
export default MandatairesRCSSection;

function RCSDiffersFromRNE(
mandatairesRCS: Array<IDirigeant>,
immatriculationRNE: IImmatriculationRNE | IAPINotRespondingError | IAPILoading
) {
function RCSDiffersFromRNE({
mandatairesRCS,
immatriculationRNE,
uniteLegale,
}: {
mandatairesRCS: Array<IDirigeant>;
immatriculationRNE:
| IImmatriculationRNE
| IAPINotRespondingError
| IAPILoading;
uniteLegale: IUniteLegale;
}) {
if (
isAPILoading(immatriculationRNE) ||
isAPINotResponding(immatriculationRNE)
) {
return null;
}
return mandatairesRCS.length !== immatriculationRNE.dirigeants.length;

if (immatriculationRNE.dirigeants.length === mandatairesRCS.length) {
return null;
}

return (
<Warning>
Les données d’Infogreffe sont issues du RNE mais il y a une différence
entre le nombre de dirigeant(s) retourné(s) par l’
<INPI />({immatriculationRNE.dirigeants.length}) et par Infogreffe (
{mandatairesRCS.length}). Pour comparer, vous pouvez consulter la page de
cette entreprise sur{' '}
<a
rel="noopener"
target="_blank"
href={`${routes.rne.portail.entreprise}${uniteLegale.siren}`}
aria-label="Consulter la liste des dirigeants sur le site de l’INPI, nouvelle fenêtre"
>
data.inpi.fr
</a>
.
</Warning>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,18 @@ export default function CarteProfessionnelleTPSection({
id="carte-professionnelle-travaux-publics"
isProtected
notFoundInfo={
'Aucune carte professionnelle trouvée pour cette entreprise'
<>
Cette entreprise n’a pas de{' '}
<a
href="https://www.fntp.fr/tout-savoir-sur-la-carte-professionnelle-tp"
aria-label="En savoir plus sur la carte professionnelle d’entrepreneur de travaux publics, nouvelle fenêtre"
target="_blank"
rel="noreferrer"
>
carte professionnelle d’entrepreneur de travaux publics
</a>
.
</>
}
sources={[EAdministration.FNTP]}
data={carteProfessionnelleTravauxPublics}
Expand Down

This file was deleted.

14 changes: 8 additions & 6 deletions app/(header-default)/labels-certificats/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
checkHasLabelsAndCertificates,
checkHasQuality,
} from '#components/badges-section/labels-and-certificates';
import { OpqibiSection } from '#components/espace-agent-components/certifications/opqibi-section';
import { QualifelecSection } from '#components/espace-agent-components/certifications/qualifelec-section';
import { CertificationsBioSection } from '#components/labels-and-certificates/bio';
import { EgaproSection } from '#components/labels-and-certificates/egapro';
import { CertificationsEntrepreneurSpectaclesSection } from '#components/labels-and-certificates/entrepreneur-spectacles';
Expand All @@ -25,7 +27,6 @@ import extractParamsAppRouter, {
AppRouterProps,
} from '#utils/server-side-helper/app/extract-params';
import getSession from '#utils/server-side-helper/app/get-session';
import { ProtectedCertificats } from './_components/protected-certificats';

export const generateMetadata = async (
props: AppRouterProps
Expand Down Expand Up @@ -116,11 +117,12 @@ const LabelsAndCertificatsPage = async (props: AppRouterProps) => {
<CertificationsBioSection uniteLegale={uniteLegale} bio={bio} />
)}
{hasRights(session, EScope.protectedCertificats) && (
<ProtectedCertificats
uniteLegale={uniteLegale}
session={session}
hasOtherCertificates={checkHasLabelsAndCertificates(uniteLegale)}
/>
<>
<HorizontalSeparator />
{/* <QualibatSection qualibat={protectedCertificates.qualibat} /> */}
<QualifelecSection uniteLegale={uniteLegale} />
<OpqibiSection uniteLegale={uniteLegale} />
</>
)}
</div>
</>
Expand Down
38 changes: 38 additions & 0 deletions app/api/data-fetching/espace-agent/_helper/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { HttpForbiddenError } from '#clients/exceptions';
import { EAdministration } from '#models/administrations/EAdministration';
import { FetchRessourceException } from '#models/exceptions';
import { EScope, hasRights } from '#models/user/rights';
import { logFatalErrorInSentry } from '#utils/sentry';
import getSession from '#utils/server-side-helper/app/get-session';

export async function ProtectedAPIRoute<T>(
routeLabel: string,
slug: string,
administration: EAdministration,
scope: EScope,
run: (agentSiret: string) => Promise<T>
) {
const session = await getSession();
try {
if (!hasRights(session, scope)) {
throw new HttpForbiddenError('Unauthorized account');
}

const agentSiret = session?.user?.siret || 'Inconnu';

const data = await run(agentSiret);
return Response.json(data, { status: 200 });
} catch (e: any) {
const message = `Failed to get donnees ${routeLabel}`;
logFatalErrorInSentry(
new FetchRessourceException({
ressource: routeLabel,
context: { slug },
cause: e,
message,
administration,
})
);
return Response.json({ message }, { status: e.status || 500 });
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { EAdministration } from '#models/administrations/EAdministration';
import { getCarteProfessionnelleTravauxPublic } from '#models/espace-agent/carte-professionnelle-travaux-publics';
import { EScope } from '#models/user/rights';
import { verifySiren } from '#utils/helpers';
import { ProtectedAPIRoute } from '../../_helper';

export async function GET(
_request: Request,
{ params }: { params: { slug: string } }
) {
const slug = params.slug;
return ProtectedAPIRoute(
'CarteProfessionnelleTravauxPublics',
slug,
EAdministration.DINUM,
EScope.protectedCertificats,
async (agentSiret: string) => {
const siren = verifySiren(slug as string);
return await getCarteProfessionnelleTravauxPublic(siren, agentSiret);
}
);
}
22 changes: 22 additions & 0 deletions app/api/data-fetching/espace-agent/opqibi/[slug]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { EAdministration } from '#models/administrations/EAdministration';
import { getOpqibi } from '#models/espace-agent/certificats/opqibi';
import { EScope } from '#models/user/rights';
import { verifySiren } from '#utils/helpers';
import { ProtectedAPIRoute } from '../../_helper';

export async function GET(
_request: Request,
{ params }: { params: { slug: string } }
) {
const slug = params.slug;
return ProtectedAPIRoute(
'Opqibi',
slug,
EAdministration.DINUM,
EScope.protectedCertificats,
async (agentSiret: string) => {
const siren = verifySiren(slug as string);
return await getOpqibi(siren, agentSiret);
}
);
}
22 changes: 22 additions & 0 deletions app/api/data-fetching/espace-agent/qualibat/[slug]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { EAdministration } from '#models/administrations/EAdministration';
import { getQualibat } from '#models/espace-agent/certificats/qualibat';
import { EScope } from '#models/user/rights';
import { verifySiret } from '#utils/helpers';
import { ProtectedAPIRoute } from '../../_helper';

export async function GET(
_request: Request,
{ params }: { params: { slug: string } }
) {
const slug = params.slug;
return ProtectedAPIRoute(
'Qualibat',
slug,
EAdministration.DINUM,
EScope.protectedCertificats,
async (agentSiret: string) => {
const siret = verifySiret(slug as string);
return await getQualibat(siret, agentSiret);
}
);
}
Loading
Loading