Skip to content

Commit

Permalink
chore: move rne document call to server (#1061)
Browse files Browse the repository at this point in the history
  • Loading branch information
johangirod committed May 29, 2024
1 parent 86e3008 commit 527e000
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 147 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { DonneesPriveesSection } from '#components/donnees-privees-section';
import { estDiffusible } from '#models/core/statut-diffusion';
import { IUniteLegale } from '#models/core/types';
import { getMandatairesRCS } from '#models/espace-agent/mandataires-rcs';
import getImmatriculationRNE from '#models/immatriculation/rne';
import { getImmatriculationRNE } from '#models/immatriculation/rne';
import { EScope, hasRights } from '#models/user/rights';
import { ISession } from '#models/user/session';
import BeneficiairesSection from './beneficiaires';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IUniteLegale } from '#models/core/types';
import getImmatriculationRNE from '#models/immatriculation/rne';
import { getImmatriculationRNE } from '#models/immatriculation/rne';
import { ISession } from '#models/user/session';
import { IJustificatifs, ImmatriculationsSection } from './container';

Expand Down
38 changes: 0 additions & 38 deletions app/api/data-fetching/espace-agent/_helper/index.ts

This file was deleted.

26 changes: 0 additions & 26 deletions app/api/data-fetching/espace-agent/documents/[slug]/route.ts

This file was deleted.

1 change: 0 additions & 1 deletion clients/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const routes = {
api: {
rne: {
documents: {
list: '/api/data-fetching/espace-agent/documents/',
download: '/api/download/espace-agent/documents/',
},
},
Expand Down
27 changes: 15 additions & 12 deletions components/espace-agent-components/documents/actes-walled.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IUniteLegale } from '#models/core/types';
import { getDocumentsRNEProtected } from '#models/immatriculation/rne';
import { EScope, hasRights } from '#models/user/rights';
import { ISession } from '#models/user/session';
import AgentWallDocuments from '../agent-wall/document';
Expand All @@ -7,16 +8,18 @@ import { AgentActesSection } from './data-section/actes';
const ActesSection: React.FC<{
uniteLegale: IUniteLegale;
session: ISession | null;
}> = ({ uniteLegale, session }) =>
!hasRights(session, EScope.actesRne) ? (
<AgentWallDocuments
title="Actes et statuts"
id="actes"
uniteLegale={uniteLegale}
condition={!hasRights(session, EScope.actesRne)}
/>
) : (
<AgentActesSection uniteLegale={uniteLegale} />
);

}> = async ({ uniteLegale, session }) => {
if (!hasRights(session, EScope.actesRne)) {
return (
<AgentWallDocuments
title="Actes et statuts"
id="actes"
uniteLegale={uniteLegale}
condition={!hasRights(session, EScope.actesRne)}
/>
);
}
const documents = getDocumentsRNEProtected(uniteLegale.siren);
return <AgentActesSection uniteLegale={uniteLegale} documents={documents} />;
};
export default ActesSection;
26 changes: 15 additions & 11 deletions components/espace-agent-components/documents/bilans-walled.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IUniteLegale } from '#models/core/types';
import { getDocumentsRNEProtected } from '#models/immatriculation/rne';
import { EScope, hasRights } from '#models/user/rights';
import { ISession } from '#models/user/session';
import AgentWallDocuments from '../agent-wall/document';
Expand All @@ -7,16 +8,19 @@ import AgentBilansSection from './data-section/bilans';
const BilansSection: React.FC<{
uniteLegale: IUniteLegale;
session: ISession | null;
}> = ({ uniteLegale, session }) =>
!hasRights(session, EScope.bilansRne) ? (
<AgentWallDocuments
title="Bilans"
id="bilans"
uniteLegale={uniteLegale}
condition={!hasRights(session, EScope.bilansRne)}
/>
) : (
<AgentBilansSection uniteLegale={uniteLegale} />
);
}> = async ({ uniteLegale, session }) => {
if (!hasRights(session, EScope.bilansRne)) {
return (
<AgentWallDocuments
title="Bilans"
id="bilans"
uniteLegale={uniteLegale}
condition={!hasRights(session, EScope.bilansRne)}
/>
);
}
const documents = getDocumentsRNEProtected(uniteLegale.siren);
return <AgentBilansSection uniteLegale={uniteLegale} documents={documents} />;
};

export default BilansSection;
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,29 @@ import { Warning } from '#components-ui/alerts';
import ButtonLink from '#components-ui/button';
import { PrintNever } from '#components-ui/print-visibility';
import ShowMore from '#components-ui/show-more';
import { AsyncDataSectionClient } from '#components/section/data-section/client';
import { AsyncDataSectionServer } from '#components/section/data-section/server';
import { FullTable } from '#components/table/full';
import { EAdministration } from '#models/administrations/EAdministration';
import { IAPINotRespondingError } from '#models/api-not-responding';
import {
IUniteLegale,
isAssociation,
isServicePublic,
} from '#models/core/types';
import { IActesRNE } from '#models/immatriculation';
import { formatDateLong } from '#utils/helpers';
import useFetchActesRNE from 'hooks/fetch/actes-RNE';

