fix dto frequency transformation

This commit is contained in:
Grégoire Chevalier 2023-05-10 15:44:25 +02:00
parent 5095082f2e
commit b83baef1ee
5 changed files with 27 additions and 33 deletions

View File

@ -41,8 +41,6 @@ export class AdController {
@GrpcMethod('AdsService', 'Create')
async createAd(data: CreateAdRequest): Promise<AdPresenter> {
console.log('controler');
console.log(data);
try {
const ad = await this._commandBus.execute(new CreateAdCommand(data));
return this._mapper.map(ad, Ad, AdPresenter);

View File

@ -7,6 +7,7 @@ import {
IsInt,
ValidateIf,
IsArray,
IsEnum,
} from 'class-validator';
import { Frequency } from '../entities/frequency.enum';
import { Address } from '../entities/address';
@ -34,7 +35,11 @@ export class CreateAdRequest {
@AutoMap()
passenger?: boolean;
@Transform(({ value }) => Frequency[value])
@Transform(
({ value }) => (value == 1 ? Frequency.PUNCTUAL : Frequency.RECURRENT),
{ toClassOnly: true },
)
@IsEnum(Frequency)
@AutoMap()
frequency: Frequency;
@ -48,47 +53,40 @@ export class CreateAdRequest {
@AutoMap()
toDate: Date;
@Type(() => Date)
@IsDate()
@IsOptional()
@AutoMap()
monTime?: Date;
monTime?: string;
@Type(() => Date)
@IsDate()
@IsString()
@IsOptional()
@AutoMap()
tueTime?: Date;
tueTime?: string;
@Type(() => Date)
@IsDate()
@IsString()
@IsOptional()
@AutoMap()
wedTime?: Date;
wedTime?: string;
@Type(() => Date)
@IsDate()
@IsString()
@IsOptional()
@AutoMap()
thuTime?: Date;
thuTime?: string;
@Type(() => Date)
@IsDate()
@IsString()
@IsOptional()
@AutoMap()
friTime?: Date;
friTime?: string;
@Type(() => Date)
@IsDate()
@IsString()
@IsOptional()
@AutoMap()
satTime?: Date;
satTime?: string;
@Type(() => Date)
@IsDate()
@IsString()
@IsOptional()
@AutoMap()
sunTime?: Date;
sunTime?: string;
@IsInt()
@IsOptional()

View File

@ -1,4 +1,4 @@
export enum Frequency {
PUNCTUAL,
RECURRENT,
PUNCTUAL = 'PUNCTUAL',
RECURRENT = 'RECURRENT',
}

View File

@ -19,12 +19,12 @@ export class AdProfile extends AutomapperProfile {
mapper,
CreateAdRequest,
Ad,
forMember(
(dest) => dest.frequency,
mapFrom((source) =>
source.frequency == Frequency.PUNCTUAL ? 'PUNCTUAL' : 'RECCURENT',
),
),
// forMember(
// (dest) => dest.frequency,
// mapFrom((source) =>
// source.frequency == Frequency.PUNCTUAL ? 'PUNCTUAL' : 'RECCURENT',
// ),
// ),
);
};
}

View File

@ -88,8 +88,6 @@ export abstract class PrismaRepository<T> implements IRepository<T> {
return res;
} catch (e) {
console.log('repository');
console.log(e);
if (e instanceof Prisma.PrismaClientKnownRequestError) {
throw new DatabaseException(
Prisma.PrismaClientKnownRequestError.name,