Skip to content

Commit

Permalink
feature: working fetch and view
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathangoulding committed Jan 30, 2025
1 parent f2b0e08 commit 856ba73
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/models/licence-document-header.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class LicenceDocumentHeaderModel extends BaseModel {
}
},
licenceEntityRole: {
relation: Model.HasOneRelation,
relation: Model.HasManyRelation,
modelClass: 'licence-entity-role.model',
join: {
from: 'licenceDocumentHeaders.companyEntityId',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ const { filteredContactDetailsByRole } = require('../crm.presenter.js')
* @module ViewLicenceContactDetailsPresenter
*/

const ROLES = {
primary_user: 'Primary user',
user_returns: 'Returns agent'
}

/**
* Formats data for the `/licences/{id}/licence-contact` view licence contact details link page
*
Expand All @@ -20,11 +25,39 @@ function go(licence) {
return {
licenceId,
licenceRef,
licenceContactDetails: filteredContactDetailsByRole(licenceDocumentHeader.metadata.contacts),
licenceContactDetails: _licenceContactDetails(licenceDocumentHeader),
pageTitle: 'Licence contact details'
}
}

function _licenceContactDetails(licenceDocumentHeader) {
return [
...filteredContactDetailsByRole(licenceDocumentHeader.metadata.contacts),
..._licenceEntityRole(licenceDocumentHeader.licenceEntityRole)
]
}

function _licenceEntityRole(licenceEntityRole) {
return licenceEntityRole.map(_licenceEntity).sort(_sortLicenceEntity)
}

function _licenceEntity(entity) {
return {
role: ROLES[entity.role],
email: entity.licenceEntity.name
}
}

function _sortLicenceEntity(a, b) {
if (a.role < b.role) {
return -1
}
if (a.role > b.role) {
return 1
}
return 0
}

module.exports = {
go
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async function _fetch(licenceId) {
})
.withGraphFetched('licenceDocumentHeader.licenceEntityRole')
.modifyGraph('licenceDocumentHeader.licenceEntityRole', (builder) => {
builder.whereIn('role', ['primary_user', 'user_returns'])
builder.select(['role']).whereIn('role', ['primary_user', 'user_returns'])
})
.withGraphFetched('licenceDocumentHeader.licenceEntityRole.licenceEntity')
.modifyGraph('licenceDocumentHeader.licenceEntityRole.licenceEntity', (builder) => {
Expand Down
11 changes: 10 additions & 1 deletion app/views/licences/licence-contact-details.njk
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
value: {
text: licenceContactDetail.name
}
},
} if licenceContactDetail.name,
{
key: {
text: "Address",
Expand All @@ -46,7 +46,16 @@
value: {
html: displayAddress(licenceContactDetail.address)
}
} if licenceContactDetail.address,
{
key: {
text: "Email",
classes:"govuk-!-font-weight-regular"
},
value: {
html: licenceContactDetail.email
}
} if licenceContactDetail.email
]
})
}}
Expand Down

0 comments on commit 856ba73

Please sign in to comment.