<commit_before>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) {
    return 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 })
          })
      }
    })
  
}
<commit_msg>Change status code for resouce confilcts to 422 'Unprocessable Entity'<commit_after>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) {
    return buildResponse(res, 400, { message: error.details[0].message })
  }

  userModel.findOne(value.username)
    .then(user => {
      if (user) {
        buildResponse(res, 422, { 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 })
          })
      }
    })
  
}

{'fraction_non_alphanumeric': 0.15474112856311809, 'fraction_numerical': 0.01687027341477603, 'mean_word_length': 2.553719008264463, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4719260', 'n_tokens_mistral': 526, 'n_tokens_neox': 492, 'n_words': 109}