Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace view licence contact details page #1238

Merged
merged 38 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
dc02895
Replace view licence contact details page
sujithvg Aug 7, 2024
1a43902
WIP
sujithvg Aug 9, 2024
09e2f04
WIP - Added presenter file and JSON filter
sujithvg Aug 12, 2024
81ec6b0
Move to using licence ID instead of document ID
Cruikshanks Aug 13, 2024
f59310f
Updated name format and moved address rendering logic to presenter file
sujithvg Aug 14, 2024
741ec3c
Updated fetch file for unit testing
sujithvg Aug 21, 2024
30e8e5d
Final commit! - Added unit tests for view licence contact details pre…
sujithvg Aug 23, 2024
d79c7c7
Merge branch 'main' into water-4559-2
rvsiyad Sep 5, 2024
d3157f1
Merge branch 'main' into water-4559-2
rvsiyad Sep 5, 2024
6071395
Remove licenceDocumentHeader from fetch query in fetch licence service
rvsiyad Sep 5, 2024
cd275bb
Fix JSDocs in licence contact presenter
rvsiyad Sep 5, 2024
5fb5cb1
Move pageTitle to licence contact presenter
rvsiyad Sep 5, 2024
b67811d
Fiz JSDocs in fetch licence contact service
rvsiyad Sep 5, 2024
652faf5
Remove pageTitle from return in view licence contact service
rvsiyad Sep 5, 2024
55fe079
Add Licence contact service to licence controller test
rvsiyad Sep 5, 2024
18df2d6
Refactor licence contact presenter test
rvsiyad Sep 5, 2024
9e68433
Add fetch licence contact service test
rvsiyad Sep 5, 2024
5c9d829
Merge branch 'water-4559-2' of https://github.com/DEFRA/water-abstrac…
rvsiyad Sep 5, 2024
3e4b50d
Merge branch 'main' into water-4559-2
rvsiyad Sep 5, 2024
d8efff8
Amend licence contact presenter to include pageTitle property in results
rvsiyad Sep 5, 2024
bf0ddae
Merge branch 'water-4559-2' of https://github.com/DEFRA/water-abstrac…
rvsiyad Sep 5, 2024
239f24f
Change contact detail tab files to use matching file names - `...lice…
rvsiyad Sep 6, 2024
86117ee
Change licence contact details page to use file names of `...licence-…
rvsiyad Sep 6, 2024
bce7d90
Update view licence contact details presenter
rvsiyad Sep 6, 2024
4fc79cc
Rename `licence-contact` view to `licence-contact-details` and update…
rvsiyad Sep 6, 2024
a1d7ba2
Remove variable for licence contact detail view link
rvsiyad Sep 6, 2024
6ad8654
Remove legacy page link from summary tab on licence page
rvsiyad Sep 6, 2024
a33b8b2
Update view licence contact details presenter test
rvsiyad Sep 6, 2024
cb8aba5
Add view licence contact details service test
rvsiyad Sep 6, 2024
d3c48ce
Merge branch 'main' into water-4559-2
rvsiyad Sep 6, 2024
25de255
Merge branch 'main' into water-4559-2
robertparkinson Sep 11, 2024
b11ee4d
Merge branch 'main' into water-4559-2
rvsiyad Sep 17, 2024
1c6e388
Remove trailing backspace from licence controller test
rvsiyad Sep 17, 2024
6cdd824
Change `data` variable to `pageData` to match naming conventions in l…
rvsiyad Sep 17, 2024
9188225
Remove commented code from fetch licence service
rvsiyad Sep 17, 2024
94f07f2
Remove unnecessary comments from view licence contacts service
rvsiyad Sep 17, 2024
f28e9b5
Remove unused imports in licence contact details view
rvsiyad Sep 17, 2024
8762d08
Merge branch 'main' into water-4559-2
robertparkinson Sep 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions app/controllers/licences.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const InitiateSessionService = require('../services/return-requirements/initiate
const ViewLicenceBillsService = require('../services/licences/view-licence-bills.service.js')
const ViewLicenceCommunicationsService = require('../services/licences/view-licence-communications.service.js')
const ViewLicenceContactDetailsService = require('../services/licences/view-licence-contact-details.service.js')
const ViewLicenceContactsService = require('../services/licences/view-licence-contacts.service.js')
const ViewLicenceHistoryService = require('../services/licences/view-licence-history.service.js')
const ViewLicenceReturnsService = require('../services/licences/view-licence-returns.service.js')
const ViewLicenceSetUpService = require('../services/licences/view-licence-set-up.service.js')
Expand Down Expand Up @@ -63,10 +64,20 @@ async function viewCommunications (request, h) {
})
}

