adding transformation pipes and update prisma schema
This commit is contained in:
parent
ad10320f5f
commit
fe315bbbd7
|
@ -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
|
||||
|
|
|
@ -41,6 +41,8 @@ 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);
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -8,7 +8,6 @@ import {
|
|||
MinLength,
|
||||
ValidateIf,
|
||||
} from 'class-validator';
|
||||
import { Frequency } from './frequency.enum';
|
||||
import { Address } from '../entities/address';
|
||||
|
||||
export class Ad {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
export enum Frequency {
|
||||
PUNCTUAL = 1,
|
||||
RECURRENT = 2,
|
||||
PUNCTUAL,
|
||||
RECURRENT,
|
||||
}
|
||||
|
|
|
@ -88,6 +88,7 @@ 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(
|
||||
|
|
Loading…
Reference in New Issue