Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

307
Views
Express Validator Schema agregar secuencia validador personalizado

¿Hay alguna forma de agregar una verificación de secuencia para el nombre de usuario?

aquí está mi validador de esquema:

 const validatorSchema = { userName: { custom: { options: (value) => { if (dataUtils.isEmpty(value) || value === null) { return false; } }, errorMessage: "userName field is empty", }, custom: { options: (value) => { return User.findOne({ where: { userName: value, }, }).then((user) => { if (user == null) { return true; } else { return Promise.reject(user); } }); }, errorMessage: "User already existed", }, custom: { options: (value) => { if (dataUtils.whiteSpaceChecker(value) && value != null) {//not allow whiteSpace between return false; } }, errorMessage: "Wrong format userName", }, }, }

Cuerpo de mi solicitud:

 { "userName": "notExistedUser", "password": "samplePassword" }

Yo lo hago siguiendo este tutorial .
Pero quiero hacer más que verificar solo el usuario existente y no funcionó como se esperaba
Respuesta siempre enviar

 "errors": [ { "value": "notExistedUser", "msg": "Wrong format userName", "param": "userName", "location": "body" } ]

Nota: uso este esquema en middleware

 const { body, checkSchema, validationResult } = require("express-validator"); app.post('/signup', checkSchema(validatorSchema), (req, res) => { // Validate incoming input const errors = validationResult(req); if (!errors.isEmpty()) { return res.status(400).json({ errors: errors }); } next(); })

Gracias por leer este artículo, ¡espero poder encontrar la solución para esto!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!