<commit_before>const Joi = require('joi')
const { waterfall } = require('async')

const renderEmail = request => (payload, cb) => {
  request.render('email', payload, (err, emailHtml) => {
    if (err) return cb(err)

    cb(null, Object.assign({}, payload, { emailHtml }))
  })
}

const route = {
  method: 'POST',
  path: '/report',
  config: {
    handler: (request, reply) => {
      const { payload, server: { plugins: { model } } } = request
      const photoUrl = model.getUrl(payload.photoKey)
      const payloadWithPhotoUrl = Object.assign({}, payload, { photoUrl })

      waterfall([
        model.submitReport(payloadWithPhotoUrl),
        renderEmail(request),
        model.sendEmail
      ], (error, payload) => {
        if (error) return console.error(error)

        const { s3PutUrl, photoData, photoExt } = payload
        reply({ s3PutUrl })
      })
    },
    payload: {
      maxBytes: 10485760
    },
    validate: {
      payload: {
        locationFirst: Joi.string().required(),
        locationSecond: Joi.string().optional(),
        locationThird: Joi.string().optional(),
        name: Joi.string().optional().allow(""),
        photoKey: Joi.string().optional(),
        description: Joi.string().required(),
        reportType: ['near miss', 'positive intervention']
      }
    }
  }
}

module.exports = route<commit_msg>fix linting errors in submit endpoint<commit_after>const Joi = require('joi')
const { waterfall } = require('async')

const renderEmail = request => (payload, cb) => {
  request.render('email', payload, (err, emailHtml) => {
    if (err) return cb(err)

    cb(null, Object.assign({}, payload, { emailHtml }))
  })
}

const route = {
  method: 'POST',
  path: '/report',
  config: {
    handler: (request, reply) => {
      const { payload, server: { plugins: { model } } } = request
      const photoUrl = model.getUrl(payload.photoKey)
      const payloadWithPhotoUrl = Object.assign({}, payload, { photoUrl })

      waterfall([
        model.submitReport(payloadWithPhotoUrl),
        renderEmail(request),
        model.sendEmail
      ], (error, payload) => {
        if (error) return console.error(error)

        const { s3PutUrl } = payload
        reply({ s3PutUrl })
      })
    },
    payload: {
      maxBytes: 10485760
    },
    validate: {
      payload: {
        locationFirst: Joi.string().required(),
        locationSecond: Joi.string().optional(),
        locationThird: Joi.string().optional(),
        name: Joi.string().optional().allow(''),
        photoKey: Joi.string().optional(),
        description: Joi.string().required(),
        reportType: ['near miss', 'positive intervention']
      }
    }
  }
}

module.exports = route
{'fraction_non_alphanumeric': 0.15531836584468164, 'fraction_numerical': 0.00736105999263894, 'mean_word_length': 2.692934782608696, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '4525075', 'n_tokens_mistral': 824, 'n_tokens_neox': 799, 'n_words': 178}