async store(req, res) {
    // Define a schema to validade the information that will be given to the backend
    const schema = Yup.object().shape({
      name: Yup.string().required(),
      email: Yup.string().email().required(),
      password: Yup.string().required().min(6),
    });

    // Verify if the data pass inside the defined schema
    if (!(await schema.isValid(req.body))) {
      return res.status(400).json({
        error: 'Validation failed',
      });
    }

    const userExists = await User.findOne({ where: { email: req.body.email } });
    if (userExists) {
      return res.status(400).json({
        error: 'User already exists',
      });
    }
    // Take the data sent from the client and create a new instance of the user
    const { id, name, email, provider } = await User.create(req.body);

    return res.json({
      id,
      name,
      email,
      provider,
    });
  }
// Method responsable to save a new entry inside the database
Method responsable to save a new entry inside the database
Method responsable to save a new entry inside the database
async store(req, res) {
    const schema = Yup.object().shape({
      name: Yup.string().required(),
      email: Yup.string().email().required(),
      password: Yup.string().required().min(6),
    });
    if (!(await schema.isValid(req.body))) {
      return res.status(400).json({
        error: 'Validation failed',
      });
    }
    const userExists = await User.findOne({ where: { email: req.body.email } });
    if (userExists) {
      return res.status(400).json({
        error: 'User already exists',
      });
    }
    const { id, name, email, provider } = await User.create(req.body);
    return res.json({
      id,
      name,
      email,
      provider,
    });
  }
async store ( req , res ) { const schema = Yup . object ( ) . shape ( { name : Yup . string ( ) . required ( ) , email : Yup . string ( ) . email ( ) . required ( ) , password : Yup . string ( ) . required ( ) . min ( 6 ) , } ) ; if ( ! ( await schema . isValid ( req . body ) ) ) { return res . status ( 400 ) . json ( { error : 'Validation failed' , } ) ; } const userExists = await User . findOne ( { where : { email : req . body . email } } ) ; if ( userExists ) { return res . status ( 400 ) . json ( { error : 'User already exists' , } ) ; } const { id , name , email , provider } = await User . create ( req . body ) ; return res . json ( { id , name , email , provider , } ) ; }
Method responsable to save a new entry inside the database
Method responsable to save a new entry inside the database
// Define a schema to validade the information that will be given to the backend // Verify if the data pass inside the defined schema // Take the data sent from the client and create a new instance of the user