From 5a6771ffec4685a1ddd632b8fcac958ba2ef92d6 Mon Sep 17 00:00:00 2001 From: Andrea Gueugnaut Date: Mon, 6 Jan 2025 10:41:54 +0100 Subject: [PATCH] feat: add OwnerKind type --- frontend/src/models/HousingFilters.tsx | 13 +++++++------ packages/models/src/HousingFiltersDTO.ts | 3 ++- packages/models/src/OwnerKind.ts | 11 +++++++++++ packages/models/src/index.ts | 1 + packages/schemas/src/housing-filters.ts | 5 ++++- packages/schemas/src/test/housing-filters.test.ts | 3 ++- 6 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 packages/models/src/OwnerKind.ts diff --git a/frontend/src/models/HousingFilters.tsx b/frontend/src/models/HousingFilters.tsx index 96ba4cd74..4d57836f5 100644 --- a/frontend/src/models/HousingFilters.tsx +++ b/frontend/src/models/HousingFilters.tsx @@ -12,7 +12,9 @@ import { LocalityKind, Occupancy, OCCUPANCY_VALUES, + OWNER_KIND_VALUES, OwnerAge, + OwnerKind, OwnershipKind, RoomCount, VacancyRate @@ -63,12 +65,11 @@ export const noCampaignOption: SelectOption = { }; export type NoCampaign = typeof noCampaignOption.value; -export const ownerKindOptions: SelectOption[] = [ - { value: 'Particulier', label: 'Particulier' }, - { value: 'Investisseur', label: 'Investisseur' }, - { value: 'SCI', label: 'SCI' }, - { value: 'Autre', label: 'Autres' } -]; +export const ownerKindOptions: SelectOption[] = + OWNER_KIND_VALUES.map((kind) => ({ + value: kind, + label: kind + })); export const campaignsCountOptions: SelectOption[] = [ { value: '0', label: 'Dans aucune campagne en cours' }, diff --git a/packages/models/src/HousingFiltersDTO.ts b/packages/models/src/HousingFiltersDTO.ts index f3347e402..b2f321d41 100644 --- a/packages/models/src/HousingFiltersDTO.ts +++ b/packages/models/src/HousingFiltersDTO.ts @@ -11,6 +11,7 @@ import { EnergyConsumption } from './EnergyConsumption'; import { HousingKind } from './HousingKind'; import { CampaignCount } from './CampaignCount'; import { RoomCount } from './RoomCount'; +import { OwnerKind } from './OwnerKind'; export interface HousingFiltersDTO { housingIds?: string[]; @@ -21,7 +22,7 @@ export interface HousingFiltersDTO { campaignsCounts?: CampaignCount[]; campaignIds?: Array; ownerIds?: string[]; - ownerKinds?: string[]; + ownerKinds?: OwnerKind[]; ownerAges?: OwnerAge[]; multiOwners?: boolean[]; beneficiaryCounts?: BeneficiaryCount[]; diff --git a/packages/models/src/OwnerKind.ts b/packages/models/src/OwnerKind.ts new file mode 100644 index 000000000..7121342d3 --- /dev/null +++ b/packages/models/src/OwnerKind.ts @@ -0,0 +1,11 @@ +export const OWNER_KIND_VALUES = [ + 'Particulier', + 'SCI, Copropriété, Autres personnes morales', + 'Promoteur, Investisseur privé', + 'Etat et collectivité territoriale', + 'Bailleur social, Aménageur, Investisseur public', + 'Autres', + 'Absence de propriétaire' +] as const; + +export type OwnerKind = (typeof OWNER_KIND_VALUES)[number]; diff --git a/packages/models/src/index.ts b/packages/models/src/index.ts index 2abbf2b17..4646ced06 100644 --- a/packages/models/src/index.ts +++ b/packages/models/src/index.ts @@ -33,6 +33,7 @@ export * from './NoteDTO'; export * from './Occupancy'; export * from './OwnerAge'; export * from './OwnerDTO'; +export * from './OwnerKind'; export * from './OwnershipKind'; export * from './Pagination'; export * from './ProspectDTO'; diff --git a/packages/schemas/src/housing-filters.ts b/packages/schemas/src/housing-filters.ts index f62bbb076..bd2e30627 100644 --- a/packages/schemas/src/housing-filters.ts +++ b/packages/schemas/src/housing-filters.ts @@ -12,6 +12,7 @@ import { LIVING_AREA_VALUES, OCCUPANCY_VALUES, OWNER_AGE_VALUES, + OWNER_KIND_VALUES, OWNERSHIP_KIND_VALUES, ROOM_COUNT_VALUES, VACANCY_RATE_VALUES @@ -44,7 +45,9 @@ export const housingFilters: ObjectSchema = object({ ownerIds: array() .transform(commaSeparatedString) .of(string().uuid().required()), - ownerKinds: array().transform(commaSeparatedString).of(string().required()), + ownerKinds: array() + .transform(commaSeparatedString) + .of(string().oneOf(OWNER_KIND_VALUES).required()), ownerAges: array() .transform(commaSeparatedString) .of(string().oneOf(OWNER_AGE_VALUES).required()), diff --git a/packages/schemas/src/test/housing-filters.test.ts b/packages/schemas/src/test/housing-filters.test.ts index d8fb4d144..d965c8fa8 100644 --- a/packages/schemas/src/test/housing-filters.test.ts +++ b/packages/schemas/src/test/housing-filters.test.ts @@ -12,6 +12,7 @@ import { LIVING_AREA_VALUES, OCCUPANCY_VALUES, OWNER_AGE_VALUES, + OWNER_KIND_VALUES, OWNERSHIP_KIND_VALUES, ROOM_COUNT_VALUES, VACANCY_RATE_VALUES @@ -28,7 +29,7 @@ describe('Housing filters', () => { campaignsCounts: fc.array(fc.constantFrom(...CAMPAIGN_COUNT_VALUES)), campaignIds: fc.array(fc.oneof(fc.constant(null), fc.uuid())), ownerIds: fc.array(fc.uuid()), - ownerKinds: fc.array(fc.string({ minLength: 1 })), + ownerKinds: fc.array(fc.constantFrom(...OWNER_KIND_VALUES)), ownerAges: fc.array(fc.constantFrom(...OWNER_AGE_VALUES)), multiOwners: fc.array(fc.boolean()), beneficiaryCounts: fc.array(fc.constantFrom(...BENEFIARY_COUNT_VALUES)),