food
This commit is contained in:
@@ -37,93 +37,104 @@ export class CreateFoodDto {
|
|||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
@ApiPropertyOptional({ example: 'توضیحات غذا' })
|
@ApiPropertyOptional({ example: 'توضیحات غذا' })
|
||||||
content?: string;
|
desc?: string;
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@IsArray()
|
||||||
|
@IsString({ each: true })
|
||||||
|
@ApiPropertyOptional({ type: [String] })
|
||||||
|
content?: string[];
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
@Type(() => Number)
|
@Type(() => Number)
|
||||||
@ApiPropertyOptional({ example: 120000 })
|
@ApiPropertyOptional({ example: 120000 })
|
||||||
price?: number;
|
price?: number;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
@Type(() => Number)
|
@Type(() => Number)
|
||||||
@ApiPropertyOptional({ example: 10 })
|
@ApiPropertyOptional({ example: 10 })
|
||||||
points?: number;
|
points?: number;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
@Type(() => Number)
|
@Type(() => Number)
|
||||||
@ApiPropertyOptional({ example: 15 })
|
@ApiPropertyOptional({ example: 15 })
|
||||||
prepareTime?: number;
|
prepareTime?: number;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
@ApiPropertyOptional({ example: true })
|
@ApiPropertyOptional({ example: true })
|
||||||
@Type(() => Boolean)
|
@Type(() => Boolean)
|
||||||
sat?: boolean;
|
sat?: boolean;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
@ApiPropertyOptional({ example: true })
|
@ApiPropertyOptional({ example: true })
|
||||||
@Type(() => Boolean)
|
@Type(() => Boolean)
|
||||||
sun?: boolean;
|
sun?: boolean;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
@ApiPropertyOptional({ example: true })
|
@ApiPropertyOptional({ example: true })
|
||||||
@Type(() => Boolean)
|
@Type(() => Boolean)
|
||||||
mon?: boolean;
|
mon?: boolean;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
@ApiPropertyOptional({ example: false })
|
@ApiPropertyOptional({ example: false })
|
||||||
@Type(() => Boolean)
|
@Type(() => Boolean)
|
||||||
noon?: boolean;
|
noon?: boolean;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
@ApiPropertyOptional({ example: true })
|
@ApiPropertyOptional({ example: true })
|
||||||
@Type(() => Boolean)
|
@Type(() => Boolean)
|
||||||
dinner?: boolean;
|
dinner?: boolean;
|
||||||
@IsOptional()
|
|
||||||
@IsBoolean()
|
|
||||||
@ApiPropertyOptional({ example: false })
|
|
||||||
@Type(() => Boolean)
|
|
||||||
isPickup?: boolean;
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
@Type(() => Number)
|
@Type(() => Number)
|
||||||
@ApiPropertyOptional({ example: 10 })
|
@ApiPropertyOptional({ example: 10 })
|
||||||
stock?: number;
|
stock?: number;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
@Type(() => Number)
|
@Type(() => Number)
|
||||||
@ApiPropertyOptional({ example: 10 })
|
@ApiPropertyOptional({ example: 10 })
|
||||||
stockDefault?: number;
|
stockDefault?: number;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
@ApiPropertyOptional({ example: true })
|
@ApiPropertyOptional({ example: true })
|
||||||
@Type(() => Boolean)
|
@Type(() => Boolean)
|
||||||
isActive?: boolean;
|
isActive?: boolean;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsArray()
|
@IsArray()
|
||||||
@IsString({ each: true })
|
@IsString({ each: true })
|
||||||
@ApiPropertyOptional({ type: [String] })
|
@ApiPropertyOptional({ type: [String] })
|
||||||
images?: string[];
|
images?: string[];
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
@ApiPropertyOptional({ example: false })
|
@ApiPropertyOptional({ example: false })
|
||||||
@Type(() => Boolean)
|
@Type(() => Boolean)
|
||||||
inPlaceServe?: boolean;
|
inPlaceServe?: boolean;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
@ApiPropertyOptional({ example: false })
|
@ApiPropertyOptional({ example: false })
|
||||||
@Type(() => Boolean)
|
@Type(() => Boolean)
|
||||||
pickupServe?: boolean;
|
pickupServe?: boolean;
|
||||||
@IsOptional()
|
|
||||||
@IsNumber()
|
|
||||||
@Type(() => Number)
|
|
||||||
@ApiPropertyOptional({ example: 4.5 })
|
|
||||||
rate?: number;
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
@Type(() => Number)
|
@Type(() => Number)
|
||||||
@ApiPropertyOptional({ example: 0 })
|
@ApiPropertyOptional({ example: 0 })
|
||||||
discount?: number;
|
discount?: number;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsArray()
|
@IsArray()
|
||||||
@IsString({ each: true })
|
@IsString({ each: true })
|
||||||
|
|||||||
@@ -11,7 +11,10 @@ export class Food extends BaseEntity {
|
|||||||
title?: string;
|
title?: string;
|
||||||
|
|
||||||
@Property({ type: 'text', nullable: true })
|
@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 })
|
@Property({ type: 'decimal', precision: 10, scale: 2, nullable: true })
|
||||||
price?: number;
|
price?: number;
|
||||||
@@ -43,9 +46,6 @@ export class Food extends BaseEntity {
|
|||||||
@Property({ type: 'boolean', default: false })
|
@Property({ type: 'boolean', default: false })
|
||||||
dinner: boolean = false;
|
dinner: boolean = false;
|
||||||
|
|
||||||
@Property({ type: 'boolean', default: false })
|
|
||||||
isPickup: boolean = false;
|
|
||||||
|
|
||||||
@Property({ type: 'int', default: 0 })
|
@Property({ type: 'int', default: 0 })
|
||||||
stock: number = 0;
|
stock: number = 0;
|
||||||
|
|
||||||
@@ -55,7 +55,6 @@ export class Food extends BaseEntity {
|
|||||||
@Property({ type: 'boolean', default: true })
|
@Property({ type: 'boolean', default: true })
|
||||||
isActive: boolean = true;
|
isActive: boolean = true;
|
||||||
|
|
||||||
// you can store image URLs as JSON array
|
|
||||||
@Property({ type: 'json', nullable: true })
|
@Property({ type: 'json', nullable: true })
|
||||||
images?: string[];
|
images?: string[];
|
||||||
|
|
||||||
@@ -66,7 +65,7 @@ export class Food extends BaseEntity {
|
|||||||
pickupServe: boolean = false;
|
pickupServe: boolean = false;
|
||||||
|
|
||||||
@Property({ type: 'float', default: 0 })
|
@Property({ type: 'float', default: 0 })
|
||||||
rate: number = 0;
|
rate?: number = 0;
|
||||||
|
|
||||||
@Property({ type: 'float', default: 0 })
|
@Property({ type: 'float', default: 0 })
|
||||||
discount: number = 0;
|
discount: number = 0;
|
||||||
|
|||||||
@@ -29,17 +29,15 @@ export class FoodService {
|
|||||||
noon: rest.noon ?? false,
|
noon: rest.noon ?? false,
|
||||||
dinner: rest.dinner ?? false,
|
dinner: rest.dinner ?? false,
|
||||||
// pickup/stock
|
// pickup/stock
|
||||||
isPickup: rest.isPickup ?? false,
|
|
||||||
stock: rest.stock ?? 0,
|
stock: rest.stock ?? 0,
|
||||||
stockDefault: rest.stockDefault ?? 0,
|
stockDefault: rest.stockDefault ?? 0,
|
||||||
isActive: rest.isActive ?? true,
|
isActive: rest.isActive ?? true,
|
||||||
inPlaceServe: rest.inPlaceServe ?? false,
|
inPlaceServe: rest.inPlaceServe ?? false,
|
||||||
pickupServe: rest.pickupServe ?? false,
|
pickupServe: rest.pickupServe ?? false,
|
||||||
rate: rest.rate ?? 0,
|
|
||||||
discount: rest.discount ?? 0,
|
discount: rest.discount ?? 0,
|
||||||
// map single-title/content DTO to localized fields
|
// map single-title/content DTO to localized fields
|
||||||
titleFa: rest.title,
|
title: rest.title,
|
||||||
contentFa: rest.content,
|
content: rest.content,
|
||||||
// numeric/array fields
|
// numeric/array fields
|
||||||
price: rest.price ?? 0,
|
price: rest.price ?? 0,
|
||||||
points: rest.points ?? 0,
|
points: rest.points ?? 0,
|
||||||
@@ -47,7 +45,10 @@ export class FoodService {
|
|||||||
images: rest.images ?? undefined,
|
images: rest.images ?? undefined,
|
||||||
} as RequiredEntityData<Food>;
|
} 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
|
// attach categories if provided
|
||||||
if (categoryIds && categoryIds.length) {
|
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