Skip to content

Commit

Permalink
fix: correction de la fiabilisation via API alternance
Browse files Browse the repository at this point in the history
  • Loading branch information
moroine committed Oct 2, 2024
1 parent 22c3c59 commit a249668
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 102 deletions.
39 changes: 0 additions & 39 deletions .yarn/patches/zod-npm-3.21.4-9f570b215c.patch

This file was deleted.

3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,5 @@
"yarn.lock": [
"yarn dedupe"
]
},
"resolutions": {
"zod@3.21.4": "patch:zod@npm%3A3.21.4#./.yarn/patches/zod-npm-3.21.4-9f570b215c.patch"
}
}
4 changes: 2 additions & 2 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@types/stream-json": "^1.7.7",
"JSONStream": "^1.3.5",
"adm-zip": "^0.5.10",
"api-alternance-sdk": "^0.0.1-rc.10",
"api-alternance-sdk": "^0.0.1",
"axios": "0.27.2",
"axios-cache-interceptor": "^0.10.7",
"axios-retry": "3.3.1",
Expand Down Expand Up @@ -98,7 +98,7 @@
"type-fest": "^4.10.2",
"uuid": "8.3.2",
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.0/xlsx-0.20.0.tgz",
"zod": "3.21.4",
"zod": "^3.23.8",
"zod-express-middleware": "1.4.0"
},
"prettier": {
Expand Down
43 changes: 25 additions & 18 deletions server/src/jobs/fiabilisation/uai-siret/update.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { captureException } from "@sentry/node";
import { PromisePool } from "@supercharge/promise-pool";
import Boom from "boom";
import { AnyBulkWriteOperation } from "mongodb";
import {
IOrganisme,
Expand Down Expand Up @@ -145,35 +147,40 @@ export const updateOrganismesFiablesFermes = async () => {
};

export const updateOrganismesFiabilisationApiUaiSiret = async () => {
const organismsToUpdate = await organismesDb().find({}).toArray();
const cursor = organismesDb().find({});

const bulkOperations: AnyBulkWriteOperation<IOrganisme>[] = [];

for (const organism of organismsToUpdate) {
let count = 0;
for await (const organism of cursor) {
count++;
const { _id, siret, uai } = organism;

if (siret && uai) {
try {
const apiData = await apiAlternanceClient.organisme.recherche({ siret, uai });

if (apiData?.resultat?.status) {
const { ouvert, declaration_catalogue, validation_uai } = apiData.resultat.status;
const fiabilisationStatus =
ouvert && declaration_catalogue && validation_uai
? STATUT_FIABILISATION_API_ORGANISME.FIABLE
: STATUT_FIABILISATION_API_ORGANISME.NON_FIABLE;

bulkOperations.push({
updateOne: {
filter: { _id },
update: { $set: { fiabilisation_api_statut: fiabilisationStatus } },
const fiabilisation_api_response: IOrganisme["fiabilisation_api_response"] = apiData;

bulkOperations.push({
updateOne: {
filter: { _id },
update: {
$set: {
fiabilisation_api_statut:
apiData.resultat == null
? STATUT_FIABILISATION_API_ORGANISME.NON_FIABLE
: STATUT_FIABILISATION_API_ORGANISME.FIABLE,
fiabilisation_api_response,
},
},
});
} else {
logger.warn(`Données API non valides pour le SIRET : ${siret}, UAI : ${uai}`);
}
},
});
} catch (error) {
console.error(`Échec de l'appel API pour le SIRET : ${siret}, UAI : ${uai}`, error);
const err = Boom.internal("Échec de l'appel API pour la fiabilisation des organismes", { uai, siret });
err.cause = error;
captureException(err);
}
} else {
bulkOperations.push({
Expand All @@ -194,5 +201,5 @@ export const updateOrganismesFiabilisationApiUaiSiret = async () => {
logger.info("Aucun organisme à mettre à jour.");
}

return { status: "Mise à jour terminée", total: organismsToUpdate.length, updated: bulkOperations.length };
return { status: "Mise à jour terminée", total: count, updated: bulkOperations.length };
};
14 changes: 0 additions & 14 deletions server/src/jobs/jobs.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { addJob, initJobProcessor } from "job-processor";
import { getAnneesScolaireListFromDate } from "shared/utils";

import { apiAlternanceClient } from "@/common/apis/apiAlternance";
import logger from "@/common/logger";
import { createCollectionIndexes } from "@/common/model/indexes/createCollectionIndexes";
import { getDatabase } from "@/common/mongodb";
Expand Down Expand Up @@ -547,19 +546,6 @@ export async function setupJobProcessor() {
return createMigration(job.payload as any);
},
},
"test:organisme:validate": {
handler: async () => {
const r = await apiAlternanceClient.organisme
.recherche({
siret: "51400512300062",
uai: "0333326L",
})
.catch((e) => {
console.error(e);
});
console.log(r);
},
},
},
});
}
10 changes: 10 additions & 0 deletions shared/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,14 @@ module.exports = {
},
"import/internal-regex": "^shared",
},
parserOptions: {
project: "shared/tsconfig.json",
},
settings: {
"import/resolver": {
typescript: {
project: "shared/tsconfig.json",
},
},
},
};
4 changes: 4 additions & 0 deletions shared/models/data/organismes.model.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { zApiOrganismesRoutes } from "api-alternance-sdk";
import { isBefore, subMonths } from "date-fns";
import type { CreateIndexesOptions, IndexSpecification } from "mongodb";
import type { Jsonify } from "type-fest";
Expand Down Expand Up @@ -215,6 +216,9 @@ const zOrganisme = z
fiabilisation_api_statut: zodEnumFromObjValues(STATUT_FIABILISATION_API_ORGANISME)
.describe("Statut de fiabilisation venant de l'API de l'organisme")
.optional(),
fiabilisation_api_response: zApiOrganismesRoutes.get["/organisme/v1/recherche"].response["200"]
.describe("Statut du siret et uai venant de l'API de l'organisme")
.optional(),
mode_de_transmission: z.enum(["API", "MANUEL"]).describe("Mode de transmission des effectifs").optional(),
mode_de_transmission_configuration_date: z
.date({
Expand Down
3 changes: 2 additions & 1 deletion shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
},
"dependencies": {
"@asteasolutions/zod-to-openapi": "^6.4.0",
"api-alternance-sdk": "^0.0.1",
"date-fns": "^2.30.0",
"date-fns-tz": "^2.0.1",
"lodash-es": "^4.17.21",
"luhn": "^2.4.1",
"react": "18.2.0",
"type-fest": "^4.11.1",
"zod": "3.21.4",
"zod": "^3.23.8",
"zod-mongodb-schema": "^1.0.2"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion shared/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"pretty": true,
"isolatedModules": true,
"module": "ESNext" /* Specify what module code is generated. */,
"moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */,
"moduleResolution": "bundler" /* Specify how TypeScript looks up a file from a given module specifier. */,
"resolveJsonModule": true,
"target": "ES2022",
"outDir": "./dist" /* Specify an output folder for all emitted files. */,
Expand Down
2 changes: 1 addition & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.0/xlsx-0.20.0.tgz",
"yup": "0.32.11",
"yup-password": "0.2.2",
"zod": "3.21.4",
"zod": "^3.23.8",
"zod-formik-adapter": "1.2.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion ui/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"incremental": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
Expand Down
31 changes: 9 additions & 22 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5572,15 +5572,15 @@ __metadata:
languageName: node
linkType: hard

"api-alternance-sdk@npm:^0.0.1-rc.10":
version: 0.0.1-rc.10
resolution: "api-alternance-sdk@npm:0.0.1-rc.10"
"api-alternance-sdk@npm:^0.0.1":
version: 0.0.1
resolution: "api-alternance-sdk@npm:0.0.1"
dependencies:
"@asteasolutions/zod-to-openapi": ^7.1.1
luxon: ^3.5.0
openapi3-ts: ^4.3.3
zod: ^3.23.8
checksum: 80c2383bbfc14a82bd1f1f4b27f174b73d831ddd35404a2704108ca89ed2a51e32cbf5216044b49213c15981c4c62fb26f9db35f80bf2e88ee87fb1d8541db75
checksum: 7985fcb1cd6bbd0edfb25ec02199321c8b62ecbc0eba2a5f87ec6115c32358311adc952386c236e720d5e5f3f186315c1f0b72d05a5c89fe7379b3fb5ef0b10c
languageName: node
linkType: hard

Expand Down Expand Up @@ -17871,7 +17871,7 @@ __metadata:
"@types/stream-json": ^1.7.7
JSONStream: ^1.3.5
adm-zip: ^0.5.10
api-alternance-sdk: ^0.0.1-rc.10
api-alternance-sdk: ^0.0.1
axios: 0.27.2
axios-cache-interceptor: ^0.10.7
axios-retry: 3.3.1
Expand Down Expand Up @@ -17948,7 +17948,7 @@ __metadata:
typescript: ^5.3.3
uuid: 8.3.2
xlsx: "https://cdn.sheetjs.com/xlsx-0.20.0/xlsx-0.20.0.tgz"
zod: 3.21.4
zod: ^3.23.8
zod-express-middleware: 1.4.0
languageName: unknown
linkType: soft
Expand Down Expand Up @@ -18017,6 +18017,7 @@ __metadata:
"@asteasolutions/zod-to-openapi": ^6.4.0
"@tsconfig/node22": ^22.0.0
"@types/node": ^22.2.0
api-alternance-sdk: ^0.0.1
bson: ^5.5.1
date-fns: ^2.30.0
date-fns-tz: ^2.0.1
Expand All @@ -18026,7 +18027,7 @@ __metadata:
react: 18.2.0
type-fest: ^4.11.1
typescript: ^5.3.3
zod: 3.21.4
zod: ^3.23.8
zod-mongodb-schema: ^1.0.2
languageName: unknown
linkType: soft
Expand Down Expand Up @@ -19560,7 +19561,7 @@ __metadata:
xlsx: "https://cdn.sheetjs.com/xlsx-0.20.0/xlsx-0.20.0.tgz"
yup: 0.32.11
yup-password: 0.2.2
zod: 3.21.4
zod: ^3.23.8
zod-formik-adapter: 1.2.0
languageName: unknown
linkType: soft
Expand Down Expand Up @@ -20586,27 +20587,13 @@ __metadata:
languageName: node
linkType: hard

"zod@npm:3.21.4":
version: 3.21.4
resolution: "zod@npm:3.21.4"
checksum: f185ba87342ff16f7a06686767c2b2a7af41110c7edf7c1974095d8db7a73792696bcb4a00853de0d2edeb34a5b2ea6a55871bc864227dace682a0a28de33e1f
languageName: node
linkType: hard

"zod@npm:^3.23.8":
version: 3.23.8
resolution: "zod@npm:3.23.8"
checksum: 15949ff82118f59c893dacd9d3c766d02b6fa2e71cf474d5aa888570c469dbf5446ac5ad562bb035bf7ac9650da94f290655c194f4a6de3e766f43febd432c5c
languageName: node
linkType: hard

"zod@patch:zod@npm%3A3.21.4#./.yarn/patches/zod-npm-3.21.4-9f570b215c.patch::locator=mna-tdb%40workspace%3A.":
version: 3.21.4
resolution: "zod@patch:zod@npm%3A3.21.4#./.yarn/patches/zod-npm-3.21.4-9f570b215c.patch::version=3.21.4&hash=45704f&locator=mna-tdb%40workspace%3A."
checksum: 8ac3afb02adff75a1d562c3479f39331548f94cd1d7f5d52623834ec75007db83c35edd8789d47d96ccb4994eec0c0a8e0bfd17130cd1db5013fd4900e0181f5
languageName: node
linkType: hard

"zwitch@npm:^1.0.0":
version: 1.0.5
resolution: "zwitch@npm:1.0.5"
Expand Down

0 comments on commit a249668

Please sign in to comment.