food
This commit is contained in:
@@ -5,28 +5,33 @@ import { Type } from 'class-transformer';
|
||||
export class CreateFoodDto {
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
@ApiProperty({ example: '123e4567-e89b-12d3-a456-426614174000' })
|
||||
@ApiProperty()
|
||||
categoryId: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
@ApiPropertyOptional({ example: false })
|
||||
@Type(() => Boolean)
|
||||
breakfast?: boolean;
|
||||
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
@ApiPropertyOptional({ example: false })
|
||||
@Type(() => Boolean)
|
||||
tue?: boolean;
|
||||
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
@ApiPropertyOptional({ example: false })
|
||||
@Type(() => Boolean)
|
||||
wed?: boolean;
|
||||
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
@ApiPropertyOptional({ example: false })
|
||||
@Type(() => Boolean)
|
||||
thu?: boolean;
|
||||
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
@ApiPropertyOptional({ example: false })
|
||||
@@ -140,8 +145,8 @@ export class CreateFoodDto {
|
||||
discount?: number;
|
||||
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
@IsString({ each: true })
|
||||
@ApiPropertyOptional({ type: [String] })
|
||||
categoryIds?: string[];
|
||||
@IsBoolean()
|
||||
@ApiPropertyOptional({ example: false })
|
||||
@Type(() => Boolean)
|
||||
isSpecialOffer?: boolean;
|
||||
}
|
||||
|
||||
@@ -73,4 +73,7 @@ export class Food extends BaseEntity {
|
||||
|
||||
@Property({ type: 'float', default: 0 })
|
||||
discount: number = 0;
|
||||
|
||||
@Property({ type: 'boolean', default: false })
|
||||
isSpecialOffer: boolean = false;
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ export class FoodService {
|
||||
inPlaceServe: rest.inPlaceServe ?? false,
|
||||
pickupServe: rest.pickupServe ?? false,
|
||||
discount: rest.discount ?? 0,
|
||||
isSpecialOffer: rest.isSpecialOffer ?? false,
|
||||
// map single-title/content DTO to localized fields
|
||||
title: rest.title,
|
||||
content: rest.content,
|
||||
@@ -103,6 +104,10 @@ export class FoodService {
|
||||
this.em.assign(food, { category: category });
|
||||
}
|
||||
|
||||
// assign other fields from DTO
|
||||
const { categoryId, ...rest } = dto;
|
||||
this.em.assign(food, rest);
|
||||
|
||||
await this.em.persistAndFlush(food);
|
||||
return food;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user