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,
|
||||
"seatsDriver": 3,
|
||||
"frequency": "PUNCTUAL",
|
||||
"departure": "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",
|
||||
"departure": "2023-01-15 09:00",
|
||||
"departureDateTime": "2023-01-15 09:00",
|
||||
"addresses": [
|
||||
{
|
||||
"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
|
||||
- passenger (boolean, optional): if the ad is a passenger ad
|
||||
- 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
|
||||
- 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
|
||||
|
|
|
@ -20,7 +20,7 @@ message Ad {
|
|||
bool driver = 3;
|
||||
bool passenger = 4;
|
||||
Frequency frequency = 5;
|
||||
optional string departure = 6;
|
||||
optional string departureDateTime = 6;
|
||||
string fromDate = 7;
|
||||
string toDate = 8;
|
||||
Schedule schedule = 9;
|
||||
|
|
|
@ -52,7 +52,7 @@ export class CreateAdRequest {
|
|||
@Type(() => Date)
|
||||
@IsDate()
|
||||
@AutoMap()
|
||||
departure?: Date;
|
||||
departureDateTime?: Date;
|
||||
|
||||
@IsOptional()
|
||||
@IsPunctualOrRecurrent()
|
||||
|
|
|
@ -18,7 +18,7 @@ export const IsPunctualOrRecurrent = (
|
|||
isPunctualOrRecurrent(args),
|
||||
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,
|
||||
),
|
||||
},
|
||||
|
|
|
@ -3,7 +3,7 @@ import { Frequency } from '../../types/frequency.enum';
|
|||
|
||||
const isPunctual = (args: ValidationArguments): boolean =>
|
||||
args.object['frequency'] === Frequency.PUNCTUAL &&
|
||||
args.object['departure'] instanceof Date &&
|
||||
args.object['departureDateTime'] instanceof Date &&
|
||||
!Object.keys(args.object['schedule']).length;
|
||||
|
||||
const isRecurrent = (args: ValidationArguments): boolean =>
|
||||
|
|
|
@ -6,12 +6,12 @@ import { Frequency } from '../types/frequency.enum';
|
|||
export class FrequencyNormaliser {
|
||||
fromDateResolver(createAdRequest: CreateAdRequest): Date {
|
||||
if (createAdRequest.frequency === Frequency.PUNCTUAL)
|
||||
return createAdRequest.departure;
|
||||
return createAdRequest.departureDateTime;
|
||||
return createAdRequest.fromDate;
|
||||
}
|
||||
toDateResolver(createAdRequest: CreateAdRequest): Date {
|
||||
if (createAdRequest.frequency === Frequency.PUNCTUAL)
|
||||
return createAdRequest.departure;
|
||||
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.departure.getDay() === day
|
||||
createAdRequest.departureDateTime.getDay() === day
|
||||
)
|
||||
return `${createAdRequest.departure
|
||||
return `${createAdRequest.departureDateTime
|
||||
.getHours()
|
||||
.toString()
|
||||
.padStart(2, '0')}:${createAdRequest.departure
|
||||
.padStart(2, '0')}:${createAdRequest.departureDateTime
|
||||
.getMinutes()
|
||||
.toString()
|
||||
.padStart(2, '0')}`;
|
||||
|
|
|
@ -205,7 +205,7 @@ describe('CreateAdUseCase', () => {
|
|||
userUuid: '113e0000-0000-4000-a000-000000000000',
|
||||
passenger: true,
|
||||
frequency: Frequency.PUNCTUAL,
|
||||
departure: 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.departure,
|
||||
toDate: newPunctualPassengerAdRequest.departure,
|
||||
fromDate: newPunctualPassengerAdRequest.departureDateTime,
|
||||
toDate: newPunctualPassengerAdRequest.departureDateTime,
|
||||
monTime: '09:36',
|
||||
tueTime: undefined,
|
||||
wedTime: undefined,
|
||||
|
|
|
@ -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 departure and empty schedule ', () => {
|
||||
it('should validate with valid departure DateTime and empty schedule ', () => {
|
||||
expect(
|
||||
isPunctualOrRecurrent({
|
||||
value: undefined,
|
||||
|
@ -12,7 +12,7 @@ describe('punctual or recurrent validators', () => {
|
|||
targetName: '',
|
||||
object: {
|
||||
frequency: Frequency.PUNCTUAL,
|
||||
departure: 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 departure 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,
|
||||
departure: 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,
|
||||
departure: new Date('20-10-2023'),
|
||||
departureDateTime: new Date('20-10-2023'),
|
||||
toDate: new Date('30-10-2023'),
|
||||
},
|
||||
property: '',
|
||||
|
|
|
@ -10,15 +10,15 @@ describe('recurrent normalizer transformer for punctual ad ', () => {
|
|||
const punctualAd: CreateAdRequest = {
|
||||
userUuid: '',
|
||||
frequency: Frequency.PUNCTUAL,
|
||||
departure: 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.departure,
|
||||
punctualAd.departureDateTime,
|
||||
);
|
||||
expect(recurrentNormaliser.toDateResolver(punctualAd)).toBe(
|
||||
punctualAd.departure,
|
||||
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.departure,
|
||||
recurrentAd.departureDateTime,
|
||||
);
|
||||
expect(recurrentNormaliser.toDateResolver(recurrentAd)).toBe(
|
||||
recurrentAd.departure,
|
||||
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,
|
||||
departure: undefined,
|
||||
departureDateTime: undefined,
|
||||
schedule: {} as ScheduleDTO,
|
||||
addresses: [],
|
||||
};
|
||||
punctualAd.departure = new Date('05-01-2023 ');
|
||||
punctualAd.departureDateTime = new Date('05-01-2023 ');
|
||||
expect(recurrentNormaliser.scheduleResolver(punctualAd, Day.mon)).toBe(
|
||||
'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(
|
||||
'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(
|
||||
'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(
|
||||
'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(
|
||||
'05:20',
|
||||
);
|
||||
punctualAd.departure = new Date('05-06-2023');
|
||||
punctualAd.departureDateTime = new Date('05-06-2023');
|
||||
expect(recurrentNormaliser.scheduleResolver(punctualAd, Day.sat)).toBe(
|
||||
'00:00',
|
||||
);
|
||||
punctualAd.departure = new Date('05-07-2023');
|
||||
punctualAd.departureDateTime = new Date('05-07-2023');
|
||||
expect(recurrentNormaliser.scheduleResolver(punctualAd, Day.sun)).toBe(
|
||||
'00:00',
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue