const { findAll, deleteUser } = require("./servis.js");

const getAll = async (req, res) => {
  try {
    const data = await findAll();
    res.status(200).json(data);
  } catch (error) {
    res.status(500).json({ message: error.message });
  }
};

const hapusUser = async (req, res) => {
  try {
    const { id } = req.params;
    const hasil = await deleteUser(id);

    if (!hasil) {
      return res.status(404).json({ message: "User tidak ditemukan" });
    }

    res.status(200).json({ message: "User berhasil dihapus" });
  } catch (error) {
    res.status(500).json({ message: error.message });
  }
};

module.exports = { getAll, hapusUser };
