const { formatCurrency } = require("../../../managers/customFormaters");
const db = require("../../../managers/dbConfig");

const dashboard = async (req, res) => {
  const sql = `SELECT SUM(outstanding_balance) AS ptDebt FROM patients WHERE outstanding_balance < 0;`;
  // let formattedAmount;
  const [debtAmount] = await db.execute(sql);
  let ptDebt = debtAmount[0].ptDebt;

  if (ptDebt) {
    ptDebt = formatCurrency(ptDebt);
  }
  // console.log(formattedAmount);
  res.status(200).json({
    status: "success",
    message: "Welcome To Admin dasboard!",
    ptDebt,
  });
};

module.exports = dashboard;