async function viewContacts (request, h) {
async function viewLicenceContactDetails (request, h) {
const { id } = request.params

const data = await ViewLicenceContactDetailsService.go(id)

return h.view('licences/licence-contact-details.njk', {
...data
})
}

async function viewLicenceContacts (request, h) {
const { params: { id }, auth } = request

const data = await ViewLicenceContactDetailsService.go(id, auth)
const data = await ViewLicenceContactsService.go(id, auth)

return h.view(ViewLicencePage, {
...data
Expand Down Expand Up @@ -115,8 +126,9 @@ module.exports = {
supplementary,
viewBills,
viewCommunications,
viewContacts,
viewLicenceContacts,
viewHistory,
viewLicenceContactDetails,
viewReturns,
viewSetUp,
viewSummary
Expand Down
2 changes: 1 addition & 1 deletion app/presenters/licences/customer-contacts.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* Formats data for the `/licences/{id}/contact-details` view customer contact details page
* @module CustomerContactDetailsPresenter
* @module CustomerContactsPresenter
*/

const ContactModel = require('../../models/contact.model.js')
Expand Down
2 changes: 1 addition & 1 deletion app/presenters/licences/licence-contacts.presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* Formats data for the `/licences/{id}/contact-details` view licence contact details page
* @module ViewLicenceContactDetailsPresenter
* @module ViewLicenceContactsPresenter
*/

/**
Expand Down
91 changes: 91 additions & 0 deletions app/presenters/licences/view-licence-contact-details.presenter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
'use strict'

/**
* Formats data for the `/licences/{id}/licence-contact` view licence contact details link page
* @module ViewLicenceContactDetailsPresenter
*/

/**
* Formats data for the `/licences/{id}/licence-contact` view licence contact details link page
*
* @param {module:LicenceModel} licence - The licence and related licenceDocumentHeader
*
* @returns {object} The data formatted for the view template
*/
function go (licence) {
const { id: licenceId, licenceDocumentHeader, licenceRef } = licence

return {
licenceId,
licenceRef,
licenceContactDetails: _licenceContactDetails(licenceDocumentHeader),
pageTitle: 'Licence contact details'
}
}

function _licenceContactAddress (contact) {
const contactAddressFields = [
'addressLine1',
'addressLine2',
'addressLine3',
'addressLine4',
'town',
'county',
'postcode',
'country'
]

// NOTE: Maps over the `contactAddressFields` array to create an array of values from the `contact` object. Each
// `contactAddressField` corresponds to a property in the `contact` object, mapping and creating a contactAddress
// array. The `filter(Boolean)` function then removes falsy values from the `contactAddress` array.
const contactAddress = contactAddressFields.map((contactAddressField) => {
return contact[contactAddressField]
}).filter(Boolean)

return contactAddress
}

function _licenceContactName (contact) {
if (contact.type === 'Person') {
const { salutation, forename, initials, name } = contact

// NOTE: Prioritise the initials and use the contact forename if initials is null
const initialsOrForename = initials || forename

const nameComponents = [
salutation,
initialsOrForename,
name
]

const filteredNameComponents = nameComponents.filter((item) => {
return item
})

return filteredNameComponents.join(' ')
}

return contact.name
}

function _licenceContactDetails (licenceDocumentHeader) {
const licenceContactDetailsData = licenceDocumentHeader.metadata.contacts

const roles = ['Licence holder', 'Returns to', 'Licence contact']

const filteredContactDetails = licenceContactDetailsData.filter((licenceContactDetail) => {
return roles.includes(licenceContactDetail.role)
})

return filteredContactDetails.map((contact) => {
return {
address: _licenceContactAddress(contact),
role: contact.role,
name: _licenceContactName(contact)
}
})
}

module.exports = {
go
}
7 changes: 6 additions & 1 deletion app/routes/licence.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ const routes = [
path: '/licences/{id}/communications',
handler: LicencesController.viewCommunications
},
{
method: 'GET',
path: '/licences/{id}/licence-contact',
handler: LicencesController.viewLicenceContactDetails
},
{
method: 'GET',
path: '/licences/{id}/contact-details',
handler: LicencesController.viewContacts
handler: LicencesController.viewLicenceContacts
},
{
method: 'GET',
Expand Down
2 changes: 1 addition & 1 deletion app/services/licences/fetch-customer-contacts.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* Fetches all customer contacts for a licence which is needed for the view '/licences/{id}/contact-details` page
* @module FetchCustomerContactDetailsService
* @module FetchCustomerContactsService
*/

const { db } = require('../../../db/db.js')
Expand Down
42 changes: 42 additions & 0 deletions app/services/licences/fetch-licence-contact-details.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
'use strict'

/**
* Fetches data needed for the view '/licences/{id}/licence-contact` page
* @module FetchLicenceContactDetailsService
*/

const LicenceModel = require('../../models/licence.model.js')

/**
* Fetch the matching licence and return data needed for the licence contact details link page
*
* Was built to provide the data needed for the '/licences/{id}/licence-contact' page
*
* @param {string} licenceId - The UUID for the licence to fetch
*
* @returns {Promise<module:LicenceModel>} the matching `licenceModel` populated with the data needed for the view
* licence contact details page
*/
async function go (licenceId) {
return _fetch(licenceId)
}

async function _fetch (licenceId) {
return LicenceModel.query()
.findById(licenceId)
.select([
'id',
'licenceRef'
])
.withGraphFetched('licenceDocumentHeader')
.modifyGraph('licenceDocumentHeader', (builder) => {
builder.select([
'id',
'metadata'
])
})
}

module.exports = {
go
}
2 changes: 1 addition & 1 deletion app/services/licences/fetch-licence-contacts.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* Fetches all return logs for a licence which is needed for the view '/licences/{id}/contact-details` page
* @module FetchLicenceContactDetailsService
* @module FetchLicenceContactService
*/

const { db } = require('../../../db/db.js')
Expand Down
7 changes: 7 additions & 0 deletions app/services/licences/fetch-licence.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ async function _fetch (licenceId) {
'licenceRef',
'revokedDate'
])
// .withGraphFetched('licenceDocumentHeader')
rvsiyad marked this conversation as resolved.
Show resolved Hide resolved
// .modifyGraph('licenceDocumentHeader', (builder) => {
// builder.select([
// 'licenceDocumentHeaders.id',
// 'licenceDocumentHeaders.metadata'
// ])
// })
.modify('licenceName')
.modify('primaryUser')
.withGraphFetched('licenceSupplementaryYears')
Expand Down
33 changes: 10 additions & 23 deletions app/services/licences/view-licence-contact-details.service.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,27 @@
'use strict'

/**
* Orchestrates fetching and presenting the data needed for the view licence contact details tab
* Orchestrates fetching and presenting the data needed for the view licence contact details link page
* @module ViewLicenceContactDetailsService
*/

const CustomerContactDetailsPresenter = require('../../presenters/licences/customer-contacts.presenter.js')
const FetchCustomerContactDetailsService = require('./fetch-customer-contacts.service.js')
const FetchLicenceContactsService = require('./fetch-licence-contacts.service.js')
const LicenceContactsPresenter = require('../../presenters/licences/licence-contacts.presenter.js')
const ViewLicenceService = require('./view-licence.service.js')
const ViewLicenceContactDetailsPresenter = require('../../presenters/licences/view-licence-contact-details.presenter.js')
const FetchLicenceContactDetailsService = require('./fetch-licence-contact-details.service.js')

/**
* Orchestrates fetching and presenting the data needed for the licence contact details page
* Orchestrates fetching and presenting the data needed for the licence contact details link page
*
* @param {string} licenceId - The UUID of the licence
* @param {object} auth - The auth object taken from `request.auth` containing user details
*
* @returns {Promise<object>} an object representing the `pageData` needed by the licence contact details template.
* @returns {Promise<object>} The view data for the licence contacts page
*/
async function go (licenceId, auth) {
const commonData = await ViewLicenceService.go(licenceId, auth)

// Licence contact details
const licenceContacts = await FetchLicenceContactsService.go(licenceId)
const licenceContactsData = LicenceContactsPresenter.go(licenceContacts)

// Customer contacts details
const customerContacts = await FetchCustomerContactDetailsService.go(licenceId)
const customerContactsData = CustomerContactDetailsPresenter.go(customerContacts)
async function go (licenceId) {
const licence = await FetchLicenceContactDetailsService.go(licenceId)
const formattedData = await ViewLicenceContactDetailsPresenter.go(licence)

return {
activeTab: 'contact-details',
...commonData,
...customerContactsData,
...licenceContactsData
activeNavBar: 'search',
...formattedData
}
}

Expand Down
43 changes: 43 additions & 0 deletions app/services/licences/view-licence-contacts.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict'

/**
* Orchestrates fetching and presenting the data needed for the view licence contact details tab
* @module ViewLicenceContactsService
*/

const CustomerContactsPresenter = require('../../presenters/licences/customer-contacts.presenter.js')
const FetchCustomerContactsService = require('./fetch-customer-contacts.service.js')
const FetchLicenceContactsService = require('./fetch-licence-contacts.service.js')
const LicenceContactsPresenter = require('../../presenters/licences/licence-contacts.presenter.js')
const ViewLicenceService = require('./view-licence.service.js')

/**
* Orchestrates fetching and presenting the data needed for the licence contact details page
*
* @param {string} licenceId - The UUID of the licence
* @param {object} auth - The auth object taken from `request.auth` containing user details
*
* @returns {Promise<object>} an object representing the `pageData` needed by the licence contact details template.
*/
async function go (licenceId, auth) {
const commonData = await ViewLicenceService.go(licenceId, auth)

// Licence contact details
rvsiyad marked this conversation as resolved.
Show resolved Hide resolved
const licenceContacts = await FetchLicenceContactsService.go(licenceId)
const licenceContactsData = LicenceContactsPresenter.go(licenceContacts)

// Customer contacts details
const customerContacts = await FetchCustomerContactsService.go(licenceId)
const customerContactsData = CustomerContactsPresenter.go(customerContacts)

return {
activeTab: 'contact-details',
...commonData,
...customerContactsData,
...licenceContactsData
}
}

module.exports = {
go
}
58 changes: 58 additions & 0 deletions app/views/licences/licence-contact-details.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{% extends 'layout.njk' %}
{% from "govuk/components/back-link/macro.njk" import govukBackLink %}
{% from "govuk/components/notification-banner/macro.njk" import govukNotificationBanner %}
rvsiyad marked this conversation as resolved.
Show resolved Hide resolved
{% from "govuk/components/summary-list/macro.njk" import govukSummaryList %}
{% from "govuk/components/table/macro.njk" import govukTable %}
rvsiyad marked this conversation as resolved.
Show resolved Hide resolved
{% from "govuk/components/tabs/macro.njk" import govukTabs %}
{% from "govuk/components/warning-text/macro.njk" import govukWarningText %}

{% block breadcrumbs %}
{{ govukBackLink({
text: 'Back to summary',
href: '/system/licences/' + licenceId + '/summary'
}) }}
{% endblock %}

{% block content %}
<h1 class="govuk-heading-l">
<span class="govuk-caption-l">Licence {{ licenceRef }}</span>
{{ pageTitle }}
</h1>

{% macro displayAddress(address) %}
{% for item in address %}
<p class="govuk-body govuk-!-margin-bottom-0"> {{ item }} </p>
{% endfor %}
{% endmacro %}

{% for licenceContactDetail in licenceContactDetails %}
{{ govukSummaryList({
card: {
title: {
text: licenceContactDetail.role
}
},
rows: [
{
key: {
text: "Name",
classes:"govuk-!-font-weight-regular"
},
value: {
text: licenceContactDetail.name
}
},
{
key: {
text: "Address",
classes:"govuk-!-font-weight-regular"
},
value: {
html: displayAddress(licenceContactDetail.address)
}
}
]
})
}}
{% endfor %}
{% endblock %}
Loading
Loading