adding ad default parameters to .env
This commit is contained in:
parent
10f4d1a0dc
commit
f5ce6ca005
13
.env.dist
13
.env.dist
|
@ -15,3 +15,16 @@ RMQ_EXCHANGE=mobicoop
|
|||
REDIS_HOST=v3-redis
|
||||
REDIS_PASSWORD=redis
|
||||
REDIS_PORT=6379
|
||||
|
||||
# DEFAULT CARPOOL DEPARTURE MARGIN (in seconds)
|
||||
DEPARTURE_MARGIN=900
|
||||
|
||||
# DEFAULT ROLE
|
||||
ROLE=passenger
|
||||
|
||||
# SEATS PROVIDED AS DRIVER / REQUESTED AS PASSENGER
|
||||
SEATS_PROVIDED=3
|
||||
SEATS_REQUESTED=1
|
||||
|
||||
# ACCEPT ONLY SAME FREQUENCY REQUESTS
|
||||
STRICT_FREQUENCY=false
|
|
@ -6,20 +6,19 @@ import { IProvideParams } from '../../domain/interfaces/param-provider.interface
|
|||
@Injectable()
|
||||
export class DefaultParamsProvider implements IProvideParams {
|
||||
constructor(private readonly configService: ConfigService) {}
|
||||
//TODO adding config service
|
||||
getParams = (): DefaultParams => {
|
||||
return {
|
||||
MON_MARGIN: 900,
|
||||
TUE_MARGIN: 900,
|
||||
WED_MARGIN: 900,
|
||||
THU_MARGIN: 900,
|
||||
FRI_MARGIN: 900,
|
||||
SAT_MARGIN: 900,
|
||||
SUN_MARGIN: 900,
|
||||
DRIVER: false,
|
||||
DRIVER_SEAT: 0,
|
||||
PASSENGER: true,
|
||||
PASSENGER_SEATS: 1,
|
||||
MON_MARGIN: this.configService.get('DEPARTURE_MARGIN'),
|
||||
TUE_MARGIN: this.configService.get('DEPARTURE_MARGIN'),
|
||||
WED_MARGIN: this.configService.get('DEPARTURE_MARGIN'),
|
||||
THU_MARGIN: this.configService.get('DEPARTURE_MARGIN'),
|
||||
FRI_MARGIN: this.configService.get('DEPARTURE_MARGIN'),
|
||||
SAT_MARGIN: this.configService.get('DEPARTURE_MARGIN'),
|
||||
SUN_MARGIN: this.configService.get('DEPARTURE_MARGIN'),
|
||||
DRIVER: this.configService.get('ROLE') == 'driver' ? true : false,
|
||||
SEATS_PROVIDED: this.configService.get('SEATS_PROVIDED'),
|
||||
PASSENGER: this.configService.get('ROLE') == 'passenger' ? true : false,
|
||||
SEATS_REQUESTED: this.configService.get('SEATS_REQUESTED'),
|
||||
STRICT: false,
|
||||
};
|
||||
};
|
||||
|
|
|
@ -50,7 +50,6 @@ export class CreateAdRequest {
|
|||
@AutoMap()
|
||||
frequency: Frequency;
|
||||
|
||||
// TODO create a proper validator
|
||||
@ValidateIf((ad) => ad.frequency === 'PUNCTUAL')
|
||||
@Type(() => Date)
|
||||
@IsDate()
|
||||
|
|
|
@ -4,8 +4,7 @@ import {
|
|||
ValidationOptions,
|
||||
buildMessage,
|
||||
} from 'class-validator';
|
||||
// TODO refactor ??
|
||||
// TODO propely set driver max limit
|
||||
|
||||
export function hasProperDriverSeats(value: any, args: ValidationArguments) {
|
||||
if (value === true && typeof args.object['seatsDriver'] === 'number')
|
||||
return args.object['seatsDriver'] > 0;
|
||||
|
|
|
@ -4,8 +4,7 @@ import {
|
|||
ValidationOptions,
|
||||
buildMessage,
|
||||
} from 'class-validator';
|
||||
// TODO refactor ??
|
||||
// TODO propely set passenger max limit
|
||||
|
||||
export function hasProperPassengerSeats(value: any, args: ValidationArguments) {
|
||||
if (value === true && typeof args.object['seatsPassenger'] === 'number')
|
||||
return args.object['seatsPassenger'] > 0;
|
||||
|
|
|
@ -3,8 +3,6 @@ import { CreateAdRequest } from '../dtos/create-ad.request';
|
|||
import { Frequency } from '../types/frequency.enum';
|
||||
|
||||
export class ReccurentNormaliser {
|
||||
constructor() {}
|
||||
|
||||
fromDateResolver(createAdRequest: CreateAdRequest): Date {
|
||||
if (createAdRequest.frequency === Frequency.PUNCTUAL)
|
||||
return createAdRequest.departure;
|
||||
|
|
|
@ -7,8 +7,8 @@ export type DefaultParams = {
|
|||
SAT_MARGIN: number;
|
||||
SUN_MARGIN: number;
|
||||
DRIVER: boolean;
|
||||
DRIVER_SEAT: number;
|
||||
SEATS_PROVIDED: number;
|
||||
PASSENGER: boolean;
|
||||
PASSENGER_SEATS: number;
|
||||
SEATS_REQUESTED: number;
|
||||
STRICT: boolean;
|
||||
};
|
||||
|
|
|
@ -11,7 +11,6 @@ import { IProvideParams } from '../interfaces/param-provider.interface';
|
|||
import { DefaultParams } from '../types/default-params.type';
|
||||
import { AdCreation } from '../dtos/ad.creation';
|
||||
import { Ad } from '../entities/ad';
|
||||
import { Frequency } from '../types/frequency.enum';
|
||||
|
||||
@CommandHandler(CreateAdCommand)
|
||||
export class CreateAdUseCase {
|
||||
|
@ -84,9 +83,9 @@ export class CreateAdUseCase {
|
|||
setDefaultDriverAndPassengerParameters(): void {
|
||||
if (!this.ad.driver && !this.ad.passenger) {
|
||||
this.ad.driver = this.defaultParams.DRIVER;
|
||||
this.ad.seatsDriver = this.defaultParams.DRIVER_SEAT;
|
||||
this.ad.seatsDriver = this.defaultParams.SEATS_PROVIDED;
|
||||
this.ad.passenger = this.defaultParams.PASSENGER;
|
||||
this.ad.seatsPassenger = this.defaultParams.PASSENGER_SEATS;
|
||||
this.ad.seatsPassenger = this.defaultParams.SEATS_REQUESTED;
|
||||
} else {
|
||||
if (!this.ad.driver) {
|
||||
this.ad.driver = false;
|
||||
|
@ -105,8 +104,4 @@ export class CreateAdUseCase {
|
|||
}
|
||||
}
|
||||
}
|
||||
TransformPunctualToReccurent(): void {
|
||||
if (this.ad.frequency === Frequency.PUNCTUAL) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,25 +79,6 @@ const newAdRequest: CreateAdRequest = {
|
|||
seatsDriver: 2,
|
||||
addresses: [mockAddress1, mockAddress2],
|
||||
};
|
||||
const newPunctualPassengerAdRequest: CreateAdRequest = {
|
||||
userUuid: '113e0000-0000-4000-a000-000000000000',
|
||||
passenger: true,
|
||||
frequency: Frequency.PUNCTUAL,
|
||||
departure: new Date('05-22-2023'),
|
||||
|
||||
marginDurations: {
|
||||
mon: undefined,
|
||||
tue: undefined,
|
||||
wed: undefined,
|
||||
thu: undefined,
|
||||
fri: undefined,
|
||||
sat: undefined,
|
||||
sun: undefined,
|
||||
},
|
||||
seatsPassenger: 1,
|
||||
addresses: [mockAddressWithoutPos1, mockAddressWithoutPos2],
|
||||
schedule: {},
|
||||
};
|
||||
|
||||
const mockMessager = {
|
||||
publish: jest.fn().mockImplementation(),
|
||||
|
@ -113,14 +94,14 @@ const mockDefaultParamsProvider = {
|
|||
SAT_MARGIN: 900,
|
||||
SUN_MARGIN: 900,
|
||||
DRIVER: false,
|
||||
DRIVER_SEAT: 0,
|
||||
SEATS_PROVIDED: 0,
|
||||
PASSENGER: true,
|
||||
PASSENGER_SEATS: 1,
|
||||
SEATS_REQUESTED: 1,
|
||||
STRICT: false,
|
||||
};
|
||||
},
|
||||
};
|
||||
let mockAdRepository = {
|
||||
const mockAdRepository = {
|
||||
create: jest
|
||||
.fn()
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
|
@ -134,7 +115,7 @@ let mockAdRepository = {
|
|||
.mockImplementationOnce(() => {
|
||||
throw new Error('Already exists');
|
||||
})
|
||||
.mockImplementation((command?: CreateAdCommand) => {}),
|
||||
.mockImplementation(),
|
||||
};
|
||||
describe('CreateAdUseCase', () => {
|
||||
let createAdUseCase: CreateAdUseCase;
|
||||
|
@ -206,9 +187,9 @@ describe('CreateAdUseCase', () => {
|
|||
satMargin: mockDefaultParamsProvider.getParams().SAT_MARGIN,
|
||||
sunMargin: mockDefaultParamsProvider.getParams().SUN_MARGIN,
|
||||
driver: mockDefaultParamsProvider.getParams().DRIVER,
|
||||
seatsDriver: mockDefaultParamsProvider.getParams().DRIVER_SEAT,
|
||||
seatsDriver: mockDefaultParamsProvider.getParams().SEATS_PROVIDED,
|
||||
passenger: mockDefaultParamsProvider.getParams().PASSENGER,
|
||||
seatsPassenger: mockDefaultParamsProvider.getParams().PASSENGER_SEATS,
|
||||
seatsPassenger: mockDefaultParamsProvider.getParams().SEATS_REQUESTED,
|
||||
strict: mockDefaultParamsProvider.getParams().STRICT,
|
||||
addresses: {
|
||||
create: minimalReccurentAdREquest.addresses as AddressCreation[],
|
||||
|
@ -219,8 +200,57 @@ describe('CreateAdUseCase', () => {
|
|||
expect(mockAdRepository.create).toBeCalledWith(expectedAdCreation);
|
||||
});
|
||||
it('should create an passengerAd with addresses without position ', async () => {
|
||||
const newPunctualPassengerAdRequest: CreateAdRequest = {
|
||||
userUuid: '113e0000-0000-4000-a000-000000000000',
|
||||
passenger: true,
|
||||
frequency: Frequency.PUNCTUAL,
|
||||
departure: new Date('05-22-2023 09:36'),
|
||||
|
||||
marginDurations: {
|
||||
mon: undefined,
|
||||
tue: undefined,
|
||||
wed: undefined,
|
||||
thu: undefined,
|
||||
fri: undefined,
|
||||
sat: undefined,
|
||||
sun: undefined,
|
||||
},
|
||||
seatsPassenger: 1,
|
||||
addresses: [mockAddressWithoutPos1, mockAddressWithoutPos2],
|
||||
schedule: {},
|
||||
};
|
||||
const newAdCommand = new CreateAdCommand(newPunctualPassengerAdRequest);
|
||||
await createAdUseCase.execute(newAdCommand);
|
||||
const expectedAdCreation = {
|
||||
userUuid: newPunctualPassengerAdRequest.userUuid,
|
||||
frequency: newPunctualPassengerAdRequest.frequency,
|
||||
fromDate: newPunctualPassengerAdRequest.departure,
|
||||
toDate: newPunctualPassengerAdRequest.departure,
|
||||
monTime: '09:36',
|
||||
tueTime: undefined,
|
||||
wedTime: undefined,
|
||||
thuTime: undefined,
|
||||
friTime: undefined,
|
||||
satTime: undefined,
|
||||
sunTime: undefined,
|
||||
monMargin: mockDefaultParamsProvider.getParams().MON_MARGIN,
|
||||
tueMargin: mockDefaultParamsProvider.getParams().TUE_MARGIN,
|
||||
wedMargin: mockDefaultParamsProvider.getParams().WED_MARGIN,
|
||||
thuMargin: mockDefaultParamsProvider.getParams().THU_MARGIN,
|
||||
friMargin: mockDefaultParamsProvider.getParams().FRI_MARGIN,
|
||||
satMargin: mockDefaultParamsProvider.getParams().SAT_MARGIN,
|
||||
sunMargin: mockDefaultParamsProvider.getParams().SUN_MARGIN,
|
||||
driver: false,
|
||||
seatsDriver: 0,
|
||||
passenger: newPunctualPassengerAdRequest.passenger,
|
||||
seatsPassenger: newPunctualPassengerAdRequest.seatsPassenger,
|
||||
strict: mockDefaultParamsProvider.getParams().STRICT,
|
||||
addresses: {
|
||||
create: newPunctualPassengerAdRequest.addresses as AddressCreation[],
|
||||
},
|
||||
createdAt: undefined,
|
||||
} as AdCreation;
|
||||
expect(mockAdRepository.create).toBeCalledWith(expectedAdCreation);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue