Files
dkala-api/src/modules/foods/entities/food.entity.ts
T
2026-02-08 09:09:21 +03:30

62 lines
1.8 KiB
TypeScript

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 { 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: 'boolean', default: true })
isActive: boolean = true;
@Property({ type: 'json', nullable: true })
images?: string[];
@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;
}