text: const Util = require('../../utils/Utils');
  const { GetAll, GetId, Store, Update, Delete } = require('./portal-models');
  
  const util = new Util();
  
  /**
   * The PortalController.
   *
   * @method index get all
   * @method show  get id
   * @method store store
   * @method update update
   * @method delete delete
   */
  
  class PortalController {
    async index(req, res) {
      try {
        const data = await GetAll();
  
        if (data.length) {
          util.setSuccess(200, data);
        } else {
          util.setError(400, 'no data!');
        }
  
        return util.send(res);
      } catch (err) {
        util.setError(500, err.message);
        return util.send(res);
      }
    }
  
    async show(req, res) {
      try {
        const { cpf } = req.query;
  
        const data = await GetId(cpf);
  
        if (data) {
          util.setSuccess(200, data);
        } else {
          util.setError(400, 'no data!');
        }
  
        return util.send(res);
      } catch (err) {
        util.setError(500, err.message);
        return util.send(res);
      }
    }
  
    async store(req, res) {
      try {
        const { name, cpf, phone } = req.body;
  
        const data = await Store(name, cpf, phone);
  
        if (data) {
          util.setSuccess(200, data);
        }
  
        return util.send(res);
      } catch (err) {
        util.setError(500, err.message);
        return util.send(res);
      }
    }
  
    async update(req, res) {
      try {
        const { name, cpf, phone } = req.body;
  
        const data = await Update(name, cpf, phone);
  
        if (data) {
          util.setSuccess(200, data);
        }
  
        return util.send(res);
      } catch (err) {
        util.setError(500, err.message);
        return util.send(res);
      }
    }
  
    async delete(req, res) {
      try {
        const { cpf } = req.query;
  
        const data = await Delete(cpf);
  
        if (data) {
          util.setSuccess(200, data);
        }
  
        return util.send(res);
      } catch (err) {
        util.setError(500, err.message);
        return util.send(res);
      }
    }
  }
  
  module.exports = PortalController;
  