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

View File

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

View File

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

View File

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

View File

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