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,
"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:
{

View File

@ -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;

View File

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

View File

@ -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,
),
},

View File

@ -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 =>

View File

@ -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')}`;

View File

@ -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,

View File

@ -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: '',

View File

@ -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',
);