Skip to content

Commit

Permalink
Merge branch 'feat/structure_size_auto_fill' into release/WIP-siret-c…
Browse files Browse the repository at this point in the history
…ross-recording
  • Loading branch information
dolemoine committed Nov 15, 2024
2 parents c13d654 + d54b3fd commit beafec5
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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')
Expand All @@ -46,7 +39,7 @@ export class SireneController extends Controller {
* @example requestBody: {"string": "siret, nom, adresse..."}
*/

@Example<Establishment>(exampleEstablishment)
@Example<EstablishmentFront>(exampleEstablishment)
@Get('{query}')
public async getEstablishmentBySiret(
@Path() query: string,
Expand Down
6 changes: 3 additions & 3 deletions apps/web/src/components/identification/TeeRegisterModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</template>
<script setup lang="ts">
import Translation from '@/utils/translation'
import { EstablishmentFront, CompanyDataStorageKey, CompanyDataType, LegalCategory, StructureSize } from '@/types'
import { EstablishmentFront, CompanyDataStorageKey, CompanyDataType } from '@/types'
import Breakpoint from '@/utils/breakpoints'
import CompanyDataStorage from '@/utils/storage/companyDataStorage'
import { onClickOutside } from '@vueuse/core'
Expand All @@ -70,8 +70,8 @@ const registerStep = computed<number>(() => {
})
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
}
Expand Down
38 changes: 36 additions & 2 deletions libs/backend-ddd/src/establishment/domain/establishmentFeatures.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
}
}
}
1 change: 1 addition & 0 deletions libs/backend-ddd/src/establishment/domain/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface EstablishmentDetails {
// https://www.insee.fr/fr/information/2560452
cityCode: string
}
workforceRange: string
}

export interface GeographicDetails {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ const parseEstablishment = (establishmentDocument: EstablishmentDocument): Estab
zipCode: rawEstablishment.adresseEtablissement.codePostalEtablissement,
cityLabel: rawEstablishment.adresseEtablissement.libelleCommuneEtablissement,
cityCode: rawEstablishment.adresseEtablissement.codeCommuneEtablissement
}
},
workforceRange: rawEstablishment.trancheEffectifsEtablissement
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface EstablishmentDocument {
siret: string
statutDiffusionEtablissement: string
dateCreationEtablissement: string
trancheEffectifsEtablissement: null
trancheEffectifsEtablissement: string
anneeEffectifsEtablissement: null
activitePrincipaleRegistreMetiersEtablissement: null
dateDernierTraitementEtablissement: string
Expand Down
3 changes: 2 additions & 1 deletion libs/backend-ddd/tests/establishment/testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const testEstablishment = {
zipCode: '94120',
cityLabel: 'FONTENAY-SOUS-BOIS',
cityCode: '94033'
}
},
workforceRange: '03'
}

const searchResult = {
Expand Down

0 comments on commit beafec5

Please sign in to comment.