update and sync prisma schema and create ad dto

This commit is contained in:
Grégoire Chevalier 2023-05-11 10:45:44 +02:00
parent 362452fc10
commit def8caa6e1
5 changed files with 55 additions and 81 deletions

View File

@ -17,7 +17,7 @@ model Ad {
passenger Boolean passenger Boolean
frequency Frequency frequency Frequency
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()
@ -25,23 +25,19 @@ model Ad {
friTime DateTime? @db.Timestamptz() friTime DateTime? @db.Timestamptz()
satTime DateTime? @db.Timestamptz() satTime DateTime? @db.Timestamptz()
sunTime DateTime? @db.Timestamptz() sunTime DateTime? @db.Timestamptz()
monMargin Int? monMargin Int
tueMargin Int? tueMargin Int
wedMargin Int? wedMargin Int
thuMargin Int? thuMargin Int
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[]
@@index([driver])
@@index([passenger])
@@index([fromDate])
@@index([toDate])
@@map("ad") @@map("ad")
} }
@ -56,8 +52,8 @@ model Address {
street String? street String?
locality String? locality String?
postalCode String? postalCode String?
country String? country String?
type AddressType? countryCode String?
createdAt DateTime @default(now()) createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt updatedAt DateTime @default(now()) @updatedAt
Ad Ad @relation(fields: [adUuid], references: [uuid], onDelete: Cascade) Ad Ad @relation(fields: [adUuid], references: [uuid], onDelete: Cascade)
@ -69,11 +65,3 @@ enum Frequency {
PUNCTUAL PUNCTUAL
RECURRENT RECURRENT
} }
enum AddressType {
HOUSE_NUMBER
STREET_ADDRESS
LOCALITY
VENUE
OTHER
}

View File

