Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

216
Vistas
How to show json message when validating Shema?

Pardon me if this question is silly! I have a problem like this: when I am validator in Shema and don't know how to code to display message on controller side. Hoping for everyone's help. Thank you very much!

userService.js

exports.findUserResgiter = async (email) => {
var result = null;
try{
    result = await User.findOne({
        email: email, 
    })
} catch(e){
}
return result; 

};

userController.js

exports.register = async (req, res, next)=>{
var email=req.body.email; 
var password=md5(req.body.password) 
var name=req.body.name 
var address=req.body.address 
var phone=req.body.phone 
var date_of_birth=req.body.date_of_birth 


var data = await userService.findUserResgiter(email);
console.log(data);
if(data === null){
    res.status(200).json({message: "null"});
    return User.create({ 
        name: name, 
        email: email, 
        password: password, 
        address: address, 
        date_of_birth: date_of_birth, 
        phone: phone, 
    }) 
}else{
    res.status(401).json({message: "This email already exists!"});
}

};

userModel.js

var validateEmail = function(email) {
var re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
return re.test(email)

};

const UserShema = new Shema({
name: { type: String,  required: [true, 'Not blank'] },  
date_of_birth: { type: Date, required: [true, 'Not blank']},   
address: { type: String, required: [true, 'Not blank']},   
phone: { type: D, required: [true, 'Not blank']},     
email: { 
    type: String,     
    Required:  'Not blank',
    validate: [validateEmail, 'Not blank'],
        match: [/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/, 'Not blank'],
    index: {unique: true, dropDups: true}
    },  
password: { type: String , required: [true,  'Not blank']}, 

},

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda