From f0913840f20d007ecbb2015fb0f90512440d72ff Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Sat, 15 Nov 2025 11:35:46 +0330 Subject: [PATCH] food --- src/modules/foods/dto/create-food.dto.ts | 33 ++++++++++++------- src/modules/foods/entities/food.entity.ts | 11 +++---- src/modules/foods/providers/food.service.ts | 11 ++++--- .../restaurants/entities/schedule.entity.ts | 20 +++++++++++ 4 files changed, 53 insertions(+), 22 deletions(-) create mode 100644 src/modules/restaurants/entities/schedule.entity.ts diff --git a/src/modules/foods/dto/create-food.dto.ts b/src/modules/foods/dto/create-food.dto.ts index 31acb8c..018d1ca 100644 --- a/src/modules/foods/dto/create-food.dto.ts +++ b/src/modules/foods/dto/create-food.dto.ts @@ -37,93 +37,104 @@ export class CreateFoodDto { @IsOptional() @IsString() @ApiPropertyOptional({ example: 'توضیحات غذا' }) - content?: string; + desc?: string; + + @IsOptional() + @IsArray() + @IsString({ each: true }) + @ApiPropertyOptional({ type: [String] }) + content?: string[]; @IsOptional() @IsNumber() @Type(() => Number) @ApiPropertyOptional({ example: 120000 }) price?: number; + @IsOptional() @IsNumber() @Type(() => Number) @ApiPropertyOptional({ example: 10 }) points?: number; + @IsOptional() @IsNumber() @Type(() => Number) @ApiPropertyOptional({ example: 15 }) prepareTime?: number; + @IsOptional() @IsBoolean() @ApiPropertyOptional({ example: true }) @Type(() => Boolean) sat?: boolean; + @IsOptional() @IsBoolean() @ApiPropertyOptional({ example: true }) @Type(() => Boolean) sun?: boolean; + @IsOptional() @IsBoolean() @ApiPropertyOptional({ example: true }) @Type(() => Boolean) mon?: boolean; + @IsOptional() @IsBoolean() @ApiPropertyOptional({ example: false }) @Type(() => Boolean) noon?: boolean; + @IsOptional() @IsBoolean() @ApiPropertyOptional({ example: true }) @Type(() => Boolean) dinner?: boolean; - @IsOptional() - @IsBoolean() - @ApiPropertyOptional({ example: false }) - @Type(() => Boolean) - isPickup?: boolean; + @IsOptional() @IsNumber() @Type(() => Number) @ApiPropertyOptional({ example: 10 }) stock?: number; + @IsOptional() @IsNumber() @Type(() => Number) @ApiPropertyOptional({ example: 10 }) stockDefault?: number; + @IsOptional() @IsBoolean() @ApiPropertyOptional({ example: true }) @Type(() => Boolean) isActive?: boolean; + @IsOptional() @IsArray() @IsString({ each: true }) @ApiPropertyOptional({ type: [String] }) images?: string[]; + @IsOptional() @IsBoolean() @ApiPropertyOptional({ example: false }) @Type(() => Boolean) inPlaceServe?: boolean; + @IsOptional() @IsBoolean() @ApiPropertyOptional({ example: false }) @Type(() => Boolean) pickupServe?: boolean; - @IsOptional() - @IsNumber() - @Type(() => Number) - @ApiPropertyOptional({ example: 4.5 }) - rate?: number; + @IsOptional() @IsNumber() @Type(() => Number) @ApiPropertyOptional({ example: 0 }) discount?: number; + @IsOptional() @IsArray() @IsString({ each: true }) diff --git a/src/modules/foods/entities/food.entity.ts b/src/modules/foods/entities/food.entity.ts index c45f1a0..ae82dc7 100644 --- a/src/modules/foods/entities/food.entity.ts +++ b/src/modules/foods/entities/food.entity.ts @@ -11,7 +11,10 @@ export class Food extends BaseEntity { title?: string; @Property({ type: 'text', nullable: true }) - content?: string; + desc?: string; + + @Property({ type: 'json', nullable: true }) + content?: string[]; @Property({ type: 'decimal', precision: 10, scale: 2, nullable: true }) price?: number; @@ -43,9 +46,6 @@ export class Food extends BaseEntity { @Property({ type: 'boolean', default: false }) dinner: boolean = false; - @Property({ type: 'boolean', default: false }) - isPickup: boolean = false; - @Property({ type: 'int', default: 0 }) stock: number = 0; @@ -55,7 +55,6 @@ export class Food extends BaseEntity { @Property({ type: 'boolean', default: true }) isActive: boolean = true; - // you can store image URLs as JSON array @Property({ type: 'json', nullable: true }) images?: string[]; @@ -66,7 +65,7 @@ export class Food extends BaseEntity { pickupServe: boolean = false; @Property({ type: 'float', default: 0 }) - rate: number = 0; + rate?: number = 0; @Property({ type: 'float', default: 0 }) discount: number = 0; diff --git a/src/modules/foods/providers/food.service.ts b/src/modules/foods/providers/food.service.ts index 9fecb7d..40bb3a6 100644 --- a/src/modules/foods/providers/food.service.ts +++ b/src/modules/foods/providers/food.service.ts @@ -29,17 +29,15 @@ export class FoodService { noon: rest.noon ?? false, dinner: rest.dinner ?? false, // pickup/stock - isPickup: rest.isPickup ?? false, stock: rest.stock ?? 0, stockDefault: rest.stockDefault ?? 0, isActive: rest.isActive ?? true, inPlaceServe: rest.inPlaceServe ?? false, pickupServe: rest.pickupServe ?? false, - rate: rest.rate ?? 0, discount: rest.discount ?? 0, // map single-title/content DTO to localized fields - titleFa: rest.title, - contentFa: rest.content, + title: rest.title, + content: rest.content, // numeric/array fields price: rest.price ?? 0, points: rest.points ?? 0, @@ -47,7 +45,10 @@ export class FoodService { images: rest.images ?? undefined, } as RequiredEntityData; - const food = this.foodRepository.create(data); + const food = this.foodRepository.create(data) as Food; + if (!food) { + throw new Error('Failed to create food entity'); + } // attach categories if provided if (categoryIds && categoryIds.length) { diff --git a/src/modules/restaurants/entities/schedule.entity.ts b/src/modules/restaurants/entities/schedule.entity.ts new file mode 100644 index 0000000..ddae562 --- /dev/null +++ b/src/modules/restaurants/entities/schedule.entity.ts @@ -0,0 +1,20 @@ +import { Entity, Property } from '@mikro-orm/core'; +import { BaseEntity } from '../../../common/entities/base.entity'; + +@Entity({ tableName: 'restaurants' }) +export class Schedule extends BaseEntity { + @Property({ type: 'date' }) + date!: Date; + + @Property({ type: 'int' }) + openTime!: number; + + @Property({ type: 'int' }) + closeTime!: number; + + @Property({ default: true }) + isActive: boolean = true; + + @Property() + restId!: string; +}