text: import { startOfDay, endOfDay, parseISO } from 'date-fns';
  import { Op } from 'sequelize';
  import Appointment from '../models/appointment';
  import User from '../models/user';
  
  class ScheduleController {
    async index(req, res) {
      const checkUserProvider = User.findOne({
        where: {
          id: req.userId, provider: true,
        },
      });
  
      if (!checkUserProvider) {
        return res.status(401).json({ error: 'user is not a provider' });
      }
  
      const { date } = req.query;
      const parsedDate = parseISO(date);
  
      const appointments = await Appointment.findAll({
        where: {
          provider_id: req.userId,
          canceled_at: null,
          date: {
            [Op.between]: [
              startOfDay(parsedDate), endOfDay(parsedDate),
            ],
          },
        },
        include: [{
          model: User,
          as: 'user',
          attributes: ['name'],
        }],
        order: ['date'],
      });
  
      return res.json(appointments);
    }
  }
  
  export default new ScheduleController();
  