diff --git a/prisma/schema.prisma b/prisma/schema.prisma index da4f4e3..429a9ef 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -13,11 +13,11 @@ datasource db { model Ad { uuid String @id @default(uuid()) @db.Uuid userUuid String @db.Uuid - driver Boolean? - passenger Boolean? + driver Boolean + passenger Boolean frequency Frequency @default(RECURRENT) fromDate DateTime @db.Date - toDate DateTime? @db.Date + toDate DateTime @db.Date monTime DateTime? @db.Timestamptz() tueTime DateTime? @db.Timestamptz() wedTime DateTime? @db.Timestamptz() @@ -32,8 +32,8 @@ model Ad { friMargin Int? satMargin Int? sunMargin Int? - seatsDriver Int? @db.SmallInt - seatsPassenger Int? @db.SmallInt + seatsDriver Int @db.SmallInt + seatsPassenger Int @db.SmallInt createdAt DateTime @default(now()) updatedAt DateTime @default(now()) @updatedAt addresses Address[] @@ -70,6 +70,7 @@ enum Frequency { } enum AddressType { + NAME HOUSE_NUMBER STREET_ADDRESS LOCALITY diff --git a/src/modules/ad/adapters/primaries/ad.controller.ts b/src/modules/ad/adapters/primaries/ad.controller.ts index ec2ca65..d0213d2 100644 --- a/src/modules/ad/adapters/primaries/ad.controller.ts +++ b/src/modules/ad/adapters/primaries/ad.controller.ts @@ -41,6 +41,8 @@ export class AdController { @GrpcMethod('AdsService', 'Create') async createAd(data: CreateAdRequest): Promise { + console.log('controler'); + console.log(data); try { const ad = await this._commandBus.execute(new CreateAdCommand(data)); return this._mapper.map(ad, Ad, AdPresenter); diff --git a/src/modules/ad/domain/dtos/create-ad.request.ts b/src/modules/ad/domain/dtos/create-ad.request.ts index 44e7225..8323e88 100644 --- a/src/modules/ad/domain/dtos/create-ad.request.ts +++ b/src/modules/ad/domain/dtos/create-ad.request.ts @@ -6,12 +6,11 @@ import { IsDate, IsInt, ValidateIf, - ArrayMinSize, IsArray, - IsEnum, } from 'class-validator'; import { Frequency } from '../entities/frequency.enum'; import { Address } from '../entities/address'; +import { Transform, Type } from 'class-transformer'; export class CreateAdRequest { @IsString() @@ -35,48 +34,57 @@ export class CreateAdRequest { @AutoMap() passenger?: boolean; + @Transform(({ value }) => Frequency[value]) @AutoMap() - @IsEnum(Frequency) frequency: Frequency; + @Type(() => Date) @IsDate() @AutoMap() fromDate: Date; + @Type(() => Date) @IsDate() @AutoMap() toDate: Date; + @Type(() => Date) @IsDate() @IsOptional() @AutoMap() monTime?: Date; + @Type(() => Date) @IsDate() @IsOptional() @AutoMap() tueTime?: Date; + @Type(() => Date) @IsDate() @IsOptional() @AutoMap() wedTime?: Date; + @Type(() => Date) @IsDate() @IsOptional() @AutoMap() thuTime?: Date; + @Type(() => Date) @IsDate() @IsOptional() @AutoMap() friTime?: Date; + @Type(() => Date) @IsDate() @IsOptional() @AutoMap() satTime?: Date; + @Type(() => Date) @IsDate() @IsOptional() @AutoMap() @@ -128,12 +136,12 @@ export class CreateAdRequest { @IsInt() @AutoMap() seatsPassenger?: number; - + @Type(() => Date) @IsDate() @IsOptional() @AutoMap() createdAt?: Date; - + @Type(() => Date) @IsDate() @IsOptional() @AutoMap() diff --git a/src/modules/ad/domain/entities/ad.ts b/src/modules/ad/domain/entities/ad.ts index 696895c..013dfc0 100644 --- a/src/modules/ad/domain/entities/ad.ts +++ b/src/modules/ad/domain/entities/ad.ts @@ -8,7 +8,6 @@ import { MinLength, ValidateIf, } from 'class-validator'; -import { Frequency } from './frequency.enum'; import { Address } from '../entities/address'; export class Ad { diff --git a/src/modules/ad/domain/entities/frequency.enum.ts b/src/modules/ad/domain/entities/frequency.enum.ts index ec435e8..6c571eb 100644 --- a/src/modules/ad/domain/entities/frequency.enum.ts +++ b/src/modules/ad/domain/entities/frequency.enum.ts @@ -1,4 +1,4 @@ export enum Frequency { - PUNCTUAL = 1, - RECURRENT = 2, + PUNCTUAL, + RECURRENT, } diff --git a/src/modules/database/adapters/secondaries/prisma-repository.abstract.ts b/src/modules/database/adapters/secondaries/prisma-repository.abstract.ts index 7346e3c..699ab86 100644 --- a/src/modules/database/adapters/secondaries/prisma-repository.abstract.ts +++ b/src/modules/database/adapters/secondaries/prisma-repository.abstract.ts @@ -88,6 +88,7 @@ export abstract class PrismaRepository implements IRepository { return res; } catch (e) { + console.log('repository'); console.log(e); if (e instanceof Prisma.PrismaClientKnownRequestError) { throw new DatabaseException(