const { Banks } = require('../../models');
const { formatCase, formatImage } = require('../../util/formatter');

exports.getBanks = async (req, res, next) => {
  try {
    let banks = await Banks.findAll({
      attributes: {
        exclude: ['createdAt'],
      },
      order: [['name', 'ASC']],
    });

    banks = banks.map((bank) => ({
      ...bank.get({ plain: true }),
      image: formatImage(bank.image, 'banks'),
    }));

    return res.status(200).json({
      success: true,
      data: formatCase(banks),
    });
  } catch (error) {
    next(error);
  }
};
