text: import * as Yup from 'yup';
  import Student from '../models/Student';
  
  class StudentController {
    async store(req, res) {
      const schema = Yup.object().shape({
        name: Yup.string().required(),
        email: Yup.string()
          .email()
          .required(),
        age: Yup.number().required(),
        weight: Yup.number().required(),
        height: Yup.number().required(),
      });
  
      if (!(await schema.isValid(req.body))) {
        return res.status(400).json({ error: 'Validation fails' });
      }
  
      const studentExists = await Student.findOne({
        where: { email: req.body.email },
      });
  
      if (studentExists) {
        return res.status(400).json({ error: 'Student already exists' });
      }
  
      const { id, name, email, age, weight, height } = Student.create(req.body);
  
      return res.json({
        id,
        name,
        email,
        age,
        weight,
        height,
      });
    }
  
    async update(req, res) {
      const schema = Yup.object().shape({
        name: Yup.string(),
        email: Yup.string().email(),
        age: Yup.number(),
        weight: Yup.number(),
        height: Yup.number(),
      });
  
      if (!(await schema.isValid(req.body))) {
        return res.status(400).json({ error: 'Validation fails' });
      }
  
      const { id } = req.params;
  
      const student = await Student.findByPk(id);
  
      const { email } = req.body;
  
      if (email !== student.email) {
        const studentExists = await Student.findOne({ where: { email } });
  
        if (studentExists) {
          return res.status(400).json({ error: 'Student already exists' });
        }
      }
  
      const { name, age, weight, height } = await student.update(req.body);
  
      return res.json({
        id,
        name,
        email,
        age,
        weight,
        height,
      });
    }
  }
  
  export default new StudentController();
  