Merge branch 'refactor-ad' into 'main'
rename departure See merge request v3/service/ad!8
This commit is contained in:
commit
fe7d948fd1
|
@ -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",
|
||||||
"departure": "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",
|
||||||
"departure": "2023-01-15 09:00",
|
"departureDateTime": "2023-01-15 09:00",
|
||||||
"addresses": [
|
"addresses": [
|
||||||
{
|
{
|
||||||
"position": 0,
|
"position": 0,
|
||||||
|
@ -169,7 +169,7 @@ 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`
|
||||||
- departure (required if punctual): departure date and hour/minute for a punctual ad
|
- departureDateTime (required if punctual): departure 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 departure time for each carpooled day in the week
|
- schedule (required if recurrent): an object with the departure time for each carpooled day in the week
|
||||||
|
|
|
@ -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 departure = 6;
|
optional string departureDateTime = 6;
|
||||||
string fromDate = 7;
|
string fromDate = 7;
|
||||||
string toDate = 8;
|
string toDate = 8;
|
||||||
Schedule schedule = 9;
|
Schedule schedule = 9;
|
||||||
|
|
|
@ -52,7 +52,7 @@ export class CreateAdRequest {
|
||||||
@Type(() => Date)
|
@Type(() => Date)
|
||||||
@IsDate()
|
@IsDate()
|
||||||
@AutoMap()
|
@AutoMap()
|
||||||
departure?: Date;
|
departureDateTime?: Date;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsPunctualOrRecurrent()
|
@IsPunctualOrRecurrent()
|
||||||
|
|
|
@ -18,7 +18,7 @@ export const IsPunctualOrRecurrent = (
|
||||||
isPunctualOrRecurrent(args),
|
isPunctualOrRecurrent(args),
|
||||||
defaultMessage: buildMessage(
|
defaultMessage: buildMessage(
|
||||||
() =>
|
() =>
|
||||||
`the departure, from date, to date and schedule must be properly set on recurrent or punctual ad`,
|
`the departure Date and time , from date, to date and schedule must be properly set on recurrent or punctual ad`,
|
||||||
validationOptions,
|
validationOptions,
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|
|
@ -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['departure'] 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 =>
|
||||||
|
|
|
@ -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.departure;
|
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.departure;
|
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.departure.getDay() === day
|
createAdRequest.departureDateTime.getDay() === day
|
||||||
)
|
)
|
||||||
return `${createAdRequest.departure
|
return `${createAdRequest.departureDateTime
|
||||||
.getHours()
|
.getHours()
|
||||||
.toString()
|
.toString()
|
||||||
.padStart(2, '0')}:${createAdRequest.departure
|
.padStart(2, '0')}:${createAdRequest.departureDateTime
|
||||||
.getMinutes()
|
.getMinutes()
|
||||||
.toString()
|
.toString()
|
||||||
.padStart(2, '0')}`;
|
.padStart(2, '0')}`;
|
||||||
|
|
|
@ -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,
|
||||||
departure: 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.departure,
|
fromDate: newPunctualPassengerAdRequest.departureDateTime,
|
||||||
toDate: newPunctualPassengerAdRequest.departure,
|
toDate: newPunctualPassengerAdRequest.departureDateTime,
|
||||||
monTime: '09:36',
|
monTime: '09:36',
|
||||||
tueTime: undefined,
|
tueTime: undefined,
|
||||||
wedTime: undefined,
|
wedTime: undefined,
|
||||||
|
|
|
@ -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 departure and empty schedule ', () => {
|
it('should validate with valid departure DateTime 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,
|
||||||
departure: 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 departure 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,
|
||||||
departure: 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,
|
||||||
departure: 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: '',
|
||||||
|
|
|
@ -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,
|
||||||
departure: 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.departure,
|
punctualAd.departureDateTime,
|
||||||
);
|
);
|
||||||
expect(recurrentNormaliser.toDateResolver(punctualAd)).toBe(
|
expect(recurrentNormaliser.toDateResolver(punctualAd)).toBe(
|
||||||
punctualAd.departure,
|
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.departure,
|
recurrentAd.departureDateTime,
|
||||||
);
|
);
|
||||||
expect(recurrentNormaliser.toDateResolver(recurrentAd)).toBe(
|
expect(recurrentNormaliser.toDateResolver(recurrentAd)).toBe(
|
||||||
recurrentAd.departure,
|
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,
|
||||||
departure: undefined,
|
departureDateTime: undefined,
|
||||||
schedule: {} as ScheduleDTO,
|
schedule: {} as ScheduleDTO,
|
||||||
addresses: [],
|
addresses: [],
|
||||||
};
|
};
|
||||||
punctualAd.departure = 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.departure = 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.departure = 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.departure = 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.departure = 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.departure = 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.departure = 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',
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue