Skip to content

Commit

Permalink
fix: fixed update script
Browse files Browse the repository at this point in the history
  • Loading branch information
GaelFerrand committed Feb 27, 2025
1 parent 169fbc6 commit 56a4aba
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions back/src/scripts/bin/updateCompaniesSplittedAdresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@ import { prisma } from "@td/prisma";
import { getCompanySplittedAddress } from "../../companies/companyUtils";
import { Company } from "@prisma/client";
import { searchCompanyTD } from "../../companies/sirene/trackdechets/client";
import { SiretNotFoundError } from "../../companies/sirene/errors";
import { SireneSearchResult } from "../../companies/sirene/types";

// TODO: important: comment out the ClosedCompanyError!!!
// back/src/companies/sirene/insee/client.ts
// back/src/companies/sirene/trackdechets/client.ts

// Résultat avec la DB de sandbox:
// 30162 entreprises mises à jour, 0 erreurs (0%), 108 ignorées (0%) en 713504ms!
// Commande: npx tsx --tsconfig back/tsconfig.lib.json back/src/scripts/bin/updateCompaniesSplittedAdresses.ts

(async function () {
console.log(">> Lancement du script de mise à jour des adresses splittées");

let companiesTotal = 0;
let errors = 0;
let ignored = 0;
let addressTest = 0;

const startDate = new Date();

Expand Down Expand Up @@ -60,12 +58,19 @@ import { searchCompanyTD } from "../../companies/sirene/trackdechets/client";
companiesTotal += 1;

if (company.address === "Adresse test") {
ignored++;
addressTest++;
continue;
}

try {
const companySearch = await searchCompanyTD(company.orgId);
let companySearch: SireneSearchResult | null = null;
try {
companySearch = await searchCompanyTD(company.orgId);
} catch (e) {
if (!(e instanceof SiretNotFoundError)) {
throw e;
}
}

const splittedAddress = getCompanySplittedAddress(
companySearch,
Expand Down Expand Up @@ -107,6 +112,8 @@ import { searchCompanyTD } from "../../companies/sirene/trackdechets/client";
(errors / companiesTotal) * 100
)}%), ${ignored} ignorées (${Math.round(
(ignored / companiesTotal) * 100
)}%), ${addressTest} addresses test (${Math.round(
(addressTest / companiesTotal) * 100
)}%) en ${duration}ms!`
);

Expand Down

0 comments on commit 56a4aba

Please sign in to comment.