food
This commit is contained in:
@@ -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 })
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<Food>;
|
||||
|
||||
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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user