pretty, lint
This commit is contained in:
parent
106c225ee3
commit
3cf2667f92
|
@ -155,17 +155,17 @@ The app exposes the following [gRPC](https://grpc.io/) services :
|
|||
{
|
||||
"day": 1,
|
||||
"time": "07:00",
|
||||
"margin": 600,
|
||||
"margin": 600
|
||||
},
|
||||
{
|
||||
"day": 2,
|
||||
"time": "07:05",
|
||||
"margin": 600,
|
||||
"margin": 600
|
||||
},
|
||||
{
|
||||
"day": 5,
|
||||
"time": "07:10",
|
||||
"margin": 600,
|
||||
"margin": 600
|
||||
}
|
||||
],
|
||||
"waypoints": [
|
||||
|
|
|
@ -26,10 +26,14 @@ import { HEALTH_CRITICAL_LOGGING_KEY, SERVICE_NAME } from './app.constants';
|
|||
useFactory: async (
|
||||
configService: ConfigService,
|
||||
): Promise<ConfigurationModuleOptions> => ({
|
||||
domain: configService.get<string>('SERVICE_CONFIGURATION_DOMAIN') as string,
|
||||
domain: configService.get<string>(
|
||||
'SERVICE_CONFIGURATION_DOMAIN',
|
||||
) as string,
|
||||
messageBroker: {
|
||||
uri: configService.get<string>('MESSAGE_BROKER_URI') as string,
|
||||
exchange: configService.get<string>('MESSAGE_BROKER_EXCHANGE') as string,
|
||||
exchange: configService.get<string>(
|
||||
'MESSAGE_BROKER_EXCHANGE',
|
||||
) as string,
|
||||
},
|
||||
redis: {
|
||||
host: configService.get<string>('REDIS_HOST') as string,
|
||||
|
|
|
@ -81,11 +81,6 @@ const adapters: Provider[] = [
|
|||
...orms,
|
||||
...adapters,
|
||||
],
|
||||
exports: [
|
||||
PrismaService,
|
||||
AdMapper,
|
||||
AD_REPOSITORY,
|
||||
TIMEZONE_FINDER,
|
||||
],
|
||||
exports: [PrismaService, AdMapper, AD_REPOSITORY, TIMEZONE_FINDER],
|
||||
})
|
||||
export class AdModule {}
|
||||
|
|
|
@ -15,26 +15,48 @@ import { DateTimeTransformerPort } from '../../ports/datetime-transformer.port';
|
|||
|
||||
@CommandHandler(CreateAdCommand)
|
||||
export class CreateAdService implements ICommandHandler {
|
||||
|
||||
constructor(
|
||||
@Inject(AD_REPOSITORY)
|
||||
private readonly repository: AdRepositoryPort,
|
||||
@Inject(INPUT_DATETIME_TRANSFORMER)
|
||||
private readonly datetimeTransformer: DateTimeTransformerPort,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
async execute(command: CreateAdCommand): Promise<AggregateID> {
|
||||
const ad = AdEntity.create(
|
||||
{
|
||||
userId: command.userId,
|
||||
driver: command.driver,
|
||||
passenger: command.passenger,
|
||||
frequency: command.frequency,
|
||||
fromDate: this.datetimeTransformer.fromDate(
|
||||
const ad = AdEntity.create({
|
||||
userId: command.userId,
|
||||
driver: command.driver,
|
||||
passenger: command.passenger,
|
||||
frequency: command.frequency,
|
||||
fromDate: this.datetimeTransformer.fromDate(
|
||||
{
|
||||
date: command.fromDate,
|
||||
time: command.schedule[0].time,
|
||||
coordinates: {
|
||||
lon: command.waypoints[0].lon,
|
||||
lat: command.waypoints[0].lat,
|
||||
},
|
||||
},
|
||||
command.frequency,
|
||||
),
|
||||
toDate: this.datetimeTransformer.toDate(
|
||||
command.toDate,
|
||||
{
|
||||
date: command.fromDate,
|
||||
time: command.schedule[0].time,
|
||||
coordinates: {
|
||||
lon: command.waypoints[0].lon,
|
||||
lat: command.waypoints[0].lat,
|
||||
},
|
||||
},
|
||||
command.frequency,
|
||||
),
|
||||
schedule: command.schedule.map((scheduleItem: ScheduleItem) => ({
|
||||
day: this.datetimeTransformer.day(
|
||||
scheduleItem.day,
|
||||
{
|
||||
date: command.fromDate,
|
||||
time: command.schedule[0].time,
|
||||
time: scheduleItem.time,
|
||||
coordinates: {
|
||||
lon: command.waypoints[0].lon,
|
||||
lat: command.waypoints[0].lat,
|
||||
|
@ -42,11 +64,10 @@ export class CreateAdService implements ICommandHandler {
|
|||
},
|
||||
command.frequency,
|
||||
),
|
||||
toDate: this.datetimeTransformer.toDate(
|
||||
command.toDate,
|
||||
time: this.datetimeTransformer.time(
|
||||
{
|
||||
date: command.fromDate,
|
||||
time: command.schedule[0].time,
|
||||
time: scheduleItem.time,
|
||||
coordinates: {
|
||||
lon: command.waypoints[0].lon,
|
||||
lat: command.waypoints[0].lat,
|
||||
|
@ -54,52 +75,27 @@ export class CreateAdService implements ICommandHandler {
|
|||
},
|
||||
command.frequency,
|
||||
),
|
||||
schedule: command.schedule.map((scheduleItem: ScheduleItem) => ({
|
||||
day: this.datetimeTransformer.day(
|
||||
scheduleItem.day,
|
||||
{
|
||||
date: command.fromDate,
|
||||
time: scheduleItem.time,
|
||||
coordinates: {
|
||||
lon: command.waypoints[0].lon,
|
||||
lat: command.waypoints[0].lat,
|
||||
},
|
||||
},
|
||||
command.frequency,
|
||||
),
|
||||
time: this.datetimeTransformer.time(
|
||||
{
|
||||
date: command.fromDate,
|
||||
time: scheduleItem.time,
|
||||
coordinates: {
|
||||
lon: command.waypoints[0].lon,
|
||||
lat: command.waypoints[0].lat,
|
||||
},
|
||||
},
|
||||
command.frequency,
|
||||
),
|
||||
margin: scheduleItem.margin,
|
||||
})),
|
||||
seatsProposed: command.seatsProposed ?? 0,
|
||||
seatsRequested: command.seatsRequested ?? 0,
|
||||
strict: command.strict,
|
||||
waypoints: command.waypoints.map((waypoint: Waypoint) => ({
|
||||
position: waypoint.position,
|
||||
address: {
|
||||
name: waypoint.name,
|
||||
houseNumber: waypoint.houseNumber,
|
||||
street: waypoint.street,
|
||||
postalCode: waypoint.postalCode,
|
||||
locality: waypoint.locality,
|
||||
country: waypoint.country,
|
||||
coordinates: {
|
||||
lon: waypoint.lon,
|
||||
lat: waypoint.lat,
|
||||
},
|
||||
margin: scheduleItem.margin,
|
||||
})),
|
||||
seatsProposed: command.seatsProposed ?? 0,
|
||||
seatsRequested: command.seatsRequested ?? 0,
|
||||
strict: command.strict,
|
||||
waypoints: command.waypoints.map((waypoint: Waypoint) => ({
|
||||
position: waypoint.position,
|
||||
address: {
|
||||
name: waypoint.name,
|
||||
houseNumber: waypoint.houseNumber,
|
||||
street: waypoint.street,
|
||||
postalCode: waypoint.postalCode,
|
||||
locality: waypoint.locality,
|
||||
country: waypoint.country,
|
||||
coordinates: {
|
||||
lon: waypoint.lon,
|
||||
lat: waypoint.lat,
|
||||
},
|
||||
})),
|
||||
},
|
||||
);
|
||||
},
|
||||
})),
|
||||
});
|
||||
|
||||
try {
|
||||
await this.repository.insert(ad);
|
||||
|
|
|
@ -8,9 +8,7 @@ import { WaypointProps } from './value-objects/waypoint.value-object';
|
|||
export class AdEntity extends AggregateRoot<AdProps> {
|
||||
protected readonly _id: AggregateID;
|
||||
|
||||
static create = (
|
||||
create: CreateAdProps
|
||||
): AdEntity => {
|
||||
static create = (create: CreateAdProps): AdEntity => {
|
||||
const id = v4();
|
||||
const props: AdProps = { ...create };
|
||||
const ad = new AdEntity({ id, props });
|
||||
|
|
|
@ -5,10 +5,7 @@ import {
|
|||
GeoDateTime,
|
||||
} from '../core/application/ports/datetime-transformer.port';
|
||||
import { TimeConverterPort } from '../core/application/ports/time-converter.port';
|
||||
import {
|
||||
TIMEZONE_FINDER,
|
||||
TIME_CONVERTER,
|
||||
} from '../ad.di-tokens';
|
||||
import { TIMEZONE_FINDER, TIME_CONVERTER } from '../ad.di-tokens';
|
||||
import { TimezoneFinderPort } from '../core/application/ports/timezone-finder.port';
|
||||
|
||||
@Injectable()
|
||||
|
@ -17,8 +14,7 @@ export class InputDateTimeTransformer implements DateTimeTransformerPort {
|
|||
@Inject(TIMEZONE_FINDER)
|
||||
private readonly timezoneFinder: TimezoneFinderPort,
|
||||
@Inject(TIME_CONVERTER) private readonly timeConverter: TimeConverterPort,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Compute the fromDate : if an ad is punctual, the departure date
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { INestApplication, Injectable, OnModuleInit } from '@nestjs/common';
|
||||
import { Injectable, OnModuleInit } from '@nestjs/common';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
@Injectable()
|
||||
|
|
|
@ -4,8 +4,5 @@ import { TimezoneFinderPort } from '../core/application/ports/timezone-finder.po
|
|||
|
||||
@Injectable()
|
||||
export class TimezoneFinder implements TimezoneFinderPort {
|
||||
timezones = (
|
||||
lon: number,
|
||||
lat: number,
|
||||
): string[] => find(lat, lon);
|
||||
timezones = (lon: number, lat: number): string[] => find(lat, lon);
|
||||
}
|
||||
|
|
|
@ -24,16 +24,16 @@ export class CreateAdRequestDto {
|
|||
|
||||
@IsBoolean()
|
||||
@HasRole('passenger', {
|
||||
message: 'At least one of driver or passenger property needs to be truthy'
|
||||
message: 'At least one of driver or passenger property needs to be truthy',
|
||||
})
|
||||
@HasSeats('seatsProposed', {
|
||||
message: 'Number of seats proposed as a driver is required'
|
||||
message: 'Number of seats proposed as a driver is required',
|
||||
})
|
||||
driver: boolean;
|
||||
|
||||
@IsBoolean()
|
||||
@HasSeats('seatsRequested', {
|
||||
message: 'Number of seats requested as a passenger is required'
|
||||
message: 'Number of seats requested as a passenger is required',
|
||||
})
|
||||
passenger: boolean;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { IsOptional, IsMilitaryTime, IsInt, Min, Max } from 'class-validator';
|
||||
import { IsMilitaryTime, IsInt, Min, Max } from 'class-validator';
|
||||
|
||||
export class ScheduleItemDto {
|
||||
@IsInt()
|
||||
|
|
|
@ -19,7 +19,7 @@ export function HasRole(
|
|||
validate(value: any, args: ValidationArguments) {
|
||||
const [relatedPropertyName] = args.constraints;
|
||||
const relatedValue = (args.object as any)[relatedPropertyName];
|
||||
return value || relatedValue;
|
||||
return value || relatedValue;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
|
|
@ -19,7 +19,7 @@ export function HasSeats(
|
|||
validate(value: any, args: ValidationArguments) {
|
||||
const [relatedPropertyName] = args.constraints;
|
||||
const relatedValue = (args.object as any)[relatedPropertyName];
|
||||
return (value && relatedValue>0) || !value;
|
||||
return (value && relatedValue > 0) || !value;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { IsInt, IsOptional } from 'class-validator';
|
||||
import { IsInt } from 'class-validator';
|
||||
import { AddressDto } from './address.dto';
|
||||
|
||||
export class WaypointDto extends AddressDto {
|
||||
|
|
|
@ -7,10 +7,7 @@ import {
|
|||
} from '@modules/ad/ad.di-tokens';
|
||||
import { AdMapper } from '@modules/ad/ad.mapper';
|
||||
import { AdEntity } from '@modules/ad/core/domain/ad.entity';
|
||||
import {
|
||||
CreateAdProps,
|
||||
Frequency,
|
||||
} from '@modules/ad/core/domain/ad.types';
|
||||
import { CreateAdProps, Frequency } from '@modules/ad/core/domain/ad.types';
|
||||
import { AdRepository } from '@modules/ad/infrastructure/ad.repository';
|
||||
import { OutputDateTimeTransformer } from '@modules/ad/infrastructure/output-datetime-transformer';
|
||||
import { PrismaService } from '@modules/ad/infrastructure/prisma.service';
|
||||
|
@ -230,9 +227,7 @@ describe('Ad Repository', () => {
|
|||
],
|
||||
};
|
||||
|
||||
const adToCreate: AdEntity = AdEntity.create(
|
||||
createAdProps,
|
||||
);
|
||||
const adToCreate: AdEntity = AdEntity.create(createAdProps);
|
||||
await adRepository.insert(adToCreate);
|
||||
|
||||
const afterCount = await prismaService.ad.count();
|
||||
|
@ -308,9 +303,7 @@ describe('Ad Repository', () => {
|
|||
],
|
||||
};
|
||||
|
||||
const adToCreate: AdEntity = AdEntity.create(
|
||||
createAdProps,
|
||||
);
|
||||
const adToCreate: AdEntity = AdEntity.create(createAdProps);
|
||||
await adRepository.insert(adToCreate);
|
||||
|
||||
const afterCount = await prismaService.ad.count();
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
import { AdEntity } from '@modules/ad/core/domain/ad.entity';
|
||||
import {
|
||||
CreateAdProps,
|
||||
Frequency,
|
||||
} from '@modules/ad/core/domain/ad.types';
|
||||
import { CreateAdProps, Frequency } from '@modules/ad/core/domain/ad.types';
|
||||
import { WaypointProps } from '@modules/ad/core/domain/value-objects/waypoint.value-object';
|
||||
|
||||
const originWaypointProps: WaypointProps = {
|
||||
|
|
|
@ -102,9 +102,8 @@ describe('create-ad.service', () => {
|
|||
AdEntity.create = jest.fn().mockReturnValue({
|
||||
id: '047a6ecf-23d4-4d3e-877c-3225d560a8da',
|
||||
});
|
||||
const result: AggregateID = await createAdService.execute(
|
||||
createAdCommand,
|
||||
);
|
||||
const result: AggregateID =
|
||||
await createAdService.execute(createAdCommand);
|
||||
expect(result).toBe('047a6ecf-23d4-4d3e-877c-3225d560a8da');
|
||||
});
|
||||
it('should throw an error if something bad happens', async () => {
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
import { AD_REPOSITORY } from '@modules/ad/ad.di-tokens';
|
||||
import { AdEntity } from '@modules/ad/core/domain/ad.entity';
|
||||
import {
|
||||
CreateAdProps,
|
||||
Frequency,
|
||||
} from '@modules/ad/core/domain/ad.types';
|
||||
import { CreateAdProps, Frequency } from '@modules/ad/core/domain/ad.types';
|
||||
import { FindAdByIdQuery } from '@modules/ad/core/application/queries/find-ad-by-id/find-ad-by-id.query';
|
||||
import { FindAdByIdQueryHandler } from '@modules/ad/core/application/queries/find-ad-by-id/find-ad-by-id.query-handler';
|
||||
import { WaypointProps } from '@modules/ad/core/domain/value-objects/waypoint.value-object';
|
||||
|
@ -59,9 +56,7 @@ const punctualPassengerCreateAdProps: CreateAdProps = {
|
|||
passenger: true,
|
||||
};
|
||||
|
||||
const ad: AdEntity = AdEntity.create(
|
||||
punctualPassengerCreateAdProps,
|
||||
);
|
||||
const ad: AdEntity = AdEntity.create(punctualPassengerCreateAdProps);
|
||||
|
||||
const mockAdRepository = {
|
||||
findOneById: jest.fn().mockImplementation(() => ad),
|
||||
|
@ -95,9 +90,8 @@ describe('find-ad-by-id.query-handler', () => {
|
|||
const findAdbyIdQuery = new FindAdByIdQuery(
|
||||
'dd264806-13b4-4226-9b18-87adf0ad5dd1',
|
||||
);
|
||||
const ad: AdEntity = await findAdByIdQueryHandler.execute(
|
||||
findAdbyIdQuery,
|
||||
);
|
||||
const ad: AdEntity =
|
||||
await findAdByIdQueryHandler.execute(findAdbyIdQuery);
|
||||
expect(ad.getProps().fromDate).toBe('2023-06-22');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
import {
|
||||
TIMEZONE_FINDER,
|
||||
TIME_CONVERTER,
|
||||
} from '@modules/ad/ad.di-tokens';
|
||||
import { TIMEZONE_FINDER, TIME_CONVERTER } from '@modules/ad/ad.di-tokens';
|
||||
import { Frequency } from '@modules/ad/core/application/ports/datetime-transformer.port';
|
||||
import { TimeConverterPort } from '@modules/ad/core/application/ports/time-converter.port';
|
||||
import { TimezoneFinderPort } from '@modules/ad/core/application/ports/timezone-finder.port';
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
import {
|
||||
TIMEZONE_FINDER,
|
||||
TIME_CONVERTER,
|
||||
} from '@modules/ad/ad.di-tokens';
|
||||
import { TIMEZONE_FINDER, TIME_CONVERTER } from '@modules/ad/ad.di-tokens';
|
||||
import { Frequency } from '@modules/ad/core/application/ports/datetime-transformer.port';
|
||||
import { TimeConverterPort } from '@modules/ad/core/application/ports/time-converter.port';
|
||||
import { TimezoneFinderPort } from '@modules/ad/core/application/ports/timezone-finder.port';
|
||||
|
|
|
@ -4,13 +4,13 @@ import { Validator } from 'class-validator';
|
|||
describe('has seats decorator', () => {
|
||||
class MyClass {
|
||||
@HasSeats('seatsProposed')
|
||||
driver:boolean;
|
||||
driver: boolean;
|
||||
@HasSeats('seatsRequested')
|
||||
passenger: boolean;
|
||||
|
||||
seatsProposed?: number;
|
||||
seatsRequested?: number;
|
||||
}
|
||||
}
|
||||
it('should return a property decorator has a function', () => {
|
||||
const hasSeats = HasSeats('property');
|
||||
expect(typeof hasSeats).toBe('function');
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { hasValidPositionIndexes } from "@modules/ad/interface/grpc-controllers/dtos/validators/has-valid-position-indexes.validator";
|
||||
import { WaypointDto } from "@modules/ad/interface/grpc-controllers/dtos/waypoint.dto";
|
||||
import { hasValidPositionIndexes } from '@modules/ad/interface/grpc-controllers/dtos/validators/has-valid-position-indexes.validator';
|
||||
import { WaypointDto } from '@modules/ad/interface/grpc-controllers/dtos/waypoint.dto';
|
||||
|
||||
describe('addresses position validator', () => {
|
||||
const waypoint1: WaypointDto = {
|
||||
|
|
|
@ -3,7 +3,11 @@ import { MESSAGE_PUBLISHER } from './messager.di-tokens';
|
|||
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
import { SERVICE_NAME } from '@src/app.constants';
|
||||
import { MessageBrokerModule, MessageBrokerModuleOptions, MessageBrokerPublisher } from '@mobicoop/message-broker-module';
|
||||
import {
|
||||
MessageBrokerModule,
|
||||
MessageBrokerModuleOptions,
|
||||
MessageBrokerPublisher,
|
||||
} from '@mobicoop/message-broker-module';
|
||||
|
||||
const imports = [
|
||||
MessageBrokerModule.forRootAsync({
|
||||
|
@ -15,7 +19,9 @@ const imports = [
|
|||
uri: configService.get<string>('MESSAGE_BROKER_URI') as string,
|
||||
exchange: {
|
||||
name: configService.get<string>('MESSAGE_BROKER_EXCHANGE') as string,
|
||||
durable: configService.get<boolean>('MESSAGE_BROKER_EXCHANGE_DURABILITY') as boolean
|
||||
durable: configService.get<boolean>(
|
||||
'MESSAGE_BROKER_EXCHANGE_DURABILITY',
|
||||
) as boolean,
|
||||
},
|
||||
name: SERVICE_NAME,
|
||||
}),
|
||||
|
|
Loading…
Reference in New Issue