From 183fdfeaf49eab36d500a3be18f3c14fbfa6fba6 Mon Sep 17 00:00:00 2001 From: ttdm Date: Fri, 8 Nov 2024 16:05:13 +0100 Subject: [PATCH 1/3] auto fill the structure size --- .../establishment/establishmentController.ts | 33 +++++++--------- .../identification/TeeRegisterModal.vue | 4 +- .../domain/establishmentFeatures.ts | 38 ++++++++++++++++++- .../src/establishment/domain/types.ts | 1 + .../recherche-entreprise.ts | 3 +- .../api/recherche-entreprise/type.ts | 2 +- .../infrastructure/api/sirene/sirene.ts | 3 +- .../infrastructure/api/sirene/types.ts | 2 +- 8 files changed, 58 insertions(+), 28 deletions(-) diff --git a/apps/backend/src/controller/establishment/establishmentController.ts b/apps/backend/src/controller/establishment/establishmentController.ts index 232f81523..0e9fd360d 100644 --- a/apps/backend/src/controller/establishment/establishmentController.ts +++ b/apps/backend/src/controller/establishment/establishmentController.ts @@ -1,6 +1,6 @@ import { Controller, Route, SuccessResponse, TsoaResponse, Res, Example, Get, Path, Query } from 'tsoa' -import { ErrorJSON, Establishment, EstablishmentNotFoundError, EstablishmentService, ValidateErrorJSON, Monitor } from '@tee/backend-ddd' -import { EstablishmentSearch } from '@tee/common' +import { ErrorJSON, EstablishmentNotFoundError, EstablishmentService, ValidateErrorJSON, Monitor } from '@tee/backend-ddd' +import { EstablishmentFront, EstablishmentSearch, StructureSize } from '@tee/common' interface EstablishmentNotFoundErrorJSON { message: 'Establishment not found' @@ -12,24 +12,17 @@ interface EstablishmentNotFoundErrorJSON { export type Siret = string const exampleEstablishment = { - siren: '830141321', - nic: '00034', - siret: '83014132100034', - creationDate: '2021-12-01', - denomination: 'MULTI', - nafCode: '62.01Z', + codeNAF: '62.01Z', + codeNAF1: 'A', + ville: 'DALAYRAC', + codePostal: '94120', legalCategory: '5710', - nafSectionCode: 'A', - nafLabel: 'Programmation informatique', - address: { - streetNumber: '116', - streetType: 'RUE', - streetLabel: 'DALAYRAC', - zipCode: '94120', - cityLabel: 'FONTENAY-SOUS-BOIS', - cityCode: '94033' - }, - region: 'Île-de-France' + region: 'Île-de-France', + structure_size: StructureSize.TPE, + denomination: 'MULTI', + secteur: 'Programmation informatique', + creationDate: '2021-12-01', + siret: '83014132100034' } @SuccessResponse('200', 'OK') @@ -46,7 +39,7 @@ export class SireneController extends Controller { * @example requestBody: {"string": "siret, nom, adresse..."} */ - @Example(exampleEstablishment) + @Example(exampleEstablishment) @Get('{query}') public async getEstablishmentBySiret( @Path() query: string, diff --git a/apps/web/src/components/identification/TeeRegisterModal.vue b/apps/web/src/components/identification/TeeRegisterModal.vue index 7ad2feeaa..0dcd628df 100644 --- a/apps/web/src/components/identification/TeeRegisterModal.vue +++ b/apps/web/src/components/identification/TeeRegisterModal.vue @@ -70,8 +70,8 @@ const registerStep = computed(() => { }) const updateEstablishment = (selectedEstablishment: EstablishmentFront) => { company.value = selectedEstablishment - if (company.value.legalCategory === LegalCategory.EI) { - companySize.value = StructureSize.EI + if (company.value.structure_size) { + companySize.value = company.value.structure_size } manualRegistration.value = false } diff --git a/libs/backend-ddd/src/establishment/domain/establishmentFeatures.ts b/libs/backend-ddd/src/establishment/domain/establishmentFeatures.ts index 919995ccd..dbc9bb2fb 100644 --- a/libs/backend-ddd/src/establishment/domain/establishmentFeatures.ts +++ b/libs/backend-ddd/src/establishment/domain/establishmentFeatures.ts @@ -1,7 +1,7 @@ import { Result } from 'true-myth' import type { CityToRegionMappingType, EstablishmentRepository, NafMappingType } from './spi' import { Establishment, EstablishmentDetails, SearchResult, Siret } from './types' -import { EstablishmentFront, EstablishmentSearch, SiretValidator } from '@tee/common' +import { EstablishmentFront, EstablishmentSearch, LegalCategory, SiretValidator, StructureSize } from '@tee/common' export default class EstablishmentFeatures { private readonly _establishmentRepository: EstablishmentRepository @@ -90,7 +90,7 @@ export default class EstablishmentFeatures { codePostal: establishment.address.zipCode, region: establishment.region || '', legalCategory: establishment.legalCategory, - structure_size: undefined, + structure_size: this._computeBestStructureSizeGuess(establishment), denomination: establishment.denomination, secteur: establishment.nafLabel || '', creationDate: establishment.creationDate @@ -112,4 +112,38 @@ export default class EstablishmentFeatures { }) return { resultCount: result.resultCount, establishments: transformedEstablishments } } + + private _computeBestStructureSizeGuess(establishement: Establishment): StructureSize | undefined { + if (establishement.legalCategory === LegalCategory.EI) { + return StructureSize.EI + } + + switch (establishement.workforceRange) { + case '00': // 0 employee + case '01': // 1 to 2 employees + case '02': // 3 to 5 employees + case '03': // 6 to 9 employees + case '11': // 10 to 19 employees + return StructureSize.TPE + + case '12': // 20 to 49 employees + return StructureSize.PE + + case '21': // 50 to 99 employees + case '22': // 100 to 199 employees + case '31': // 200 to 249 employees + return StructureSize.ME + + case '32': // 250 to 499 employees + case '41': // 500 to 999 employees + case '51': // 1 000 to 1 999 employees + case '52': // 2 000 to 4 999 employees + case '53': // 5 000 to 9 999 employees + case '54': // 10 000 employees or more + return StructureSize.ETI_GE + + default: + return undefined + } + } } diff --git a/libs/backend-ddd/src/establishment/domain/types.ts b/libs/backend-ddd/src/establishment/domain/types.ts index 12097203d..6f4f0122a 100644 --- a/libs/backend-ddd/src/establishment/domain/types.ts +++ b/libs/backend-ddd/src/establishment/domain/types.ts @@ -21,6 +21,7 @@ export interface EstablishmentDetails { // https://www.insee.fr/fr/information/2560452 cityCode: string } + workforceRange: string } export interface GeographicDetails { diff --git a/libs/backend-ddd/src/establishment/infrastructure/api/recherche-entreprise/recherche-entreprise.ts b/libs/backend-ddd/src/establishment/infrastructure/api/recherche-entreprise/recherche-entreprise.ts index 207e67a12..1074dcd2a 100644 --- a/libs/backend-ddd/src/establishment/infrastructure/api/recherche-entreprise/recherche-entreprise.ts +++ b/libs/backend-ddd/src/establishment/infrastructure/api/recherche-entreprise/recherche-entreprise.ts @@ -51,7 +51,8 @@ export class RechercheEntreprise { zipCode: result.siege.code_postal, cityLabel: result.siege.libelle_commune, cityCode: result.siege.commune - } + }, + workforceRange: result.tranche_effectif_salarie })) return { establishments: establishmentList, diff --git a/libs/backend-ddd/src/establishment/infrastructure/api/recherche-entreprise/type.ts b/libs/backend-ddd/src/establishment/infrastructure/api/recherche-entreprise/type.ts index 4053c2f1d..d8a86891a 100644 --- a/libs/backend-ddd/src/establishment/infrastructure/api/recherche-entreprise/type.ts +++ b/libs/backend-ddd/src/establishment/infrastructure/api/recherche-entreprise/type.ts @@ -16,7 +16,7 @@ export interface RechercheEntrepriseEstablishment { nature_juridique: string section_activite_principale: string // NafSectionCode date_creation: string - + tranche_effectif_salarie: string // eslint-disable-next-line @typescript-eslint/no-explicit-any [key: string]: any } diff --git a/libs/backend-ddd/src/establishment/infrastructure/api/sirene/sirene.ts b/libs/backend-ddd/src/establishment/infrastructure/api/sirene/sirene.ts index 4137afe6c..0f5b47909 100644 --- a/libs/backend-ddd/src/establishment/infrastructure/api/sirene/sirene.ts +++ b/libs/backend-ddd/src/establishment/infrastructure/api/sirene/sirene.ts @@ -62,7 +62,8 @@ const parseEstablishment = (establishmentDocument: EstablishmentDocument): Estab zipCode: rawEstablishment.adresseEtablissement.codePostalEtablissement, cityLabel: rawEstablishment.adresseEtablissement.libelleCommuneEtablissement, cityCode: rawEstablishment.adresseEtablissement.codeCommuneEtablissement - } + }, + workforceRange: rawEstablishment.trancheEffectifsEtablissement } } diff --git a/libs/backend-ddd/src/establishment/infrastructure/api/sirene/types.ts b/libs/backend-ddd/src/establishment/infrastructure/api/sirene/types.ts index 64512d922..5fb236f21 100644 --- a/libs/backend-ddd/src/establishment/infrastructure/api/sirene/types.ts +++ b/libs/backend-ddd/src/establishment/infrastructure/api/sirene/types.ts @@ -5,7 +5,7 @@ export interface EstablishmentDocument { siret: string statutDiffusionEtablissement: string dateCreationEtablissement: string - trancheEffectifsEtablissement: null + trancheEffectifsEtablissement: string anneeEffectifsEtablissement: null activitePrincipaleRegistreMetiersEtablissement: null dateDernierTraitementEtablissement: string From d406802853a25c226e60d94c4d97564c4e801ef7 Mon Sep 17 00:00:00 2001 From: ttdm Date: Tue, 12 Nov 2024 09:15:54 +0100 Subject: [PATCH 2/3] fix lint by deleting unused imports --- apps/web/src/components/identification/TeeRegisterModal.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/web/src/components/identification/TeeRegisterModal.vue b/apps/web/src/components/identification/TeeRegisterModal.vue index 0dcd628df..4dd8eb2e2 100644 --- a/apps/web/src/components/identification/TeeRegisterModal.vue +++ b/apps/web/src/components/identification/TeeRegisterModal.vue @@ -45,7 +45,7 @@