const NoDocument = () => (
<>Aucun document n’a été retrouvé dans le RNE pour cette entreprise.</>
);

export const AgentActesSection: React.FC<{
uniteLegale: IUniteLegale;
}> = ({ uniteLegale }) => {
const documents = useFetchActesRNE(uniteLegale);

documents: Promise<IActesRNE | IAPINotRespondingError>;
}> = ({ uniteLegale, documents }) => {
return (
<PrintNever>
<AsyncDataSectionClient
<AsyncDataSectionServer
title="Actes et statuts"
id="actes"
isProtected
Expand Down Expand Up @@ -72,7 +71,7 @@ export const AgentActesSection: React.FC<{
</>
)
}
</AsyncDataSectionClient>
</AsyncDataSectionServer>
</PrintNever>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,30 @@ import ButtonLink from '#components-ui/button';
import FAQLink from '#components-ui/faq-link';
import { PrintNever } from '#components-ui/print-visibility';
import { Tag } from '#components-ui/tag';
import { AsyncDataSectionClient } from '#components/section/data-section/client';
import { AsyncDataSectionServer } from '#components/section/data-section/server';
import { FullTable } from '#components/table/full';
import { EAdministration } from '#models/administrations/EAdministration';
import { IAPINotRespondingError } from '#models/api-not-responding';
import {
IUniteLegale,
isAssociation,
isServicePublic,
} from '#models/core/types';
import { IActesRNE } from '#models/immatriculation';
import { formatDateLong } from '#utils/helpers';
import { getFiscalYear } from '#utils/helpers/formatting/format-fiscal-year';
import useFetchActesRNE from 'hooks/fetch/actes-RNE';

const NoBilans = () => (
<>Aucun comptes n’a été déposé au RNE pour cette entreprise.</>
);

const AgentBilansSection: React.FC<{
uniteLegale: IUniteLegale;
}> = ({ uniteLegale }) => {
const documents = useFetchActesRNE(uniteLegale);

documents: Promise<IActesRNE | IAPINotRespondingError>;
}> = ({ uniteLegale, documents }) => {
return (
<PrintNever>
<AsyncDataSectionClient
<AsyncDataSectionServer
title="Bilans"
id="bilans"
isProtected
Expand Down Expand Up @@ -94,7 +94,7 @@ const AgentBilansSection: React.FC<{
</>
)
}
</AsyncDataSectionClient>
</AsyncDataSectionServer>
</PrintNever>
);
};
Expand Down
7 changes: 0 additions & 7 deletions cypress/e2e/data-fetching.cy.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
describe('Data fetching routes', () => {
it('Agent-only routes are forbidden', () => {
cy.request({
url: '/api/data-fetching/espace-agent/documents/552032534',
failOnStatusCode: false,
}).then((resp) => {
expect(resp.status).to.eq(403);
});

cy.request({
url: '/api/download/espace-agent/documents/552032534',
failOnStatusCode: false,
Expand Down
34 changes: 0 additions & 34 deletions hooks/fetch/actes-RNE.ts

This file was deleted.

2 changes: 2 additions & 0 deletions models/espace-agent/conformite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export const getConformiteEntreprise = async (
siret: Siret,
recipientSiret?: string
): Promise<IConformiteUniteLegale> => {
await new Promise((resolve) => setTimeout(resolve, 20000));

const [fiscale, vigilance, msa] = await Promise.all([
clientApiEntrepriseConformiteFiscale(siren, recipientSiret).catch((error) =>
handleApiEntrepriseError(error, { siren, siret })
Expand Down
20 changes: 18 additions & 2 deletions models/immatriculation/rne.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { fetchRNEImmatriculation } from '#clients/api-proxy/rne';
import { clientDocuments } from '#clients/api-proxy/rne/documents';
import { HttpNotFound } from '#clients/exceptions';
import routes from '#clients/routes';
import { EAdministration } from '#models/administrations/EAdministration';
Expand All @@ -13,7 +14,7 @@ import { IImmatriculationRNE } from '.';
* Request Immatriculation from INPI's RNE
* @param siren
*/
const getImmatriculationRNE = async (
export const getImmatriculationRNE = async (
siren: Siren
): Promise<IAPINotRespondingError | IImmatriculationRNE> => {
try {
Expand Down Expand Up @@ -47,4 +48,19 @@ const getImmatriculationRNE = async (
}
};

export default getImmatriculationRNE;
export async function getDocumentsRNEProtected(siren: Siren) {
try {
const actes = await clientDocuments(siren);
actes.hasBilanConsolide =
actes.bilans.filter((b) => b.typeBilan === 'K').length > 0;
return actes;
} catch (e: any) {
if (e instanceof HttpNotFound) {
return APINotRespondingFactory(EAdministration.INPI, 404);
}

// no need to log an error as API-Proxy already logged it

return APINotRespondingFactory(EAdministration.INPI, 500);
}
}

0 comments on commit 527e000

Please sign in to comment.