diff --git a/.vscode/settings.json b/.vscode/settings.json index fb075504d4ce8c29dccd12fda2fdfb98b34ba020..76c96065f1ee5a0dbefd0f5e49154f68053ce0f9 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -51,6 +51,7 @@ "espace", "friday", "grandlyon", + "Gratuit", "healthcheck", "housenumber", "insee", @@ -63,6 +64,7 @@ "Numerique", "numero", "orientator", + "Payant", "permanences", "photonban", "rdvs", diff --git a/src/migrations/scripts/1730281269936-freeness-condition.ts b/src/migrations/scripts/1730281269936-freeness-condition.ts new file mode 100644 index 0000000000000000000000000000000000000000..34351db5d31ab8bd31b257c97f91d22c2bf01c78 --- /dev/null +++ b/src/migrations/scripts/1730281269936-freeness-condition.ts @@ -0,0 +1,83 @@ +import { Db } from 'mongodb'; +import { getDb } from '../migrations-utils/db'; + +export const up = async () => { + try { + const db: Db = await getDb(); + + // Update labels of freeness + const cursor = db.collection('categories').find({ id: 'freeWorkShop' }); + let category; + while ((category = await cursor.next())) { + const modules = [ + { + id: 'yes', + name: 'Gratuit', + }, + { + id: 'underCondition', + name: 'Gratuit sous conditions', + }, + { + id: 'no', + name: 'Payant', + }, + ]; + + await db.collection('categories').updateOne( + { _id: category._id }, + { + $set: { modules: modules }, + } + ); + } + + // Adds the field for the condition of freeness + await db.collection('structures').updateMany({}, { $set: { 'categories.freenessCondition': null } }); + + console.log( + `Update done: freeWorkShops labels changed and 'freenessCondition' field added to all documents in 'structures' collection.` + ); + } catch (error) { + console.error('Error while changing freeWorkShops labels:', error); + } +}; + +export const down = async () => { + try { + const db: Db = await getDb(); + + const cursor = db.collection('categories').find({ id: 'freeWorkShop' }); + let category; + while ((category = await cursor.next())) { + const modules = [ + { + id: 'yes', + name: 'Accompagnements gratuits', + }, + { + id: 'underCondition', + name: 'Accompagnements gratuits sous conditions', + }, + { + id: 'no', + name: 'Accompagnements payants', + }, + ]; + + await db.collection('categories').updateOne( + { _id: category._id }, + { + $set: { modules: modules }, + } + ); + } + + // Removes the field for the condition of freeness + await db.collection('structures').updateMany({}, { $unset: { 'categories.freenessCondition': '' } }); + + console.log(`Downgrade done: 'freenessCondition' field removed from all documents in 'structures' collection.`); + } catch (error) { + console.error('Error reverting freeWorkShop ids:', error); + } +}; diff --git a/src/structures/dto/structure.dto.ts b/src/structures/dto/structure.dto.ts index acf9c7761dc7b67d8db04be5b948bbdc6e22ca8c..8f2b9f18a341fe8e12dff42d53a74a3a844f98e7 100644 --- a/src/structures/dto/structure.dto.ts +++ b/src/structures/dto/structure.dto.ts @@ -45,6 +45,7 @@ export class StructureDto { categories: any; freeWorkShop: string; + freenessCondition: string; @ApiProperty({ required: true }) @IsNotEmpty() diff --git a/src/structures/interfaces/structure-formatted.interface.ts b/src/structures/interfaces/structure-formatted.interface.ts index 94bb4e31dc00f6f0efbb284c67865f38b7901b60..72949c9f7803a84698b6a6d38834ed29b9f70d26 100644 --- a/src/structures/interfaces/structure-formatted.interface.ts +++ b/src/structures/interfaces/structure-formatted.interface.ts @@ -24,7 +24,6 @@ export interface StructureFormatted extends Partial<Structure>, Partial<Document twitter?: string; instagram?: string; linkedin?: string; - atelier_gratuit?: string; nb_imprimantes?: number; nb_ordinateurs?: number; nb_scanners?: number; diff --git a/src/structures/schemas/structure.schema.ts b/src/structures/schemas/structure.schema.ts index 7c11fbbbffeb18d4cfc44c5582e740d3f3ba90ae..f91eeb6d924aa33913ad0ca37499baf69e22c23b 100644 --- a/src/structures/schemas/structure.schema.ts +++ b/src/structures/schemas/structure.schema.ts @@ -30,6 +30,7 @@ export class Structure { this.categories = data.categories; this.exceptionalClosures = data.exceptionalClosures; this.freeWorkShop = data.freeWorkShop; + this.freenessCondition = data.freenessCondition; this.nbPrinters = data.nbPrinters; this.nbComputers = data.nbComputers; this.nbScanners = data.nbScanners; @@ -97,9 +98,12 @@ export class Structure { categories: StructureCategories; @Prop() - /** 'Oui' | 'Oui sous condition' | 'Non' */ + /** 'Gratuit' | 'Gratuit sous conditions' | 'Payant' */ freeWorkShop: string; + @Prop() + freenessCondition: string; + @Prop() nbComputers: number; diff --git a/src/structures/services/structures-export.service.spec.ts b/src/structures/services/structures-export.service.spec.ts index f2c086938967ac1e772669009633690240460c45..793fbacb04114afdae064a2e6de2614a373f1d43 100644 --- a/src/structures/services/structures-export.service.spec.ts +++ b/src/structures/services/structures-export.service.spec.ts @@ -126,7 +126,8 @@ function createMockedStructure(overrides: Partial<StructureDocument> = {}) { nbComputers: 1, nbPrinters: 1, nbScanners: 1, - freeWorkShop: 'Oui', + freeWorkShop: 'Gratuit', + freenessCondition: null, accountVerified: true, personalOffers: [], dataShareConsentDate: new Date('2021-01-24T09:59:26.000Z'), diff --git a/src/structures/services/structures-export.service.ts b/src/structures/services/structures-export.service.ts index 43b0c3ad945a0cc1094dcdc1cf021032d9f8984f..cf207c850418664a6e177b7dc336a2d0cc262e43 100644 --- a/src/structures/services/structures-export.service.ts +++ b/src/structures/services/structures-export.service.ts @@ -67,7 +67,8 @@ export class StructuresExportService { ...(structure.twitter && { twitter: structure.twitter }), ...(structure.instagram && { instagram: structure.instagram }), ...(structure.linkedin && { linkedin: structure.linkedin }), - ...(structure.freeWorkShop && { atelier_gratuit: structure.freeWorkShop }), + ...(structure.freeWorkShop && { freeWorkShop: structure.freeWorkShop }), + ...(structure.freenessCondition && { freenessCondition: structure.freenessCondition }), ...(structure.nbPrinters && { nb_imprimantes: structure.nbPrinters }), ...(structure.nbComputers && { nb_ordinateurs: structure.nbComputers }), ...(structure.nbScanners && { nb_scanners: structure.nbScanners }), diff --git a/src/structures/services/structures-import.service.ts b/src/structures/services/structures-import.service.ts index f995d31bd518b01bc791ba864c7736557d11a11a..386a9eb6bad5fa23f72a8b651980cde7eb7ec561 100644 --- a/src/structures/services/structures-import.service.ts +++ b/src/structures/services/structures-import.service.ts @@ -160,7 +160,8 @@ export class StructuresImportService { nbComputers: 0, nbPrinters: 0, nbScanners: 0, - freeWorkShop: 'Non', + freeWorkShop: 'Payant', + freenessCondition: null, structureType: null, website: structure.site_web ?? null, dataShareConsentDate: null, diff --git a/src/structures/services/structures.service.spec.ts b/src/structures/services/structures.service.spec.ts index c76db4e410d5c0608ef7ffda84d2e542999c2a0a..1f39c3a75c9beea7e4c52656b542837cb33f866e 100644 --- a/src/structures/services/structures.service.spec.ts +++ b/src/structures/services/structures.service.spec.ts @@ -54,7 +54,8 @@ const mockStructuresSearchService = { _id: '6903ba0e2ab5775cfc01ed4d', structureId: '6903ba0e2ab5775cfc01ed4d', structureType: null, - freeWorkShop: 'Non', + freeWorkShop: 'Payant', + freenessCondition: null, createdAt: '2020-11-16T09:30:00.000Z', updatedAt: '2021-04-12T08:48:00.000Z', structureName: "L'Atelier Numérique", @@ -283,7 +284,8 @@ describe('StructuresService', () => { structureName: "L'Atelier Numérique", structureId: '6903ba0e2ab5775cfc01ed4d', structureType: null, - freeWorkShop: 'Non', + freeWorkShop: 'Payant', + freenessCondition: null, createdAt: '2020-11-16T09:30:00.000Z', updatedAt: '2021-04-12T08:48:00.000Z', description: diff --git a/test/mock/data/gouvStructures.mock.data.ts b/test/mock/data/gouvStructures.mock.data.ts index c83cf92e2a47e4926fe90845aa3252e315c1fb15..01149dea169512420e70f1d734d77bea314a387f 100644 --- a/test/mock/data/gouvStructures.mock.data.ts +++ b/test/mock/data/gouvStructures.mock.data.ts @@ -80,7 +80,8 @@ export const mockGouvStructureToResinFormat = new Structure({ ctm: [], genre: [], }, - freeWorkShop: 'Non', + freeWorkShop: 'Payant', + freenessCondition: null, nbComputers: 0, nbPrinters: 0, nbScanners: 0, diff --git a/test/mock/data/structure.mock.dto.ts b/test/mock/data/structure.mock.dto.ts index 8ec6e3391971dcaf866d8da0ac1b94b2ea5cdc85..8f5f2bcb82a7410600b0622879d052a25852108b 100644 --- a/test/mock/data/structure.mock.dto.ts +++ b/test/mock/data/structure.mock.dto.ts @@ -19,6 +19,7 @@ export const structureDtoMock: StructureDto = { pmrAccess: false, categories: '', freeWorkShop: '', + freenessCondition: null, nbComputers: 0, nbPrinters: 0, nbScanners: 0, diff --git a/test/mock/data/structures.mock.data.ts b/test/mock/data/structures.mock.data.ts index 2d82c86d1be07d6ef7261aaaa7878cd297e5b672..f0fb70ecdb245ca127bb9e201a0bbc5574591026 100644 --- a/test/mock/data/structures.mock.data.ts +++ b/test/mock/data/structures.mock.data.ts @@ -63,7 +63,8 @@ export const structuresDocumentDataMock: StructureDocument[] = [ nbComputers: 1, nbPrinters: 1, nbScanners: 1, - freeWorkShop: 'Non', + freeWorkShop: 'Payant', + freenessCondition: null, accountVerified: true, personalOffers: [], createdAt: '2021-05-06T09:42:38.000Z', @@ -128,7 +129,8 @@ export const structuresDocumentDataMock: StructureDocument[] = [ nbComputers: 1, nbPrinters: 1, nbScanners: 1, - freeWorkShop: 'Non', + freeWorkShop: 'Payant', + freenessCondition: null, accountVerified: true, personalOffers: ['1234ba0e2ab5775cfc01ed3e'], createdAt: '2021-05-06T09:42:38.000Z', @@ -198,7 +200,8 @@ export const structureMockDto: StructureDto = { nbComputers: 1, nbPrinters: 1, nbScanners: 1, - freeWorkShop: 'Non', + freeWorkShop: 'Payant', + freenessCondition: null, accountVerified: true, personalOffers: [], createdAt: new Date(), @@ -302,7 +305,8 @@ export const mockStructureDocument = { nbComputers: 1, nbPrinters: 1, nbScanners: 1, - freeWorkShop: 'Non', + freeWorkShop: 'Payant', + freenessCondition: null, accountVerified: true, createdAt: new Date('2021-05-06T09:42:38.000Z'), updatedAt: new Date('2021-05-06T09:42:38.000Z'), @@ -410,7 +414,8 @@ export const mockStructure: Structure = { nbComputers: 1, nbPrinters: 1, nbScanners: 1, - freeWorkShop: 'Non', + freeWorkShop: 'Payant', + freenessCondition: null, accountVerified: true, categoriesWithPersonalOffers: {}, lastUpdateMail: new Date('2020-11-16T09:30:00.000Z'), @@ -490,7 +495,8 @@ export const mockDeletedStructure: Structure = { handicaps: ['physicalDisability'], genre: ['uniquementFemmes'], }, - freeWorkShop: 'Non', + freeWorkShop: 'Payant', + freenessCondition: null, structureName: "L'Atelier Numérique", description: diff --git a/test/mock/services/structures-export.mock.service.ts b/test/mock/services/structures-export.mock.service.ts index 29fb852807860a68f9244d51ac300bc5d8bbbc90..dd51c37c52d9b9b347a879b55c38104e71983d7b 100644 --- a/test/mock/services/structures-export.mock.service.ts +++ b/test/mock/services/structures-export.mock.service.ts @@ -28,7 +28,7 @@ export const mockFormattedStructures: Array<StructureFormatted> = [ publics_accueillis: 'Jeunes (16-26 ans);Seniors (+ 65 ans);Uniquement femmes', site_web: 'http://lesonduclic.fr/site1/', telephone: '06 60 60 60 60', - atelier_gratuit: 'Oui', + freeWorkShop: 'Gratuit', nb_imprimantes: 1, nb_ordinateurs: 1, nb_scanners: 1, diff --git a/test/mock/services/structures.mock.service.ts b/test/mock/services/structures.mock.service.ts index 5f0c7a1f19a2173c520100583b5db8c8115159a8..0acbf448bba33b9ff449a9c312095a196ec5c401 100644 --- a/test/mock/services/structures.mock.service.ts +++ b/test/mock/services/structures.mock.service.ts @@ -1,7 +1,6 @@ import { HttpException, HttpStatus } from '@nestjs/common'; import { Types } from 'mongoose'; import { PersonalOfferDocument } from '../../../src/personal-offers/schemas/personal-offer.schema'; -import { CNFSStructure } from '../../../src/structures/interfaces/cnfs-structure.interface'; import { PhotonPoints } from '../../../src/structures/interfaces/photon-response.interface'; import { Structure, StructureDocument } from '../../../src/structures/schemas/structure.schema'; @@ -102,7 +101,8 @@ export class StructuresServiceMock { nbComputers: 1, nbPrinters: 1, nbScanners: 1, - freeWorkShop: 'Non', + freeWorkShop: 'Payant', + freenessCondition: null, accountVerified: true, createdAt: new Date('2021-05-06T09:42:38.000Z'), updatedAt: new Date('2021-05-06T09:42:38.000Z'), @@ -152,7 +152,8 @@ export class StructuresServiceMock { handicaps: ['physicalDisability'], genre: ['uniquementFemmes'], }, - freeWorkShop: 'Non', + freeWorkShop: 'Payant', + freenessCondition: null, createdAt: new Date('2020-11-16T09:30:00.000Z'), updatedAt: new Date('2020-11-16T09:30:00.000Z'), structureName: "L'Atelier Numérique", @@ -297,7 +298,8 @@ export class StructuresServiceMock { handicaps: ['physicalDisability'], genre: ['uniquementFemmes'], }, - freeWorkShop: 'Non', + freeWorkShop: 'Payant', + freenessCondition: null, structureName: "L'Atelier Numérique", description: @@ -377,7 +379,8 @@ export class StructuresServiceMock { handicaps: ['physicalDisability'], genre: ['uniquementFemmes'], }, - freeWorkShop: 'Non', + freeWorkShop: 'Payant', + freenessCondition: null, createdAt: new Date('2020-11-16T09:30:00.000Z'), updatedAt: new Date('2020-11-16T09:30:00.000Z'), structureName: "L'Atelier Numérique", @@ -580,7 +583,8 @@ export class StructuresServiceMock { nbComputers: 1, nbPrinters: 1, nbScanners: 1, - freeWorkShop: 'Non', + freeWorkShop: 'Payant', + freenessCondition: null, accountVerified: true, createdAt: new Date('2021-05-06T09:42:38.000Z'), updatedAt: new Date('2021-05-06T09:42:50.000Z'), @@ -680,7 +684,8 @@ export class StructuresServiceMock { nbComputers: 1, nbPrinters: 1, nbScanners: 1, - freeWorkShop: 'Non', + freeWorkShop: 'Payant', + freenessCondition: null, accountVerified: true, createdAt: new Date('2021-05-06T09:42:38.000Z'), updatedAt: new Date('2021-05-06T09:42:50.000Z'), @@ -785,7 +790,8 @@ export class StructuresServiceMock { nbComputers: 1, nbPrinters: 1, nbScanners: 1, - freeWorkShop: 'Non', + freeWorkShop: 'Payant', + freenessCondition: null, accountVerified: true, createdAt: new Date('2021-05-06T09:42:38.000Z'), updatedAt: new Date('2021-05-06T09:42:50.000Z'), @@ -886,7 +892,8 @@ export class StructuresServiceMock { nbComputers: 1, nbPrinters: 1, nbScanners: 1, - freeWorkShop: 'Non', + freeWorkShop: 'Payant', + freenessCondition: null, accountVerified: true, createdAt: new Date('2021-05-06T09:42:38.000Z'), updatedAt: new Date('2021-05-06T09:42:50.000Z'), @@ -992,7 +999,8 @@ export class StructuresServiceMock { nbComputers: 1, nbPrinters: 1, nbScanners: 1, - freeWorkShop: 'Non', + freeWorkShop: 'Payant', + freenessCondition: null, accountVerified: true, personalOffers: [], dataShareConsentDate: '2022-03-01T09:00:00.000Z', @@ -1094,7 +1102,8 @@ export class StructuresServiceMock { nbComputers: 1, nbPrinters: 1, nbScanners: 1, - freeWorkShop: 'Non', + freeWorkShop: 'Payant', + freenessCondition: null, accountVerified: true, personalOffers: [], dataShareConsentDate: '2022-03-01T09:00:00.000Z', @@ -1162,7 +1171,8 @@ export class StructuresServiceMock { nbComputers: 1, nbPrinters: 1, nbScanners: 1, - freeWorkShop: 'Non', + freeWorkShop: 'Payant', + freenessCondition: null, accountVerified: true, createdAt: new Date('2021-05-06T09:42:38.000Z'), updatedAt: new Date('2021-05-06T09:42:50.000Z'), @@ -1272,7 +1282,8 @@ export class StructuresServiceMock { nbComputers: 1, nbPrinters: 1, nbScanners: 1, - freeWorkShop: 'Non', + freeWorkShop: 'Payant', + freenessCondition: null, accountVerified: true, personalOffers: [personalOfferDocument], createdAt: new Date('2021-05-06T09:42:38.000Z'), @@ -1448,7 +1459,8 @@ export const mockResinStructures: Array<Structure> = [ nbComputers: 1, nbPrinters: 1, nbScanners: 1, - freeWorkShop: 'Non', + freeWorkShop: 'Payant', + freenessCondition: null, accountVerified: true, createdAt: new Date('2021-05-06T09:42:38.000Z'), updatedAt: new Date('2021-05-06T09:42:50.000Z'), @@ -1553,7 +1565,8 @@ export const mockResinStructures: Array<Structure> = [ nbComputers: 1, nbPrinters: 1, nbScanners: 1, - freeWorkShop: 'Non', + freeWorkShop: 'Payant', + freenessCondition: null, accountVerified: true, personalOffers: [], createdAt: new Date('2021-05-06T09:42:38.000Z'), @@ -1658,7 +1671,8 @@ export const mockResinStructures: Array<Structure> = [ nbComputers: 1, nbPrinters: 1, nbScanners: 1, - freeWorkShop: 'Non', + freeWorkShop: 'Payant', + freenessCondition: null, accountVerified: true, personalOffers: [], createdAt: new Date('2021-05-06T09:42:38.000Z'),