const getCaseProgress = require('../services/get-case-progress')
const getSubNav = require('../services/get-sub-nav')
const organisationUnit = require('../constants/organisation-unit')

module.exports = function (router) {
  router.get('/:organisationLevel/:id/case-progress', function (req, res, next) {
    var organisationLevel = req.params.organisationLevel
    var id

    if (organisationLevel !== organisationUnit.NATIONAL.name) {
      id = req.params.id
    }

    var caseProgressPromise = getCaseProgress(id, organisationLevel)

    return caseProgressPromise.then(function (result) {
      return res.render('case-progress', {
        title: result.title,
        subTitle: result.subTitle,
        breadcrumbs: result.breadcrumbs,
        subNav: getSubNav(id, organisationLevel, req.path),
        caseProgress: result.caseProgress
      })
    })
  })
}

const getCaseProgress = require('../services/get-case-progress')
const getSubNav = require('../services/get-sub-nav')

module.exports = function (router) {
  router.get('/:organisationLevel/:id/case-progress', function (req, res, next) {
    var id = req.params.id
    var organisationLevel = req.params.organisationLevel

    var caseProgressPromise = getCaseProgress(id, organisationLevel)

    return caseProgressPromise.then(function (result) {
      return res.render('case-progress', {
        title: result.title,
        subTitle: result.subTitle,
        breadcrumbs: result.breadcrumbs,
        subNav: getSubNav(id, organisationLevel, req.path),
        caseProgress: result.caseProgress
      })
    })
  })
}

--- 
+++ 
@@ -1,10 +1,15 @@
 const getCaseProgress = require('../services/get-case-progress')
 const getSubNav = require('../services/get-sub-nav')
+const organisationUnit = require('../constants/organisation-unit')
 
 module.exports = function (router) {
   router.get('/:organisationLevel/:id/case-progress', function (req, res, next) {
-    var id = req.params.id
     var organisationLevel = req.params.organisationLevel
+    var id
+
+    if (organisationLevel !== organisationUnit.NATIONAL.name) {
+      id = req.params.id
+    }
 
     var caseProgressPromise = getCaseProgress(id, organisationLevel)
 
636: Add national id logic to case progress routes
