const router = require('express').Router()

const { getProjectDetails } = require('./shared.middleware')

const {
  populateDetailsFormMiddleware,
  investmentDetailsFormPostMiddleware,
} = require('./form.middleware')

function createGetHandler (req, res) {
  if (!res.locals.equityCompany) {
    return res.redirect('/investment/start')
  }
  return res.render('investment/create', {
    title: 'Add investment project',
  })
}

function createPostHandler (req, res) {
  if (res.locals.form.errors) {
    return res.render('investment/create')
  }
  return res.redirect(`/investment/${res.locals.resultId}`, {
    title: 'Add investment project',
  })
}

router.param('id', getProjectDetails)
router.get('/create', populateDetailsFormMiddleware, createGetHandler)
router.post('/create', populateDetailsFormMiddleware, investmentDetailsFormPostMiddleware, createPostHandler)

module.exports = {
  router,
  createGetHandler,
  createPostHandler,
}

@@ -537,16 +537,64 @@
 /create'
+, %7B%0A      title: 'Add investment project',%0A    %7D
 )%0A  %7D%0A  
@@ -653,52 +653,8 @@
 Id%7D%60
-, %7B%0A    title: 'Add investment project',%0A  %7D
 )%0A%7D%0A

Fix error with data being passed to redirect method