Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const User = require('../models/User');
- const router = require('express').Router();
- const Joi = require('@hapi/joi');
- const schemeRegister = Joi.object({
- name: Joi.string().min(6).max(255).required(),
- email: Joi.string().min(6).max(255).required().email(),
- password: Joi.string().min(6).max(1024).required()
- });
- router.post('/register', async (request, response) =>
- {
- // Validación de la data que nos llega por el request
- const { error } = schemeRegister.validate(request.body);
- console.log("error", error);
- if (error) {
- return response.status(400).json(
- {
- error: error.details[0].message
- }
- )
- }
- const user = new User(
- {
- name: request.body.name,
- email: request.body.email,
- password: request.body.password
- });
- try {
- const savedUser = await user.save();
- response.json({
- error: null,
- data: savedUser
- })
- } catch (error) {
- response.status(400).json({error});
- }
- });
- module.exports = router;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement