up
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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>();
|
||||
|
||||
Reference in New Issue
Block a user