better name

This commit is contained in:
Grégoire Chevalier 2023-06-14 10:34:27 +02:00
parent c7db1c1a85
commit 5bc74b3514
9 changed files with 34 additions and 34 deletions

View File

@ -66,7 +66,7 @@ The app exposes the following [gRPC](https://grpc.io/) services :
"driver": true, "driver": true,
"seatsDriver": 3, "seatsDriver": 3,
"frequency": "PUNCTUAL", "frequency": "PUNCTUAL",
"departureDate": "2023-01-15 09:00", "departureDateTime": "2023-01-15 09:00",
"addresses": [ "addresses": [
{ {
"position": 0, "position": 0,
@ -100,7 +100,7 @@ The app exposes the following [gRPC](https://grpc.io/) services :
"seatsDriver": 3, "seatsDriver": 3,
"seatsPassenger": 1, "seatsPassenger": 1,
"frequency": "PUNCTUAL", "frequency": "PUNCTUAL",
"departureDate": "2023-01-15 09:00", "departureDateTime": "2023-01-15 09:00",
"addresses": [ "addresses": [
{ {
"position": 0, "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 - driver (boolean, optional): if the ad is a driver ad
- passenger (boolean, optional): if the ad is a passenger ad - passenger (boolean, optional): if the ad is a passenger ad
- frequency: `PUNCTUAL` or `RECURRENT` - 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 - fromDate (required if recurrent): start date for recurrent ad
- toDate (required if recurrent): end 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: - marginDurations (optional): an object with the margin duration (in seconds) for each carpooled day in the week, eg:
{ {

View File

@ -20,7 +20,7 @@ message Ad {
bool driver = 3; bool driver = 3;
bool passenger = 4; bool passenger = 4;
Frequency frequency = 5; Frequency frequency = 5;
optional string departureDate = 6; optional string departureDateTime = 6;
string fromDate = 7; string fromDate = 7;
string toDate = 8; string toDate = 8;
Schedule schedule = 9; Schedule schedule = 9;

View File

@ -52,7 +52,7 @@ export class CreateAdRequest {
@Type(() => Date) @Type(() => Date)
@IsDate() @IsDate()
@AutoMap() @AutoMap()
departureDate?: Date; departureDateTime?: Date;
@IsOptional() @IsOptional()
@IsPunctualOrRecurrent() @IsPunctualOrRecurrent()

View File

@ -18,7 +18,7 @@ export const IsPunctualOrRecurrent = (
isPunctualOrRecurrent(args), isPunctualOrRecurrent(args),
defaultMessage: buildMessage( 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, validationOptions,
), ),
}, },

View File

@ -3,7 +3,7 @@ import { Frequency } from '../../types/frequency.enum';
const isPunctual = (args: ValidationArguments): boolean => const isPunctual = (args: ValidationArguments): boolean =>
args.object['frequency'] === Frequency.PUNCTUAL && args.object['frequency'] === Frequency.PUNCTUAL &&
args.object['departureDate'] instanceof Date && args.object['departureDateTime'] instanceof Date &&
!Object.keys(args.object['schedule']).length; !Object.keys(args.object['schedule']).length;
const isRecurrent = (args: ValidationArguments): boolean => const isRecurrent = (args: ValidationArguments): boolean =>

View File

@ -6,12 +6,12 @@ import { Frequency } from '../types/frequency.enum';
export class FrequencyNormaliser { export class FrequencyNormaliser {
fromDateResolver(createAdRequest: CreateAdRequest): Date { fromDateResolver(createAdRequest: CreateAdRequest): Date {
if (createAdRequest.frequency === Frequency.PUNCTUAL) if (createAdRequest.frequency === Frequency.PUNCTUAL)
return createAdRequest.departureDate; return createAdRequest.departureDateTime;
return createAdRequest.fromDate; return createAdRequest.fromDate;
} }
toDateResolver(createAdRequest: CreateAdRequest): Date { toDateResolver(createAdRequest: CreateAdRequest): Date {
if (createAdRequest.frequency === Frequency.PUNCTUAL) if (createAdRequest.frequency === Frequency.PUNCTUAL)
return createAdRequest.departureDate; return createAdRequest.departureDateTime;
return createAdRequest.toDate; return createAdRequest.toDate;
} }
scheduleResolver = ( scheduleResolver = (
@ -21,12 +21,12 @@ export class FrequencyNormaliser {
if ( if (
Object.keys(createAdRequest.schedule).length === 0 && Object.keys(createAdRequest.schedule).length === 0 &&
createAdRequest.frequency == Frequency.PUNCTUAL && createAdRequest.frequency == Frequency.PUNCTUAL &&
createAdRequest.departureDate.getDay() === day createAdRequest.departureDateTime.getDay() === day
) )
return `${createAdRequest.departureDate return `${createAdRequest.departureDateTime
.getHours() .getHours()
.toString() .toString()
.padStart(2, '0')}:${createAdRequest.departureDate .padStart(2, '0')}:${createAdRequest.departureDateTime
.getMinutes() .getMinutes()
.toString() .toString()
.padStart(2, '0')}`; .padStart(2, '0')}`;

View File

@ -205,7 +205,7 @@ describe('CreateAdUseCase', () => {
userUuid: '113e0000-0000-4000-a000-000000000000', userUuid: '113e0000-0000-4000-a000-000000000000',
passenger: true, passenger: true,
frequency: Frequency.PUNCTUAL, frequency: Frequency.PUNCTUAL,
departureDate: new Date('05-22-2023 09:36'), departureDateTime: new Date('05-22-2023 09:36'),
marginDurations: { marginDurations: {
mon: undefined, mon: undefined,
@ -225,8 +225,8 @@ describe('CreateAdUseCase', () => {
const expectedAdCreation = { const expectedAdCreation = {
userUuid: newPunctualPassengerAdRequest.userUuid, userUuid: newPunctualPassengerAdRequest.userUuid,
frequency: newPunctualPassengerAdRequest.frequency, frequency: newPunctualPassengerAdRequest.frequency,
fromDate: newPunctualPassengerAdRequest.departureDate, fromDate: newPunctualPassengerAdRequest.departureDateTime,
toDate: newPunctualPassengerAdRequest.departureDate, toDate: newPunctualPassengerAdRequest.departureDateTime,
monTime: '09:36', monTime: '09:36',
tueTime: undefined, tueTime: undefined,
wedTime: undefined, wedTime: undefined,

View File

@ -4,7 +4,7 @@ import { Frequency } from '../../../domain/types/frequency.enum';
describe('punctual or recurrent validators', () => { describe('punctual or recurrent validators', () => {
describe('punctual case ', () => { describe('punctual case ', () => {
describe('valid cases', () => { describe('valid cases', () => {
it('should validate with valid departureDate and empty schedule ', () => { it('should validate with valid departureDateTime and empty schedule ', () => {
expect( expect(
isPunctualOrRecurrent({ isPunctualOrRecurrent({
value: undefined, value: undefined,
@ -12,7 +12,7 @@ describe('punctual or recurrent validators', () => {
targetName: '', targetName: '',
object: { object: {
frequency: Frequency.PUNCTUAL, frequency: Frequency.PUNCTUAL,
departureDate: new Date('01-02-2023'), departureDateTime: new Date('01-02-2023'),
schedule: {}, schedule: {},
}, },
property: '', property: '',
@ -21,7 +21,7 @@ describe('punctual or recurrent validators', () => {
}); });
}); });
describe('invalid cases ', () => { 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( expect(
isPunctualOrRecurrent({ isPunctualOrRecurrent({
value: undefined, value: undefined,
@ -44,7 +44,7 @@ describe('punctual or recurrent validators', () => {
targetName: '', targetName: '',
object: { object: {
frequency: Frequency.PUNCTUAL, frequency: Frequency.PUNCTUAL,
departureDate: new Date('01-02-2023'), departureDateTime: new Date('01-02-2023'),
schedule: { schedule: {
mon: '08:30', mon: '08:30',
}, },
@ -101,7 +101,7 @@ describe('punctual or recurrent validators', () => {
targetName: '', targetName: '',
object: { object: {
frequency: Frequency.RECURRENT, frequency: Frequency.RECURRENT,
departureDate: new Date('20-10-2023'), departureDateTime: new Date('20-10-2023'),
toDate: new Date('30-10-2023'), toDate: new Date('30-10-2023'),
}, },
property: '', property: '',

View File

@ -10,15 +10,15 @@ describe('recurrent normalizer transformer for punctual ad ', () => {
const punctualAd: CreateAdRequest = { const punctualAd: CreateAdRequest = {
userUuid: '', userUuid: '',
frequency: Frequency.PUNCTUAL, frequency: Frequency.PUNCTUAL,
departureDate: new Date('05-03-2023 12:39:39 '), departureDateTime: new Date('05-03-2023 12:39:39 '),
schedule: {} as ScheduleDTO, schedule: {} as ScheduleDTO,
addresses: [], addresses: [],
}; };
expect(recurrentNormaliser.fromDateResolver(punctualAd)).toBe( expect(recurrentNormaliser.fromDateResolver(punctualAd)).toBe(
punctualAd.departureDate, punctualAd.departureDateTime,
); );
expect(recurrentNormaliser.toDateResolver(punctualAd)).toBe( expect(recurrentNormaliser.toDateResolver(punctualAd)).toBe(
punctualAd.departureDate, punctualAd.departureDateTime,
); );
expect( expect(
recurrentNormaliser.scheduleResolver(punctualAd, Day.mon), recurrentNormaliser.scheduleResolver(punctualAd, Day.mon),
@ -55,10 +55,10 @@ describe('recurrent normalizer transformer for punctual ad ', () => {
addresses: [], addresses: [],
}; };
expect(recurrentNormaliser.fromDateResolver(recurrentAd)).toBe( expect(recurrentNormaliser.fromDateResolver(recurrentAd)).toBe(
recurrentAd.departureDate, recurrentAd.departureDateTime,
); );
expect(recurrentNormaliser.toDateResolver(recurrentAd)).toBe( expect(recurrentNormaliser.toDateResolver(recurrentAd)).toBe(
recurrentAd.departureDate, recurrentAd.departureDateTime,
); );
expect(recurrentNormaliser.scheduleResolver(recurrentAd, Day.mon)).toBe( expect(recurrentNormaliser.scheduleResolver(recurrentAd, Day.mon)).toBe(
recurrentAd.schedule.mon, recurrentAd.schedule.mon,
@ -86,35 +86,35 @@ describe('recurrent normalizer transformer for punctual ad ', () => {
const punctualAd: CreateAdRequest = { const punctualAd: CreateAdRequest = {
userUuid: '', userUuid: '',
frequency: Frequency.PUNCTUAL, frequency: Frequency.PUNCTUAL,
departureDate: undefined, departureDateTime: undefined,
schedule: {} as ScheduleDTO, schedule: {} as ScheduleDTO,
addresses: [], addresses: [],
}; };
punctualAd.departureDate = new Date('05-01-2023 '); punctualAd.departureDateTime = new Date('05-01-2023 ');
expect(recurrentNormaliser.scheduleResolver(punctualAd, Day.mon)).toBe( expect(recurrentNormaliser.scheduleResolver(punctualAd, Day.mon)).toBe(
'00:00', '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( expect(recurrentNormaliser.scheduleResolver(punctualAd, Day.tue)).toBe(
'06:32', '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( expect(recurrentNormaliser.scheduleResolver(punctualAd, Day.wed)).toBe(
'10:21', '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( expect(recurrentNormaliser.scheduleResolver(punctualAd, Day.thu)).toBe(
'11:06', '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( expect(recurrentNormaliser.scheduleResolver(punctualAd, Day.fri)).toBe(
'05:20', '05:20',
); );
punctualAd.departureDate = new Date('05-06-2023'); punctualAd.departureDateTime = new Date('05-06-2023');
expect(recurrentNormaliser.scheduleResolver(punctualAd, Day.sat)).toBe( expect(recurrentNormaliser.scheduleResolver(punctualAd, Day.sat)).toBe(
'00:00', '00:00',
); );
punctualAd.departureDate = new Date('05-07-2023'); punctualAd.departureDateTime = new Date('05-07-2023');
expect(recurrentNormaliser.scheduleResolver(punctualAd, Day.sun)).toBe( expect(recurrentNormaliser.scheduleResolver(punctualAd, Day.sun)).toBe(
'00:00', '00:00',
); );