const userModel = require('../../models/users')
const validator = require('./registerValidation')
const { buildResponse } = require('../../utils/responseService') 

module.exports = (req, res) => {
  const {error, value} = validator.validate(req.body)
  if (error) {
    buildResponse(res, 400, { message: error.details[0].message })
  }

  userModel.findOne(value.username)
    .then(user => {
      if (user) {
        buildResponse(res, 403, { message: 'user already exists' })
      } else {
         userModel.createUser(value)
          .then(user => {
            buildResponse(res, 200, { message: 'successfully created user.', user })
          })

          .catch(error => {
            buildResponse(res, 500, { message: 'something happened', error })
          })
      }
    })
  
}

@@ -260,24 +260,31 @@
 rror) %7B%0A    
+return 
 buildRespons

Make the registration process not to proceed after validation fails