const { User, Order } = require("../Database/models/index.js");

const createUser = async (data) => {
  return await User.create(data);
};

const findUserByEmail = async (email) => {
  return await User.findOne({ where: { email } });
};

const findAll = async () => {
  return await User.findAll({
    include: {
      model: Order,
      as: "orders",
    },
  });
};

const deleteUser = async (id) => {
  return await User.destroy({ where: { id } });
};

module.exports = { createUser, findUserByEmail, findAll, deleteUser };
