This commit is contained in:
2026-02-08 08:50:08 +03:30
commit 8af4936ed0
323 changed files with 92747 additions and 0 deletions
@@ -0,0 +1,27 @@
import { Entity, Index, Property, Collection, OneToMany, ManyToOne } from '@mikro-orm/core';
import { Food } from './food.entity';
import { BaseEntity } from '../../../common/entities/base.entity';
import { Restaurant } from 'src/modules/restaurants/entities/restaurant.entity';
@Entity({ tableName: 'categories' })
@Index({ properties: ['restaurant', 'isActive'] })
@Index({ properties: ['isActive'] })
export class Category extends BaseEntity {
@Property()
title!: string;
@OneToMany(() => Food, food => food.category)
foods = new Collection<Food>(this);
@Property({ default: true })
isActive: boolean = true;
@ManyToOne(() => Restaurant)
restaurant!: Restaurant;
@Property({ nullable: true })
avatarUrl?: string;
@Property({ type: 'int', nullable: true })
order?: number;
}
@@ -0,0 +1,14 @@
import { Entity, ManyToOne, Unique } from '@mikro-orm/core';
import { BaseEntity } from '../../../common/entities/base.entity';
import { User } from '../../users/entities/user.entity';
import { Food } from '../../foods/entities/food.entity';
@Entity({ tableName: 'favorites' })
@Unique({ properties: ['user', 'food'] })
export class Favorite extends BaseEntity {
@ManyToOne(() => User)
user: User;
@ManyToOne(() => Food)
food: Food;
}
+77
View File
@@ -0,0 +1,77 @@
import { Cascade, Collection, Entity, Index, ManyToOne, OneToMany, Property, OneToOne } from '@mikro-orm/core';
import { Category } from './category.entity';
import { BaseEntity } from '../../../common/entities/base.entity';
import { Restaurant } from '../../../modules/restaurants/entities/restaurant.entity';
import { Review } from 'src/modules/review/entities/review.entity';
import { Inventory } from 'src/modules/inventory/entities/inventory.entity';
import { MealType } from '../interface/food.interface';
import { Favorite } from './favorite.entity';
@Entity({ tableName: 'foods' })
@Index({ properties: ['restaurant', 'isActive'] })
@Index({ properties: ['category', 'isActive'] })
@Index({ properties: ['isActive'] })
export class Food extends BaseEntity {
@ManyToOne(() => Restaurant)
restaurant: Restaurant;
@ManyToOne(() => Category)
category: Category;
@OneToMany(() => Review, review => review.food, { cascade: [Cascade.ALL], orphanRemoval: true })
reviews = new Collection<Review>(this);
@OneToOne(() => Inventory, {
mappedBy: 'food',
nullable: true,
})
inventory?: Inventory;
@OneToMany(() => Favorite, favorite => favorite.food)
favorites = new Collection<Favorite>(this);
@Property({ nullable: true })
title?: string;
@Property({ type: 'text', nullable: true })
desc?: string;
@Property({ type: 'json', nullable: true })
content?: string[];
@Property({ type: 'decimal', precision: 10, scale: 2, nullable: true })
price?: number;
@Property({ type: 'int', nullable: true })
order?: number;
@Property({ type: 'int', nullable: true })
prepareTime?: number; // in minutes
@Property({ type: 'jsonb', default: [] })
weekDays: number[] = [0, 1, 2, 3, 4, 5, 6];
@Property({ type: 'jsonb', default: [] })
mealTypes: MealType[] = [];
@Property({ type: 'boolean', default: true })
isActive: boolean = true;
@Property({ type: 'json', nullable: true })
images?: string[];
@Property({ type: 'boolean', default: false })
inPlaceServe: boolean = false;
@Property({ type: 'boolean', default: false })
pickupServe: boolean = false;
@Property({ type: 'float', default: null })
score?: number | null = null;
@Property({ type: 'float', default: 0 })
discount: number = 0;
@Property({ type: 'boolean', default: false })
isSpecialOffer: boolean = false;
}