import warehouse from "../models/warehouse.js";

export const addWareHouse = async (req, res) => {
  try {
    const { WarehouseCode, WarehouseName, WarehouseLocation } = req.body;
    const warehouseExists = await warehouse.findOne({ WarehouseCode });
    if (warehouseExists) {
      return res.status(400).json({ message: 'warehouse already exists' });
    }
    await new warehouse({ WarehouseCode, WarehouseName, WarehouseLocation }).save();
    res.status(201).json({ message: 'new warehouse added' });
  } catch (error) {
    res.status(500).json({ message: 'internal server error', error: error.message });
  }
};

export const getAllWarehouses = async (req, res) => {
  try {
    const result = await warehouse.find();
    res.status(200).json(result);
  } catch (error) {
    res.status(500).json({ message: 'internal server error', error: error.message });
  }
};