This commit is contained in:
2025-12-15 11:15:08 +03:30
parent 9d677622f2
commit b776f2b83a
12 changed files with 80 additions and 60 deletions
@@ -1,17 +1,12 @@
import { Entity, ManyToOne, Property, Unique } from '@mikro-orm/core';
import { Entity, Property, OneToOne } from '@mikro-orm/core';
import { BaseEntity } from '../../../common/entities/base.entity';
import { Restaurant } from '../../restaurants/entities/restaurant.entity';
import { Food } from '../../foods/entities/food.entity';
@Entity({ tableName: 'inventory' })
@Unique({ properties: ['food', 'restaurant'] })
export class Inventory extends BaseEntity {
@ManyToOne(() => Food, { unique: true })
@OneToOne(() => Food, food => food.inventory)
food!: Food;
@ManyToOne(() => Restaurant)
restaurant!: Restaurant;
@Property({ type: 'int' })
totalStock!: number;
+3 -8
View File
@@ -32,8 +32,7 @@ export class InventoryService {
// Find or create inventory record
let inventory = await this.em.findOne(Inventory, {
food: { id: foodId },
restaurant: { id: restaurantId },
food: { id: foodId, restaurant: { id: restaurantId } },
});
if (!inventory) {
@@ -45,7 +44,6 @@ export class InventoryService {
inventory = this.em.create(Inventory, {
food,
restaurant,
totalStock: setStockDto.totalStock,
availableStock: setStockDto.availableStock,
});
@@ -93,8 +91,7 @@ export class InventoryService {
// Load all existing inventories in one query
const existingInventories = await this.em.find(Inventory, {
food: { id: { $in: foodIds } },
restaurant: { id: restaurantId },
food: { id: { $in: foodIds }, restaurant: { id: restaurantId } },
});
const inventoryMap = new Map<string, Inventory>();
@@ -118,7 +115,6 @@ export class InventoryService {
// Create new inventory record
inventory = this.em.create(Inventory, {
food,
restaurant,
totalStock: item.totalStock,
availableStock: item.availableStock,
});
@@ -173,8 +169,7 @@ export class InventoryService {
// Load all existing inventories in one query
const existingInventories = await this.em.find(Inventory, {
food: { id: { $in: foodIds } },
restaurant: { id: restaurantId },
food: { id: { $in: foodIds }, restaurant: { id: restaurantId } },
});
const inventoryMap = new Map<string, Inventory>();