@ -6,51 +6,53 @@ import {
IsDate, IsDate,
IsInt, IsInt,
ValidateIf, ValidateIf,
IsArray,
IsEnum, IsEnum,
IsNumber, IsNumber,
ValidateNested, ValidateNested,
IsLongitude,
IsLatitude,
} from 'class-validator'; } from 'class-validator';
import { Frequency } from '../entities/frequency.enum'; import { Frequency } from '../entities/frequency.enum';
import { Transform, Type } from 'class-transformer'; import { Transform, Type } from 'class-transformer';
import { AddressType } from '../entities/address.enum'; import { AddressType } from '../entities/address.enum';
export class CreateAdRequest { export class CreateAdRequest {
@IsString()
@IsOptional()
@AutoMap()
uuid?: string;
@IsString() @IsString()
@AutoMap() @AutoMap()
userUuid: string; userUuid: string;
@ValidateIf((ad) => (ad.passenger ? false : true))
@IsOptional() @IsOptional()
@IsBoolean() @IsBoolean()
@AutoMap() @AutoMap()
driver?: boolean; driver?: boolean;
@ValidateIf((ad) => (ad.driver ? false : true))
@IsOptional() @IsOptional()
@IsBoolean() @IsBoolean()
@AutoMap() @AutoMap()
passenger?: boolean; passenger?: boolean;
@Transform(({ value }) => Frequency[value], { toClassOnly: true }) @Transform(({ value }) => Frequency[value - 1], { toClassOnly: true })
@IsEnum(Frequency) @IsEnum(Frequency)
@AutoMap() @AutoMap()
frequency: Frequency; frequency: Frequency;
@Type(() => Date) @Type(() => Date)
@IsDate() @IsDate()
@IsOptional()
@AutoMap() @AutoMap()
fromDate: Date; departure?: Date;
@Type(() => Date) @Type(() => Date)
@IsDate() @IsDate()
@IsOptional()
@AutoMap() @AutoMap()
toDate: Date; fromDate?: Date;
@Type(() => Date)
@IsDate()
@IsOptional()
@AutoMap()
toDate?: Date;
@IsDate() @IsDate()
@IsOptional() @IsOptional()
@ -122,14 +124,11 @@ export class CreateAdRequest {
@AutoMap() @AutoMap()
sunMargin?: number; sunMargin?: number;
@ValidateIf((ad) => (ad.passenger ? false : true))
@IsOptional() @IsOptional()
@IsInt() @IsInt()
@AutoMap() @AutoMap()
seatsDriver?: number; seatsDriver?: number;
@ValidateIf((ad) => (ad.driver ? false : true))
//@Transform(({ value }) => (value ? value : 0), { toClassOnly: true })
@IsOptional() @IsOptional()
@IsInt() @IsInt()
@AutoMap() @AutoMap()
@ -140,18 +139,6 @@ export class CreateAdRequest {
@AutoMap() @AutoMap()
strict?: boolean; strict?: boolean;
@Type(() => Date)
@IsDate()
@IsOptional()
@AutoMap()
createdAt?: Date;
@Type(() => Date)
@IsDate()
@IsOptional()
@AutoMap()
updatedAt?: Date;
@ValidateNested({ each: true }) @ValidateNested({ each: true })
@Transform( @Transform(
({ value }) => { ({ value }) => {
@ -167,15 +154,15 @@ export class CreateAdRequest {
} }
class AddressDTO { class AddressDTO {
@IsNumber() @IsInt()
@AutoMap() @AutoMap()
position: number; position: number;
@IsNumber() @IsLongitude()
@AutoMap() @AutoMap()
lon: number; lon: number;
@IsNumber() @IsLatitude()
@AutoMap() @AutoMap()
lat: number; lat: number;
@ -197,19 +184,20 @@ class AddressDTO {
@IsString() @IsString()
@IsOptional() @IsOptional()
@AutoMap() @AutoMap()
locality: string; locality?: string;
@IsString() @IsString()
@IsOptional() @IsOptional()
@AutoMap() @AutoMap()
postalCode: string; postalCode?: string;
@IsString() @IsString()
@IsOptional() @IsOptional()
@AutoMap() @AutoMap()
country: string; country?: string;
@Transform(({ value }) => AddressType[value], { toClassOnly: true }) @IsString()
@IsOptional()
@AutoMap() @AutoMap()
type: AddressType; countryCode?: string;
} }

View File

@ -5,10 +5,10 @@ import {
IsBoolean, IsBoolean,
IsDate, IsDate,
IsInt, IsInt,
MinLength, IsEnum,
ValidateIf,
} from 'class-validator'; } from 'class-validator';
import { Address } from '../entities/address'; import { Address } from '../entities/address';
import { Frequency } from './frequency.enum';
export class Ad { export class Ad {
@IsString() @IsString()
@ -19,59 +19,60 @@ export class Ad {
@AutoMap() @AutoMap()
userUuid: string; userUuid: string;
@ValidateIf((ad) => (ad.passenger ? false : true))
@IsBoolean() @IsBoolean()
@AutoMap() @AutoMap()
driver?: boolean; driver?: boolean;
@ValidateIf((ad) => (ad.driver ? false : true))
@IsBoolean() @IsBoolean()
@AutoMap() @AutoMap()
passenger?: boolean; passenger?: boolean;
@IsEnum(Frequency)
@AutoMap() @AutoMap()
frequency: string; frequency: Frequency;
@IsDate()
@AutoMap() @AutoMap()
fromDate: Date; fromDate: Date;
@IsDate()
@AutoMap() @AutoMap()
toDate: Date; toDate: Date;
@IsDate() @IsDate()
@IsOptional() @IsOptional()
@AutoMap() @AutoMap()
monTime?: Date; monTime?: string;
@IsDate() @IsString()
@IsOptional() @IsOptional()
@AutoMap() @AutoMap()
tueTime?: Date; tueTime?: string;
@IsDate() @IsString()
@IsOptional() @IsOptional()
@AutoMap() @AutoMap()
wedTime?: Date; wedTime?: string;
@IsDate() @IsString()
@IsOptional() @IsOptional()
@AutoMap() @AutoMap()
thuTime?: Date; thuTime?: string;
@IsDate() @IsString()
@IsOptional() @IsOptional()
@AutoMap() @AutoMap()
friTime?: Date; friTime?: string;
@IsDate() @IsString()
@IsOptional() @IsOptional()
@AutoMap() @AutoMap()
satTime?: Date; satTime?: string;
@IsDate() @IsString()
@IsOptional() @IsOptional()
@AutoMap() @AutoMap()
sunTime?: Date; sunTime?: string;
@IsInt() @IsInt()
@IsOptional() @IsOptional()
@ -108,12 +109,10 @@ export class Ad {
@AutoMap() @AutoMap()
sunMargin?: number; sunMargin?: number;
@ValidateIf((ad) => (ad.passenger ? false : true))
@IsInt() @IsInt()
@AutoMap() @AutoMap()
seatsDriver?: number; seatsDriver?: number;
@ValidateIf((ad) => (ad.driver ? false : true))
@IsInt() @IsInt()
@AutoMap() @AutoMap()
seatsPassenger?: number; seatsPassenger?: number;
@ -127,7 +126,6 @@ export class Ad {
@AutoMap() @AutoMap()
updatedAt?: Date; updatedAt?: Date;
@MinLength(2)
@AutoMap() @AutoMap()
addresses?: Array<Address>; addresses?: Array<Address>;
} }

View File

@ -1,5 +1,5 @@
export enum AddressType { export enum AddressType {
HOUSE_NUMBER = 1, HOUSE_NUMBER,
STREET_ADDRESS, STREET_ADDRESS,
LOCALITY, LOCALITY,
VENUE, VENUE,

View File

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