diff --git a/scripts/init-db.js b/scripts/init-db.js index c53a05b398c91caf9f9aa4935c967696d0acd9b3..dfabeede8058fbf5346e2aa34b9057e1eb3184ab 100644 --- a/scripts/init-db.js +++ b/scripts/init-db.js @@ -110,6 +110,7 @@ const structuresSchema = mongoose.Schema({ deletedAt: Date, accountVerified: Boolean, lastUpdateMail: Date, + allowOrientation: Boolean, }); // compile schema to model diff --git a/src/migrations/scripts/1731662365980-add-allow-orientation.ts b/src/migrations/scripts/1731662365980-add-allow-orientation.ts new file mode 100644 index 0000000000000000000000000000000000000000..bebe2ad5ed488ad3b1b4b5692b45405e5d09a38e --- /dev/null +++ b/src/migrations/scripts/1731662365980-add-allow-orientation.ts @@ -0,0 +1,21 @@ +import { getDb } from '../migrations-utils/db'; + +export const up = async () => { + try { + const db = await getDb(); + await db.collection('structures').updateMany({}, { $set: { allowOrientation: true } }); + console.log(`Update done: 'allowOrientation' field added to all documents in 'structures' collection.`); + } catch (error) { + console.error(`Error while adding 'allowOrientation' field:`, error); + } +}; + +export const down = async () => { + try { + const db = await getDb(); + await db.collection('structures').updateMany({}, { $unset: { allowOrientation: '' } }); + console.log(`Downgrade done: 'allowOrientation' field removed from all documents in 'structures' collection.`); + } catch (error) { + console.error(`Error while removing 'allowOrientation' field:`, error); + } +}; diff --git a/src/structures/dto/structure.dto.ts b/src/structures/dto/structure.dto.ts index 8f2b9f18a341fe8e12dff42d53a74a3a844f98e7..90986acfb3575e87873978a362a1b4e952bcdf49 100644 --- a/src/structures/dto/structure.dto.ts +++ b/src/structures/dto/structure.dto.ts @@ -69,4 +69,8 @@ export class StructureDto { personalOffers: PersonalOfferDocument[]; lastUpdateMail: Date; + + @ApiProperty({ required: true }) + @IsNotEmpty() + allowOrientation: Boolean; } diff --git a/src/structures/schemas/structure.schema.ts b/src/structures/schemas/structure.schema.ts index f91eeb6d924aa33913ad0ca37499baf69e22c23b..7f1417b1ff8a5fdf21974d0844c7374554536553 100644 --- a/src/structures/schemas/structure.schema.ts +++ b/src/structures/schemas/structure.schema.ts @@ -45,6 +45,7 @@ export class Structure { this.hasUserWithAppointmentDN = data.hasUserWithAppointmentDN; this.permalink = data.permalink; this.lastUpdateMail = data.lastUpdateMail; + this.allowOrientation = data.allowOrientation; } @Prop() @@ -162,6 +163,10 @@ export class Structure { @Prop() comment: string; + + @Prop() + @IsNotEmpty() + allowOrientation: boolean; } export const StructureSchema = SchemaFactory.createForClass(Structure); diff --git a/src/structures/services/structures-export.service.spec.ts b/src/structures/services/structures-export.service.spec.ts index 793fbacb04114afdae064a2e6de2614a373f1d43..7086ce3bf12a9a2a300235110e4a81290231020b 100644 --- a/src/structures/services/structures-export.service.spec.ts +++ b/src/structures/services/structures-export.service.spec.ts @@ -133,7 +133,8 @@ function createMockedStructure(overrides: Partial<StructureDocument> = {}) { dataShareConsentDate: new Date('2021-01-24T09:59:26.000Z'), createdAt: new Date('2021-05-06T09:42:38.000Z'), updatedAt: new Date('2023-03-01T09:42:50.000Z'), - lastUpdateMailSentAt: new Date('2021-05-06T09:42:38.000Z'), + lastUpdateMail: new Date('2021-05-06T09:42:38.000Z'), + allowOrientation: true, __v: 0, }; diff --git a/src/structures/services/structures-import.service.ts b/src/structures/services/structures-import.service.ts index 386a9eb6bad5fa23f72a8b651980cde7eb7ec561..a870925feaa918242b6e645ad457680056907d19 100644 --- a/src/structures/services/structures-import.service.ts +++ b/src/structures/services/structures-import.service.ts @@ -172,6 +172,7 @@ export class StructuresImportService { personalOffers: [], otherDescription: null, linkedin: null, + allowOrientation: true, }); return formatted; diff --git a/src/structures/services/structures.service.spec.ts b/src/structures/services/structures.service.spec.ts index 1f39c3a75c9beea7e4c52656b542837cb33f866e..29159ab4fce715411f5400149375dbd720b058ce 100644 --- a/src/structures/services/structures.service.spec.ts +++ b/src/structures/services/structures.service.spec.ts @@ -158,6 +158,7 @@ const mockStructuresSearchService = { nbScanners: 1, otherDescription: null, personalOffers: [], + allowOrientation: true, }, ]), dropIndex: jest.fn(), @@ -332,6 +333,7 @@ describe('StructuresService', () => { categories: { onlineProcedures: ['caf'], }, + allowOrientation: true, }, ]); diff --git a/test/mock/data/gouvStructures.mock.data.ts b/test/mock/data/gouvStructures.mock.data.ts index 01149dea169512420e70f1d734d77bea314a387f..b853096f91339bc9c9fe0f090a37f2306c9ae5ac 100644 --- a/test/mock/data/gouvStructures.mock.data.ts +++ b/test/mock/data/gouvStructures.mock.data.ts @@ -147,5 +147,6 @@ export const mockGouvStructureToResinFormat = new Structure({ twitter: null, otherDescription: null, linkedin: null, + allowOrientation: true, updatedAt: new Date('2023-06-23'), }); diff --git a/test/mock/data/structure.mock.dto.ts b/test/mock/data/structure.mock.dto.ts index 8f5f2bcb82a7410600b0622879d052a25852108b..19609bf5b1bf61ff59b64772eda8665f19b31be3 100644 --- a/test/mock/data/structure.mock.dto.ts +++ b/test/mock/data/structure.mock.dto.ts @@ -36,4 +36,5 @@ export const structureDtoMock: StructureDto = { coord: [], dataShareConsentDate: new Date(), personalOffers: [], + allowOrientation: true, }; diff --git a/test/mock/data/structures.mock.data.ts b/test/mock/data/structures.mock.data.ts index f0fb70ecdb245ca127bb9e201a0bbc5574591026..3bf950c3e7ca3ebab294ab7200607b6776c38fa3 100644 --- a/test/mock/data/structures.mock.data.ts +++ b/test/mock/data/structures.mock.data.ts @@ -70,6 +70,7 @@ export const structuresDocumentDataMock: StructureDocument[] = [ createdAt: '2021-05-06T09:42:38.000Z', updatedAt: '2021-05-06T09:42:50.000Z', lastUpdateMail: '2020-11-16T09:30:00.000Z', + allowOrientation: true, __v: 0, save: jest.fn(), } as any, @@ -133,6 +134,7 @@ export const structuresDocumentDataMock: StructureDocument[] = [ freenessCondition: null, accountVerified: true, personalOffers: ['1234ba0e2ab5775cfc01ed3e'], + allowOrientation: true, createdAt: '2021-05-06T09:42:38.000Z', updatedAt: '2021-05-06T09:42:50.000Z', __v: 0, @@ -210,6 +212,7 @@ export const structureMockDto: StructureDto = { deletedAt: new Date(), lastUpdateMail: new Date(), dataShareConsentDate: new Date(), + allowOrientation: true, }; export const mockStructureDocument = { @@ -314,6 +317,7 @@ export const mockStructureDocument = { deletedAt: null, dataShareConsentDate: null, personalOffers: null, + allowOrientation: true, } as unknown as StructureDocument; export const mockStructure: Structure = { @@ -421,6 +425,7 @@ export const mockStructure: Structure = { lastUpdateMail: new Date('2020-11-16T09:30:00.000Z'), permalink: 'a', comment: 'nouveau', + allowOrientation: true, }; export const mockDeletedStructure: Structure = { @@ -530,4 +535,5 @@ export const mockDeletedStructure: Structure = { lastUpdateMail: new Date('2020-11-16T09:30:00.000Z'), permalink: 'latelier-numerique', comment: 'ancienne structure', + allowOrientation: true, }; diff --git a/test/mock/services/structures.mock.service.ts b/test/mock/services/structures.mock.service.ts index 0acbf448bba33b9ff449a9c312095a196ec5c401..21d5152fd9f1baf902ac1bda6edc332e396aca96 100644 --- a/test/mock/services/structures.mock.service.ts +++ b/test/mock/services/structures.mock.service.ts @@ -104,6 +104,7 @@ export class StructuresServiceMock { freeWorkShop: 'Payant', freenessCondition: null, accountVerified: true, + allowOrientation: true, createdAt: new Date('2021-05-06T09:42:38.000Z'), updatedAt: new Date('2021-05-06T09:42:38.000Z'), __v: 0, @@ -253,6 +254,7 @@ export class StructuresServiceMock { nbScanners: 1, otherDescription: null, personalOffers: [], + allowOrientation: true, }; } @@ -328,6 +330,7 @@ export class StructuresServiceMock { nbScanners: 1, otherDescription: null, personalOffers: [], + allowOrientation: true, createdAt: new Date('2020-11-16T09:30:00.000Z'), updatedAt: new Date('2020-11-16T09:30:00.000Z'), deletedAt: new Date('2020-11-16T09:30:00.000Z'), @@ -481,6 +484,7 @@ export class StructuresServiceMock { nbScanners: 1, otherDescription: null, personalOffers: [], + allowOrientation: true, }; } @@ -586,6 +590,7 @@ export class StructuresServiceMock { freeWorkShop: 'Payant', freenessCondition: null, accountVerified: true, + allowOrientation: true, createdAt: new Date('2021-05-06T09:42:38.000Z'), updatedAt: new Date('2021-05-06T09:42:50.000Z'), __v: 0, @@ -687,6 +692,7 @@ export class StructuresServiceMock { freeWorkShop: 'Payant', freenessCondition: null, accountVerified: true, + allowOrientation: true, createdAt: new Date('2021-05-06T09:42:38.000Z'), updatedAt: new Date('2021-05-06T09:42:50.000Z'), __v: 0, @@ -793,6 +799,7 @@ export class StructuresServiceMock { freeWorkShop: 'Payant', freenessCondition: null, accountVerified: true, + allowOrientation: true, createdAt: new Date('2021-05-06T09:42:38.000Z'), updatedAt: new Date('2021-05-06T09:42:50.000Z'), __v: 0, @@ -895,6 +902,7 @@ export class StructuresServiceMock { freeWorkShop: 'Payant', freenessCondition: null, accountVerified: true, + allowOrientation: true, createdAt: new Date('2021-05-06T09:42:38.000Z'), updatedAt: new Date('2021-05-06T09:42:50.000Z'), __v: 0, @@ -1003,6 +1011,7 @@ export class StructuresServiceMock { freenessCondition: null, accountVerified: true, personalOffers: [], + allowOrientation: true, dataShareConsentDate: '2022-03-01T09:00:00.000Z', createdAt: new Date('2021-05-06T09:42:38.000Z'), updatedAt: new Date('2021-05-06T09:42:50.000Z'), @@ -1106,6 +1115,7 @@ export class StructuresServiceMock { freenessCondition: null, accountVerified: true, personalOffers: [], + allowOrientation: true, dataShareConsentDate: '2022-03-01T09:00:00.000Z', createdAt: new Date('2021-05-06T09:42:38.000Z'), updatedAt: new Date('2021-05-06T09:42:50.000Z'), @@ -1174,6 +1184,7 @@ export class StructuresServiceMock { freeWorkShop: 'Payant', freenessCondition: null, accountVerified: true, + allowOrientation: true, createdAt: new Date('2021-05-06T09:42:38.000Z'), updatedAt: new Date('2021-05-06T09:42:50.000Z'), __v: 0, @@ -1286,6 +1297,7 @@ export class StructuresServiceMock { freenessCondition: null, accountVerified: true, personalOffers: [personalOfferDocument], + allowOrientation: true, createdAt: new Date('2021-05-06T09:42:38.000Z'), updatedAt: new Date('2021-05-06T09:42:50.000Z'), deletedAt: null, @@ -1471,6 +1483,7 @@ export const mockResinStructures: Array<Structure> = [ lastUpdateMail: new Date('2021-05-06T09:42:38.000Z'), permalink: 'a', comment: 'petit commentaire', + allowOrientation: true, }, { contactMail: 'matchin@email.com', @@ -1577,6 +1590,7 @@ export const mockResinStructures: Array<Structure> = [ lastUpdateMail: new Date('2021-05-06T09:42:38.000Z'), permalink: 'a-1', comment: 'petit commentaire', + allowOrientation: true, }, { contactMail: 'nomatch@email.com', @@ -1683,5 +1697,6 @@ export const mockResinStructures: Array<Structure> = [ lastUpdateMail: new Date('2021-05-06T09:42:38.000Z'), permalink: 'a-2', comment: 'petit commentaire', + allowOrientation: true, }, ];