OwlCyberSecurity - MANAGER
Edit File: supplier.controller.js
// controllers/supplierController.js import { Supplier, AssetCategory } from '../models/index.js'; export const getAllSuppliers = async (req, res) => { try { const suppliers = await Supplier.findAll({ include: [{ model: AssetCategory, attributes: ['id', 'category'] }], }); res.json(suppliers); } catch (error) { console.error('Error fetching suppliers:', error); res.status(500).json({ error: 'Failed to fetch suppliers' }); } }; export const createSupplier = async (req, res) => { try { const supplier = await Supplier.create(req.body); res.status(201).json(supplier); } catch (error) { console.error('Error creating supplier:', error); res.status(500).json({ error: 'Failed to create supplier' }); } };