From 5bc74b3514eb2dfb9a27ef703ceae49e43c5a95d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Chevalier?= Date: Wed, 14 Jun 2023 10:34:27 +0200 Subject: [PATCH] better name --- README.md | 8 +++--- src/modules/ad/adapters/primaries/ad.proto | 2 +- .../ad/domain/dtos/create-ad.request.ts | 2 +- .../is-punctual-or-recurrent.validator.ts | 2 +- .../validators/is-punctual-or-recurrent.ts | 2 +- .../domain/entities/frequency.normaliser.ts | 10 +++---- .../unit/domain/create-ad.usecase.spec.ts | 6 ++--- .../domain/is-punctual-or-reccurent.spec.ts | 10 +++---- .../unit/domain/recurrent-normaliser.spec.ts | 26 +++++++++---------- 9 files changed, 34 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index fae6bfd..66a08d4 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ The app exposes the following [gRPC](https://grpc.io/) services : "driver": true, "seatsDriver": 3, "frequency": "PUNCTUAL", - "departureDate": "2023-01-15 09:00", + "departureDateTime": "2023-01-15 09:00", "addresses": [ { "position": 0, @@ -100,7 +100,7 @@ The app exposes the following [gRPC](https://grpc.io/) services : "seatsDriver": 3, "seatsPassenger": 1, "frequency": "PUNCTUAL", - "departureDate": "2023-01-15 09:00", + "departureDateTime": "2023-01-15 09:00", "addresses": [ { "position": 0, @@ -169,10 +169,10 @@ The app exposes the following [gRPC](https://grpc.io/) services : - driver (boolean, optional): if the ad is a driver ad - passenger (boolean, optional): if the ad is a passenger ad - frequency: `PUNCTUAL` or `RECURRENT` - - departureDate (required if punctual): departureDate date and hour/minute for a punctual ad + - departureDateTime (required if punctual): departureDateTime date and hour/minute for a punctual ad - fromDate (required if recurrent): start date for recurrent ad - toDate (required if recurrent): end date for recurrent ad - - schedule (required if recurrent): an object with the departureDate time for each carpooled day in the week + - schedule (required if recurrent): an object with the departureDateTime time for each carpooled day in the week - marginDurations (optional): an object with the margin duration (in seconds) for each carpooled day in the week, eg: { diff --git a/src/modules/ad/adapters/primaries/ad.proto b/src/modules/ad/adapters/primaries/ad.proto index 9cc623d..d8c2652 100644 --- a/src/modules/ad/adapters/primaries/ad.proto +++ b/src/modules/ad/adapters/primaries/ad.proto @@ -20,7 +20,7 @@ message Ad { bool driver = 3; bool passenger = 4; Frequency frequency = 5; - optional string departureDate = 6; + optional string departureDateTime = 6; string fromDate = 7; string toDate = 8; Schedule schedule = 9; diff --git a/src/modules/ad/domain/dtos/create-ad.request.ts b/src/modules/ad/domain/dtos/create-ad.request.ts index feb42d1..cbb3f7b 100644 --- a/src/modules/ad/domain/dtos/create-ad.request.ts +++ b/src/modules/ad/domain/dtos/create-ad.request.ts @@ -52,7 +52,7 @@ export class CreateAdRequest { @Type(() => Date) @IsDate() @AutoMap() - departureDate?: Date; + departureDateTime?: Date; @IsOptional() @IsPunctualOrRecurrent() diff --git a/src/modules/ad/domain/dtos/validators/decorators/is-punctual-or-recurrent.validator.ts b/src/modules/ad/domain/dtos/validators/decorators/is-punctual-or-recurrent.validator.ts index 2ce5527..de249ee 100644 --- a/src/modules/ad/domain/dtos/validators/decorators/is-punctual-or-recurrent.validator.ts +++ b/src/modules/ad/domain/dtos/validators/decorators/is-punctual-or-recurrent.validator.ts @@ -18,7 +18,7 @@ export const IsPunctualOrRecurrent = ( isPunctualOrRecurrent(args), defaultMessage: buildMessage( () => - `the departureDate, from date, to date and schedule must be properly set on recurrent or punctual ad`, + `the departureDateTime, from date, to date and schedule must be properly set on recurrent or punctual ad`, validationOptions, ), }, diff --git a/src/modules/ad/domain/dtos/validators/is-punctual-or-recurrent.ts b/src/modules/ad/domain/dtos/validators/is-punctual-or-recurrent.ts index d25827e..7c974d6 100644 --- a/src/modules/ad/domain/dtos/validators/is-punctual-or-recurrent.ts +++ b/src/modules/ad/domain/dtos/validators/is-punctual-or-recurrent.ts @@ -3,7 +3,7 @@ import { Frequency } from '../../types/frequency.enum'; const isPunctual = (args: ValidationArguments): boolean => args.object['frequency'] === Frequency.PUNCTUAL && - args.object['departureDate'] instanceof Date && + args.object['departureDateTime'] instanceof Date && !Object.keys(args.object['schedule']).length; const isRecurrent = (args: ValidationArguments): boolean => diff --git a/src/modules/ad/domain/entities/frequency.normaliser.ts b/src/modules/ad/domain/entities/frequency.normaliser.ts index 032f294..4d8c72a 100644 --- a/src/modules/ad/domain/entities/frequency.normaliser.ts +++ b/src/modules/ad/domain/entities/frequency.normaliser.ts @@ -6,12 +6,12 @@ import { Frequency } from '../types/frequency.enum'; export class FrequencyNormaliser { fromDateResolver(createAdRequest: CreateAdRequest): Date { if (createAdRequest.frequency === Frequency.PUNCTUAL) - return createAdRequest.departureDate; + return createAdRequest.departureDateTime; return createAdRequest.fromDate; } toDateResolver(createAdRequest: CreateAdRequest): Date { if (createAdRequest.frequency === Frequency.PUNCTUAL) - return createAdRequest.departureDate; + return createAdRequest.departureDateTime; return createAdRequest.toDate; } scheduleResolver = ( @@ -21,12 +21,12 @@ export class FrequencyNormaliser { if ( Object.keys(createAdRequest.schedule).length === 0 && createAdRequest.frequency == Frequency.PUNCTUAL && - createAdRequest.departureDate.getDay() === day + createAdRequest.departureDateTime.getDay() === day ) - return `${createAdRequest.departureDate + return `${createAdRequest.departureDateTime .getHours() .toString() - .padStart(2, '0')}:${createAdRequest.departureDate + .padStart(2, '0')}:${createAdRequest.departureDateTime .getMinutes() .toString() .padStart(2, '0')}`; diff --git a/src/modules/ad/tests/unit/domain/create-ad.usecase.spec.ts b/src/modules/ad/tests/unit/domain/create-ad.usecase.spec.ts index 4f9e64b..8ef3770 100644 --- a/src/modules/ad/tests/unit/domain/create-ad.usecase.spec.ts +++ b/src/modules/ad/tests/unit/domain/create-ad.usecase.spec.ts @@ -205,7 +205,7 @@ describe('CreateAdUseCase', () => { userUuid: '113e0000-0000-4000-a000-000000000000', passenger: true, frequency: Frequency.PUNCTUAL, - departureDate: new Date('05-22-2023 09:36'), + departureDateTime: new Date('05-22-2023 09:36'), marginDurations: { mon: undefined, @@ -225,8 +225,8 @@ describe('CreateAdUseCase', () => { const expectedAdCreation = { userUuid: newPunctualPassengerAdRequest.userUuid, frequency: newPunctualPassengerAdRequest.frequency, - fromDate: newPunctualPassengerAdRequest.departureDate, - toDate: newPunctualPassengerAdRequest.departureDate, + fromDate: newPunctualPassengerAdRequest.departureDateTime, + toDate: newPunctualPassengerAdRequest.departureDateTime, monTime: '09:36', tueTime: undefined, wedTime: undefined, diff --git a/src/modules/ad/tests/unit/domain/is-punctual-or-reccurent.spec.ts b/src/modules/ad/tests/unit/domain/is-punctual-or-reccurent.spec.ts index b4a0566..c2f8373 100644 --- a/src/modules/ad/tests/unit/domain/is-punctual-or-reccurent.spec.ts +++ b/src/modules/ad/tests/unit/domain/is-punctual-or-reccurent.spec.ts @@ -4,7 +4,7 @@ import { Frequency } from '../../../domain/types/frequency.enum'; describe('punctual or recurrent validators', () => { describe('punctual case ', () => { describe('valid cases', () => { - it('should validate with valid departureDate and empty schedule ', () => { + it('should validate with valid departureDateTime and empty schedule ', () => { expect( isPunctualOrRecurrent({ value: undefined, @@ -12,7 +12,7 @@ describe('punctual or recurrent validators', () => { targetName: '', object: { frequency: Frequency.PUNCTUAL, - departureDate: new Date('01-02-2023'), + departureDateTime: new Date('01-02-2023'), schedule: {}, }, property: '', @@ -21,7 +21,7 @@ describe('punctual or recurrent validators', () => { }); }); describe('invalid cases ', () => { - it('should not validate with invalid departureDate and empty schedule and margin', () => { + it('should not validate with invalid departureDateTime and empty schedule and margin', () => { expect( isPunctualOrRecurrent({ value: undefined, @@ -44,7 +44,7 @@ describe('punctual or recurrent validators', () => { targetName: '', object: { frequency: Frequency.PUNCTUAL, - departureDate: new Date('01-02-2023'), + departureDateTime: new Date('01-02-2023'), schedule: { mon: '08:30', }, @@ -101,7 +101,7 @@ describe('punctual or recurrent validators', () => { targetName: '', object: { frequency: Frequency.RECURRENT, - departureDate: new Date('20-10-2023'), + departureDateTime: new Date('20-10-2023'), toDate: new Date('30-10-2023'), }, property: '', diff --git a/src/modules/ad/tests/unit/domain/recurrent-normaliser.spec.ts b/src/modules/ad/tests/unit/domain/recurrent-normaliser.spec.ts index 504b166..f94e52e 100644 --- a/src/modules/ad/tests/unit/domain/recurrent-normaliser.spec.ts +++ b/src/modules/ad/tests/unit/domain/recurrent-normaliser.spec.ts @@ -10,15 +10,15 @@ describe('recurrent normalizer transformer for punctual ad ', () => { const punctualAd: CreateAdRequest = { userUuid: '', frequency: Frequency.PUNCTUAL, - departureDate: new Date('05-03-2023 12:39:39 '), + departureDateTime: new Date('05-03-2023 12:39:39 '), schedule: {} as ScheduleDTO, addresses: [], }; expect(recurrentNormaliser.fromDateResolver(punctualAd)).toBe( - punctualAd.departureDate, + punctualAd.departureDateTime, ); expect(recurrentNormaliser.toDateResolver(punctualAd)).toBe( - punctualAd.departureDate, + punctualAd.departureDateTime, ); expect( recurrentNormaliser.scheduleResolver(punctualAd, Day.mon), @@ -55,10 +55,10 @@ describe('recurrent normalizer transformer for punctual ad ', () => { addresses: [], }; expect(recurrentNormaliser.fromDateResolver(recurrentAd)).toBe( - recurrentAd.departureDate, + recurrentAd.departureDateTime, ); expect(recurrentNormaliser.toDateResolver(recurrentAd)).toBe( - recurrentAd.departureDate, + recurrentAd.departureDateTime, ); expect(recurrentNormaliser.scheduleResolver(recurrentAd, Day.mon)).toBe( recurrentAd.schedule.mon, @@ -86,35 +86,35 @@ describe('recurrent normalizer transformer for punctual ad ', () => { const punctualAd: CreateAdRequest = { userUuid: '', frequency: Frequency.PUNCTUAL, - departureDate: undefined, + departureDateTime: undefined, schedule: {} as ScheduleDTO, addresses: [], }; - punctualAd.departureDate = new Date('05-01-2023 '); + punctualAd.departureDateTime = new Date('05-01-2023 '); expect(recurrentNormaliser.scheduleResolver(punctualAd, Day.mon)).toBe( '00:00', ); - punctualAd.departureDate = new Date('05-02-2023 06:32:45'); + punctualAd.departureDateTime = new Date('05-02-2023 06:32:45'); expect(recurrentNormaliser.scheduleResolver(punctualAd, Day.tue)).toBe( '06:32', ); - punctualAd.departureDate = new Date('05-03-2023 10:21'); + punctualAd.departureDateTime = new Date('05-03-2023 10:21'); expect(recurrentNormaliser.scheduleResolver(punctualAd, Day.wed)).toBe( '10:21', ); - punctualAd.departureDate = new Date('05-04-2023 11:06:00'); + punctualAd.departureDateTime = new Date('05-04-2023 11:06:00'); expect(recurrentNormaliser.scheduleResolver(punctualAd, Day.thu)).toBe( '11:06', ); - punctualAd.departureDate = new Date('05-05-2023 05:20'); + punctualAd.departureDateTime = new Date('05-05-2023 05:20'); expect(recurrentNormaliser.scheduleResolver(punctualAd, Day.fri)).toBe( '05:20', ); - punctualAd.departureDate = new Date('05-06-2023'); + punctualAd.departureDateTime = new Date('05-06-2023'); expect(recurrentNormaliser.scheduleResolver(punctualAd, Day.sat)).toBe( '00:00', ); - punctualAd.departureDate = new Date('05-07-2023'); + punctualAd.departureDateTime = new Date('05-07-2023'); expect(recurrentNormaliser.scheduleResolver(punctualAd, Day.sun)).toBe( '00:00', );