{"size": 1059, "ext": "js", "max_stars_repo_path": "app/routes/organisations.js", "max_stars_repo_name": "christopherthomasdesign/dfe-manage-teacher-applications", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "app/routes/organisations.js", "max_issues_repo_name": "christopherthomasdesign/dfe-manage-teacher-applications", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "app/routes/organisations.js", "max_forks_repo_name": "christopherthomasdesign/dfe-manage-teacher-applications", "max_forks_repo_forks_event_min_datetime": "2020-09-09T15:04:42.000Z", "max_forks_repo_forks_event_max_datetime": "2020-09-09T15:04:42.000Z"}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 27.1538461538, "max_line_length": 98, "alphanum_fraction": 0.6449480642}
const utils = require('../data/application-utils')

module.exports = router => {

  router.get('/organisations/:organisationId', (req, res) => {

    let org = req.session.data.user.organisations.find(org => org.id == req.params.organisationId)

    let relationships = req.session.data.relationships
      .filter(relationship => {
        return relationship.org.id == org.id
      })
      .filter(relationship => relationship.partner)

    const flashMessage = utils.getFlashMessage({
      flash: req.flash('success'),
      overrideValue: req.query.flash,
      map: {
        'permissions-changed': 'Permissions successfully changed'
      }
    })

    res.render('organisations/show', {
      flashMessage,
      org,
      relationships
    })
  })

  router.get('/organisations/:organisationId/edit', (req, res) => {
    res.render('organisations/edit')
  })

  router.post('/organisations/:organisationId/edit', (req, res) => {
    req.flash('success', 'permissions-changed')
    res.redirect(`/organisations/${req.params.organisationId}`)
  })
}
