Skip to content

Commit

Permalink
fix: add flag optionnal on field
Browse files Browse the repository at this point in the history
  • Loading branch information
Xantass committed Nov 5, 2024
1 parent 7fd405f commit 5c539dc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/modules/food/DTO/food.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IsString, IsNotEmpty, IsNumber, IsArray } from 'class-validator';
import { IsString, IsNotEmpty, IsNumber, IsArray, IsOptional } from 'class-validator';

export class FoodDto {
@IsString()
Expand All @@ -13,10 +13,12 @@ export class FoodDto {
@IsNotEmpty()
id_category: number;

@IsOptional()
@IsArray()
@IsNumber({}, { each: true })
ingredients: number[];

@IsOptional()
@IsArray()
@IsNumber({}, { each: true })
details: number[];
Expand Down
4 changes: 3 additions & 1 deletion src/modules/ingredient/DTO/ingredient.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IsString, IsNotEmpty, IsNumber } from 'class-validator';
import { IsString, IsNotEmpty, IsNumber, IsOptional } from 'class-validator';

export class IngredientDto {
@IsString()
Expand All @@ -9,9 +9,11 @@ export class IngredientDto {
@IsNotEmpty()
price: number;

@IsOptional()
@IsNumber()
quantity: number;

@IsOptional()
@IsString()
unit: string;
}
6 changes: 6 additions & 0 deletions src/modules/orders/DTO/food_ordered.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
IsObject,
ValidateNested,
IsEnum,
IsEmpty,
IsOptional,
} from 'class-validator';

enum ModsIngredientType {
Expand Down Expand Up @@ -35,18 +37,22 @@ export class FoodOrderedDto {
@IsNotEmpty()
is_ready: boolean;

@IsOptional()
@IsNumber()
part: number;

@IsOptional()
@IsArray()
@ValidateNested({ each: true })
@Type(() => ModsIngredient)
mods_ingredients: ModsIngredient[];

@IsOptional()
@IsArray()
@IsString({ each: true })
details: string[];

@IsOptional()
@IsString()
note: string;
}
8 changes: 6 additions & 2 deletions src/modules/orders/DTO/orders.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { IsString, IsNotEmpty, IsNumber, IsArray, IsEnum } from 'class-validator';
import { IsString, IsNotEmpty, IsNumber, IsArray, IsEnum, ValidateNested } from 'class-validator';
import { FoodOrderedDto } from './food_ordered.dto';
import { Type } from 'class-transformer';

enum Channel {
TYPE1 = 'Sur place',
Expand All @@ -24,6 +25,9 @@ export class OrdersDto {
@IsNotEmpty()
part: number;

@IsArray({ each: true })
@IsNotEmpty()
@IsArray()
@ValidateNested({ each: true })
@Type(() => FoodOrderedDto)
food_ordered: FoodOrderedDto[];
}

0 comments on commit 5c539dc

Please sign in to comment.