From 5d6547a1847641517b931736fade52743dc59b4a Mon Sep 17 00:00:00 2001 From: Sylvain Briat Date: Wed, 17 Jan 2024 11:59:51 +0100 Subject: [PATCH 1/4] fix bad validation : wrong cascade update after ad status change --- .../application/commands/validate-ad/validate-ad.service.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/ad/core/application/commands/validate-ad/validate-ad.service.ts b/src/modules/ad/core/application/commands/validate-ad/validate-ad.service.ts index 4d99750..c4ed353 100644 --- a/src/modules/ad/core/application/commands/validate-ad/validate-ad.service.ts +++ b/src/modules/ad/core/application/commands/validate-ad/validate-ad.service.ts @@ -15,8 +15,8 @@ export class ValidateAdService implements ICommandHandler { async execute(command: ValidateAdCommand): Promise { const ad: AdEntity = await this.repository.findOneById(command.id, { - waypoints: true, - schedule: true, + waypoints: false, + schedule: false, }); ad.valid(); await this.repository.update(ad.id, ad); From 2009355b18b87382b9b2fd6f6e2203e57377e56d Mon Sep 17 00:00:00 2001 From: Sylvain Briat Date: Wed, 17 Jan 2024 12:00:00 +0100 Subject: [PATCH 2/4] 2.4.4 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7a249f7..b1404fe 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@mobicoop/ad", - "version": "2.4.3", + "version": "2.4.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@mobicoop/ad", - "version": "2.4.3", + "version": "2.4.4", "license": "AGPL", "dependencies": { "@grpc/grpc-js": "^1.9.14", diff --git a/package.json b/package.json index 9583ef2..b31aae2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@mobicoop/ad", - "version": "2.4.3", + "version": "2.4.4", "description": "Mobicoop V3 Ad", "author": "sbriat", "private": true, From b039dbb3bdd042c12d9ddcf995ba139b3211364d Mon Sep 17 00:00:00 2001 From: Sylvain Briat Date: Thu, 18 Jan 2024 15:53:48 +0100 Subject: [PATCH 3/4] fix ad validation : remove schedule and waypoints duplication --- src/modules/ad/ad.mapper.ts | 74 ++++++++++--------- .../ad/infrastructure/ad.repository.ts | 20 +++-- src/modules/ad/tests/unit/ad.mapper.spec.ts | 6 +- 3 files changed, 53 insertions(+), 47 deletions(-) diff --git a/src/modules/ad/ad.mapper.ts b/src/modules/ad/ad.mapper.ts index cf036d9..5c7c014 100644 --- a/src/modules/ad/ad.mapper.ts +++ b/src/modules/ad/ad.mapper.ts @@ -43,43 +43,45 @@ export class AdMapper frequency: copy.frequency, fromDate: new Date(copy.fromDate), toDate: new Date(copy.toDate), - schedule: { - create: copy.schedule.map((scheduleItem: ScheduleItemProps) => ({ - uuid: v4(), - day: scheduleItem.day as number, - time: new Date( - 1970, - 0, - 1, - parseInt(scheduleItem.time.split(':')[0]), - parseInt(scheduleItem.time.split(':')[1]), - ), - margin: scheduleItem.margin as number, - createdAt: now, - updatedAt: now, - })), - }, + schedule: copy.schedule + ? { + create: copy.schedule.map((scheduleItem: ScheduleItemProps) => ({ + uuid: v4(), + day: scheduleItem.day as number, + time: new Date( + 1970, + 0, + 1, + parseInt(scheduleItem.time.split(':')[0]), + parseInt(scheduleItem.time.split(':')[1]), + ), + margin: scheduleItem.margin as number, + createdAt: now, + updatedAt: now, + })), + } + : undefined, seatsProposed: copy.seatsProposed as number, seatsRequested: copy.seatsRequested as number, strict: copy.strict as boolean, - waypoints: { - create: copy.waypoints.map((waypoint: WaypointProps) => ({ - uuid: v4(), - position: waypoint.position, - name: waypoint.address.name, - houseNumber: waypoint.address.houseNumber, - street: waypoint.address.street, - locality: waypoint.address.locality, - postalCode: waypoint.address.postalCode, - country: waypoint.address.country, - lon: waypoint.address.coordinates.lon, - lat: waypoint.address.coordinates.lat, - createdAt: now, - updatedAt: now, - })), - }, - createdAt: copy.createdAt, - updatedAt: copy.updatedAt, + waypoints: copy.waypoints + ? { + create: copy.waypoints.map((waypoint: WaypointProps) => ({ + uuid: v4(), + position: waypoint.position, + name: waypoint.address.name, + houseNumber: waypoint.address.houseNumber, + street: waypoint.address.street, + locality: waypoint.address.locality, + postalCode: waypoint.address.postalCode, + country: waypoint.address.country, + lon: waypoint.address.coordinates.lon, + lat: waypoint.address.coordinates.lat, + createdAt: now, + updatedAt: now, + })), + } + : undefined, }; return record; }; @@ -97,7 +99,7 @@ export class AdMapper frequency: record.frequency as Frequency, fromDate: record.fromDate.toISOString().split('T')[0], toDate: record.toDate.toISOString().split('T')[0], - schedule: record.schedule.map((scheduleItem: ScheduleItemModel) => ({ + schedule: record.schedule?.map((scheduleItem: ScheduleItemModel) => ({ day: scheduleItem.day, time: `${scheduleItem.time .getUTCHours() @@ -111,7 +113,7 @@ export class AdMapper seatsProposed: record.seatsProposed, seatsRequested: record.seatsRequested, strict: record.strict, - waypoints: record.waypoints.map((waypoint: WaypointModel) => ({ + waypoints: record.waypoints?.map((waypoint: WaypointModel) => ({ position: waypoint.position, address: { name: waypoint.name, diff --git a/src/modules/ad/infrastructure/ad.repository.ts b/src/modules/ad/infrastructure/ad.repository.ts index 7c3f380..673a036 100644 --- a/src/modules/ad/infrastructure/ad.repository.ts +++ b/src/modules/ad/infrastructure/ad.repository.ts @@ -24,22 +24,26 @@ export type AdBaseModel = { seatsProposed: number; seatsRequested: number; strict: boolean; - createdAt: Date; - updatedAt: Date; }; export type AdReadModel = AdBaseModel & { waypoints: WaypointModel[]; schedule: ScheduleItemModel[]; + createdAt: Date; + updatedAt: Date; }; export type AdWriteModel = AdBaseModel & { - waypoints: { - create: WaypointModel[]; - }; - schedule: { - create: ScheduleItemModel[]; - }; + schedule: ScheduleWriteModel | undefined; + waypoints: WaypointWriteModel | undefined; +}; + +export type ScheduleWriteModel = { + create: ScheduleItemModel[]; +}; + +export type WaypointWriteModel = { + create: WaypointModel[]; }; export type ScheduleItemModel = { diff --git a/src/modules/ad/tests/unit/ad.mapper.spec.ts b/src/modules/ad/tests/unit/ad.mapper.spec.ts index dba2f55..47ec4d6 100644 --- a/src/modules/ad/tests/unit/ad.mapper.spec.ts +++ b/src/modules/ad/tests/unit/ad.mapper.spec.ts @@ -144,9 +144,9 @@ describe('Ad Mapper', () => { it('should map domain entity to persistence data', async () => { const mapped: AdWriteModel = adMapper.toPersistence(adEntity); - expect(mapped.waypoints.create[0].uuid.length).toBe(36); - expect(mapped.waypoints.create[1].uuid.length).toBe(36); - expect(mapped.schedule.create.length).toBe(1); + expect(mapped.waypoints?.create[0].uuid.length).toBe(36); + expect(mapped.waypoints?.create[1].uuid.length).toBe(36); + expect(mapped.schedule?.create.length).toBe(1); }); it('should map persisted data to domain entity', async () => { From fbc0ae2a3364bb4d698e22b4d3004d907daed11e Mon Sep 17 00:00:00 2001 From: Sylvain Briat Date: Thu, 18 Jan 2024 15:53:57 +0100 Subject: [PATCH 4/4] 2.4.5 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index b1404fe..1ae01ed 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@mobicoop/ad", - "version": "2.4.4", + "version": "2.4.5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@mobicoop/ad", - "version": "2.4.4", + "version": "2.4.5", "license": "AGPL", "dependencies": { "@grpc/grpc-js": "^1.9.14", diff --git a/package.json b/package.json index b31aae2..44911d2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@mobicoop/ad", - "version": "2.4.4", + "version": "2.4.5", "description": "Mobicoop V3 Ad", "author": "sbriat", "private": true,