const db = require("../db/db");
const getall = () => {
  const sql = `SELECT * FROM news_letter`;
  return new Promise((resolve, reject) => {
    db.query(sql, (err, results) => {
      if (err) {
        reject(err);
      } else {
        resolve(results);
      }
    });
  });
};

const addNews = (Email) => {
  const sql = `INSERT INTO news_letter (Email) VALUES (?)`;
  return new Promise((resolve, reject) => {
    db.query(sql, [Email], (err, results) => {
      if (err) {
      } else {
        resolve(results);
      }
    });
  });
};

const deletenews = (idNewsLetter) => {
  const sql = `DELETE FROM news_letter WHERE idNewsLetter = ?`;
  return new Promise((resolve, reject) => {
    db.query(sql, [idNewsLetter], (err, results) => {
      if (err) {
        reject(err);
      } else {
        resolve(results);
      }
    });
  });
};

module.exports = {
  getall,
  addNews,
  deletenews,
};
