Skip to content

Commit

Permalink
fix(backend): fix infinite loop in soliguide's import
Browse files Browse the repository at this point in the history
  • Loading branch information
pYassine committed Nov 8, 2024
1 parent 3db2b8f commit 6804192
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const getFromDataInclusion = async (structureType: "CCAS" | "CIAS") => {
}
}

if (datInclusionData.length >= 500) {
if (datInclusionData?.length >= 500) {
appLogger.warn(
"Import 'data-inclusion' data N°" +
page +
Expand Down
11 changes: 8 additions & 3 deletions packages/backend/src/open-data-places/load-soliguide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ let nbResults = 0;
let newPlaces = 0;
let updatedPlaces = 0;

const RESULTS_BY_PAGE = 50;

const getFromSoliguide = async () => {
let soliguideData: SoliguidePlace[] = [];

Expand All @@ -31,7 +33,7 @@ const getFromSoliguide = async () => {
geoValue: "france",
},
options: {
limit: 50,
limit: RESULTS_BY_PAGE,
page,
},
},
Expand All @@ -43,7 +45,10 @@ const getFromSoliguide = async () => {
);

soliguideData = response.data.places;
nbResults = response.data.nbResults;

if (!nbResults) {
nbResults = response.data.nbResults;
}

for await (const place of soliguideData) {
let soliguidePlace = await openDataPlaceRepository.findOneBy({
Expand Down Expand Up @@ -114,7 +119,7 @@ const getFromSoliguide = async () => {
}
}

if (soliguideData.length * page < nbResults) {
if (soliguideData?.length === RESULTS_BY_PAGE) {
appLogger.warn(
`Import 'soliguide' data page N°${page} : ${
soliguideData.length * page
Expand Down
6 changes: 2 additions & 4 deletions packages/backend/src/run-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ import { domifaConfig } from "./config";
appLogger.warn(`[${__filename}] Application listening on port 3000`);

if (
(domifaConfig().envId === "prod" ||
domifaConfig().envId === "preprod" ||
domifaConfig().envId === "local") &&
(domifaConfig().envId === "prod" || domifaConfig().envId === "local") &&
domifaConfig().cron.enable
) {
await loadDomifaData();
await loadMssData();
await loadSoliguideData();
await loadMssData();
}
} catch (error) {
const err = error as Error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@ export class ProfilStructureDocsComponent implements OnInit, OnDestroy {
}

if (this.usager.decision.statut !== "RADIE") {
this.docs.filter(
(doc) => doc.customDocType === "courrier_radiation"
this.docs = this.docs.filter(
(doc) => doc.customDocType !== "courrier_radiation"
);
}

if (!this.usager.echeanceInfos.isActif) {
this.docs.filter(
(doc) => doc.customDocType === "attestation_postale"
this.docs = this.docs.filter(
(doc) => doc.customDocType !== "attestation_postale"
);
}
},
Expand Down

0 comments on commit 6804192

Please sign in to comment.