Skip to content

Commit

Permalink
fix: tmp_siret object definition (#882)
Browse files Browse the repository at this point in the history
* feat: check diffusible sirets

* fix: corrected object

* fix: prettier

* feat: erreurs 422 plus considérées comme 404
  • Loading branch information
alanlr authored Dec 1, 2023
1 parent 2f9c327 commit 744216d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
9 changes: 5 additions & 4 deletions server/src/jobs/database/fixDiffusibleCompanies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,24 @@ export async function fixDiffusibleCompanies(): Promise<void> {

export async function checkDiffusibleCompanies(): Promise<void> {
logger.info(`Checking diffusible sirets`)
const sirets: AsyncIterable<string> = await db.collection("tmp_siret").find({})
const sirets: AsyncIterable<{ _id: string }> = await db.collection("tmp_siret").find({})

let count = 0
let nonDiffusibleCount = 0
let partiellementDiffusibleCount = 0
let unavailableCount = 0
let notFoundCount = 0
let errorCount = 0
for await (const siret of sirets) {
if (count % 500 === 0) {

for await (const { _id } of sirets) {
if (count % 100 === 0) {
logger.info(
`${count} sirets checked. ${partiellementDiffusibleCount} partDiff. ${unavailableCount} indisp. ${notFoundCount} non trouvé. ${nonDiffusibleCount} nonDiff. ${errorCount} errors`
)
}
count++
try {
const isDiffusible = await getDiffusionStatus(siret)
const isDiffusible = await getDiffusionStatus(_id)

switch (isDiffusible) {
case EDiffusibleStatus.NON_DIFFUSIBLE: {
Expand Down
3 changes: 1 addition & 2 deletions server/src/services/etablissement.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,11 @@ export const getEtablissementDiffusionStatus = async (siret: string): Promise<st
params: apiParams,
}
)

await saveSiretDiffusionStatus(siret, data.data.status_diffusion)

return data.data.status_diffusion
} catch (error: any) {
if (error?.response?.status === 404 || error?.response?.status === 422) {
if (error?.response?.status === 404) {
await saveSiretDiffusionStatus(siret, EDiffusibleStatus.NOT_FOUND)
return EDiffusibleStatus.NOT_FOUND
}
Expand Down

0 comments on commit 744216d

Please sign in to comment.