const { getDitCompany, getCHCompany } = require('../repos')

async function getCompany (req, res, next, id) {
  try {
    res.locals.company = await getDitCompany(req.session.token, id)
    next()
  } catch (error) {
    next(error)
  }
}

async function getCompaniesHouseRecord (req, res, next, companyNumber) {
  try {
    res.locals.companiesHouseRecord = await getCHCompany(req.session.token, companyNumber)
    next()
  } catch (error) {
    next(error)
  }
}

module.exports = {
  getCompany,
  getCompaniesHouseRecord,
}

@@ -8,56 +8,630 @@
  get
-DitCompany, getCHCompany %7D = require('../repos')
+FormattedAddress %7D = require('../../../lib/address')%0Aconst %7B getDitCompany, getCHCompany %7D = require('../repos')%0A%0A// TODO: Use transformer to return correct address object and handle display%0A// in view layer%0Afunction getHeadingAddress (company) %7B%0A  // If this is a CDMS company%0A  const cdmsTradingAddress = getFormattedAddress(company, 'trading')%0A  if (cdmsTradingAddress) %7B%0A    return cdmsTradingAddress%0A  %7D%0A%0A  if (company.companies_house_data && company.companies_house_data !== null) %7B%0A    return getFormattedAddress(company.companies_house_data, 'registered')%0A  %7D%0A%0A  return getFormattedAddress(company, 'registered')%0A%7D
 %0A%0Aas
@@ -685,35 +685,30 @@
   try %7B%0A    
-res.locals.
+const 
 company = aw
@@ -748,16 +748,101 @@
 en, id)%0A
+%0A    company.address = getHeadingAddress(company)%0A%0A    res.locals.company = company%0A%0A
     next

Extend company view params to set address for shared header