adding transformation pipes and update prisma schema
This commit is contained in:
parent
ad10320f5f
commit
fe315bbbd7
|
@ -13,11 +13,11 @@ datasource db {
|
||||||
model Ad {
|
model Ad {
|
||||||
uuid String @id @default(uuid()) @db.Uuid
|
uuid String @id @default(uuid()) @db.Uuid
|
||||||
userUuid String @db.Uuid
|
userUuid String @db.Uuid
|
||||||
driver Boolean?
|
driver Boolean
|
||||||
passenger Boolean?
|
passenger Boolean
|
||||||
frequency Frequency @default(RECURRENT)
|
frequency Frequency @default(RECURRENT)
|
||||||
fromDate DateTime @db.Date
|
fromDate DateTime @db.Date
|
||||||
toDate DateTime? @db.Date
|
toDate DateTime @db.Date
|
||||||
monTime DateTime? @db.Timestamptz()
|
monTime DateTime? @db.Timestamptz()
|
||||||
tueTime DateTime? @db.Timestamptz()
|
tueTime DateTime? @db.Timestamptz()
|
||||||
wedTime DateTime? @db.Timestamptz()
|
wedTime DateTime? @db.Timestamptz()
|
||||||
|
@ -32,8 +32,8 @@ model Ad {
|
||||||
friMargin Int?
|
friMargin Int?
|
||||||
satMargin Int?
|
satMargin Int?
|
||||||
sunMargin Int?
|
sunMargin Int?
|
||||||
seatsDriver Int? @db.SmallInt
|
seatsDriver Int @db.SmallInt
|
||||||
seatsPassenger Int? @db.SmallInt
|
seatsPassenger Int @db.SmallInt
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @default(now()) @updatedAt
|
updatedAt DateTime @default(now()) @updatedAt
|
||||||
addresses Address[]
|
addresses Address[]
|
||||||
|
@ -70,6 +70,7 @@ enum Frequency {
|
||||||
}
|
}
|
||||||
|
|
||||||
enum AddressType {
|
enum AddressType {
|
||||||
|
NAME
|
||||||
HOUSE_NUMBER
|
HOUSE_NUMBER
|
||||||
STREET_ADDRESS
|
STREET_ADDRESS
|
||||||
LOCALITY
|
LOCALITY
|
||||||
|
|
|
@ -41,6 +41,8 @@ export class AdController {
|
||||||
|
|
||||||
@GrpcMethod('AdsService', 'Create')
|
@GrpcMethod('AdsService', 'Create')
|
||||||
async createAd(data: CreateAdRequest): Promise<AdPresenter> {
|
async createAd(data: CreateAdRequest): Promise<AdPresenter> {
|
||||||
|
console.log('controler');
|
||||||
|
console.log(data);
|
||||||
try {
|
try {
|
||||||
const ad = await this._commandBus.execute(new CreateAdCommand(data));
|
const ad = await this._commandBus.execute(new CreateAdCommand(data));
|
||||||
return this._mapper.map(ad, Ad, AdPresenter);
|
return this._mapper.map(ad, Ad, AdPresenter);
|
||||||
|
|
|
@ -6,12 +6,11 @@ import {
|
||||||
IsDate,
|
IsDate,
|
||||||
IsInt,
|
IsInt,
|
||||||
ValidateIf,
|
ValidateIf,
|
||||||
ArrayMinSize,
|
|
||||||
IsArray,
|
IsArray,
|
||||||
IsEnum,
|
|
||||||
} from 'class-validator';
|
} from 'class-validator';
|
||||||
import { Frequency } from '../entities/frequency.enum';
|
import { Frequency } from '../entities/frequency.enum';
|
||||||
import { Address } from '../entities/address';
|
import { Address } from '../entities/address';
|
||||||
|
import { Transform, Type } from 'class-transformer';
|
||||||
|
|
||||||
export class CreateAdRequest {
|
export class CreateAdRequest {
|
||||||
@IsString()
|
@IsString()
|
||||||
|
@ -35,48 +34,57 @@ export class CreateAdRequest {
|
||||||
@AutoMap()
|
@AutoMap()
|
||||||
passenger?: boolean;
|
passenger?: boolean;
|
||||||
|
|
||||||
|
@Transform(({ value }) => Frequency[value])
|
||||||
@AutoMap()
|
@AutoMap()
|
||||||
@IsEnum(Frequency)
|
|
||||||
frequency: Frequency;
|
frequency: Frequency;
|
||||||
|
|
||||||
|
@Type(() => Date)
|
||||||
@IsDate()
|
@IsDate()
|
||||||
@AutoMap()
|
@AutoMap()
|
||||||
fromDate: Date;
|
fromDate: Date;
|
||||||
|
|
||||||
|
@Type(() => Date)
|
||||||
@IsDate()
|
@IsDate()
|
||||||
@AutoMap()
|
@AutoMap()
|
||||||
toDate: Date;
|
toDate: Date;
|
||||||
|
|
||||||
|
@Type(() => Date)
|
||||||
@IsDate()
|
@IsDate()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@AutoMap()
|
@AutoMap()
|
||||||
monTime?: Date;
|
monTime?: Date;
|
||||||
|
|
||||||
|
@Type(() => Date)
|
||||||
@IsDate()
|
@IsDate()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@AutoMap()
|
@AutoMap()
|
||||||
tueTime?: Date;
|
tueTime?: Date;
|
||||||
|
|
||||||
|
@Type(() => Date)
|
||||||
@IsDate()
|
@IsDate()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@AutoMap()
|
@AutoMap()
|
||||||
wedTime?: Date;
|
wedTime?: Date;
|
||||||
|
|
||||||
|
@Type(() => Date)
|
||||||
@IsDate()
|
@IsDate()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@AutoMap()
|
@AutoMap()
|
||||||
thuTime?: Date;
|
thuTime?: Date;
|
||||||
|
|
||||||
|
@Type(() => Date)
|
||||||
@IsDate()
|
@IsDate()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@AutoMap()
|
@AutoMap()
|
||||||
friTime?: Date;
|
friTime?: Date;
|
||||||
|
|
||||||
|
@Type(() => Date)
|
||||||
@IsDate()
|
@IsDate()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@AutoMap()
|
@AutoMap()
|
||||||
satTime?: Date;
|
satTime?: Date;
|
||||||
|
|
||||||
|
@Type(() => Date)
|
||||||
@IsDate()
|
@IsDate()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@AutoMap()
|
@AutoMap()
|
||||||
|
@ -128,12 +136,12 @@ export class CreateAdRequest {
|
||||||
@IsInt()
|
@IsInt()
|
||||||
@AutoMap()
|
@AutoMap()
|
||||||
seatsPassenger?: number;
|
seatsPassenger?: number;
|
||||||
|
@Type(() => Date)
|
||||||
@IsDate()
|
@IsDate()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@AutoMap()
|
@AutoMap()
|
||||||
createdAt?: Date;
|
createdAt?: Date;
|
||||||
|
@Type(() => Date)
|
||||||
@IsDate()
|
@IsDate()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@AutoMap()
|
@AutoMap()
|
||||||
|
|
|
@ -8,7 +8,6 @@ import {
|
||||||
MinLength,
|
MinLength,
|
||||||
ValidateIf,
|
ValidateIf,
|
||||||
} from 'class-validator';
|
} from 'class-validator';
|
||||||
import { Frequency } from './frequency.enum';
|
|
||||||
import { Address } from '../entities/address';
|
import { Address } from '../entities/address';
|
||||||
|
|
||||||
export class Ad {
|
export class Ad {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
export enum Frequency {
|
export enum Frequency {
|
||||||
PUNCTUAL = 1,
|
PUNCTUAL,
|
||||||
RECURRENT = 2,
|
RECURRENT,
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,6 +88,7 @@ export abstract class PrismaRepository<T> implements IRepository<T> {
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
console.log('repository');
|
||||||
console.log(e);
|
console.log(e);
|
||||||
if (e instanceof Prisma.PrismaClientKnownRequestError) {
|
if (e instanceof Prisma.PrismaClientKnownRequestError) {
|
||||||
throw new DatabaseException(
|
throw new DatabaseException(
|
||||||
|
|
Loading…
Reference in New Issue