import { getCustomers, addCustomer, updateCustomer, deleteCustomer } from "../models/customerModel.js"; export const getAllCustomers = async (req, res) => { try { const data = await getCustomers(); res.json(data); } catch (error) { res.status(500).json({ error: error.message }); } }; export const createCustomer = async (req, res) => { try { const { name, email, phone } = req.body; if (!name || !email || !phone) { return res.status(400).json({ message: "Name, Email and Phone required" }); } const result = await addCustomer({ name, email, phone }); res.json({ message: "Customer added", result}); } catch (error) { res.status(500).json({ error: error.message }); } }; export const editCustomer = async (req, res) => { try { const id = req.params.id; const { name, email, phone } = req.body; const result = await updateCustomer(id, { name, email, phone }); res.json({ message: "Customer updated", result}); } catch (error) { res.status(500).json({ error: error.message }); } }; export const removeCustomer = async (req, res) => { try { const id = req.params.id; const result = await deleteCustomer(id); res.json({ message: "Customer deleted", result }); } catch (error) { res.status(500).json({ error: error.message }); } }