-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Suggested View contact details changes
https://eaflood.atlassian.net/browse/WATER-4433 This relates to [Add View Licence contact details page](#993). What started as experimenting with an alternate fetch implementation has grown into a detailed comparison of the original changes and our current patterns and conventions. In this we have tried to highlight how we think the changes would be implemented if they followed our current norms. These are suggested and can be challenged. But we felt in this case "show don't tell" would be more appropriate to support the conversation!
- Loading branch information
1 parent
fc84d51
commit 0854af3
Showing
12 changed files
with
395 additions
and
426 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
'use strict' | ||
|
||
/** | ||
* Formats data for the `/licences/{id}/contact-details` view licence contact details page | ||
* @module ViewLicenceContactDetailsPresenter | ||
*/ | ||
|
||
/** | ||
* Formats data for the `/licences/{id}/contact-details` view licence contact details page | ||
* | ||
* @returns {Object} The data formatted for the view template | ||
*/ | ||
function go (contacts) { | ||
return { | ||
customerId: _findCustomerId(contacts), | ||
licenceContacts: _licenceContacts(contacts) | ||
} | ||
} | ||
|
||
function _findCustomerId (contacts) { | ||
const customerContact = contacts.find((contact) => { | ||
return contact.communicationType === 'Licence Holder' | ||
}) | ||
|
||
if (customerContact) { | ||
return customerContact.companyId | ||
} | ||
|
||
return null | ||
} | ||
|
||
function _licenceContactName (contact) { | ||
if (contact.contactId) { | ||
return `${contact.firstName || ''} ${contact.lastName}`.trim() | ||
} | ||
|
||
return contact.companyName | ||
} | ||
|
||
function _licenceContacts (contacts) { | ||
return contacts.map((contact) => { | ||
return { | ||
address: { | ||
address1: contact.address1, | ||
address2: contact.address2, | ||
address3: contact.address3, | ||
address4: contact.address4, | ||
address5: contact.address5, | ||
address6: contact.address6, | ||
country: contact.country, | ||
postcode: contact.postcode | ||
}, | ||
communicationType: contact.communicationType, | ||
name: _licenceContactName(contact) | ||
} | ||
}) | ||
} | ||
|
||
module.exports = { | ||
go | ||
} |
55 changes: 0 additions & 55 deletions
55
app/presenters/licences/view-licence-contact-details.presenter.js
This file was deleted.
Oops, something went wrong.
62 changes: 0 additions & 62 deletions
62
app/services/licences/fetch-licence-contact-details.service.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
'use strict' | ||
|
||
/** | ||
* Fetches all return logs for a licence which is needed for the view '/licences/{id}/contact-details` page | ||
* @module FetchLicenceContactDetailsService | ||
*/ | ||
|
||
const { db } = require('../../../db/db.js') | ||
|
||
/** | ||
* Fetches all contact details for a licence which is needed for the view '/licences/{id}/contact-details` page | ||
* | ||
* @param {string} licenceId - The UUID for the licence to fetch | ||
* | ||
* @returns {Promise<Object>} the data needed to populate the view licence page's contact details tab | ||
*/ | ||
async function go (licenceId) { | ||
return _fetch(licenceId) | ||
} | ||
|
||
async function _fetch (licenceId) { | ||
return db.withSchema('public') | ||
.select([ | ||
'lr.label AS communicationType', | ||
'cmp.id AS companyId', | ||
'cmp.name AS companyName', | ||
'con.id AS contactId', | ||
'con.firstName', | ||
'con.lastName', | ||
'a.address1', | ||
'a.address2', | ||
'a.address3', | ||
'a.address4', | ||
'a.address5', | ||
'a.address6', | ||
'a.postcode', | ||
'a.country' | ||
]) | ||
.from('licenceDocuments AS ld') | ||
.innerJoin('licences AS l', 'l.licenceRef', '=', 'ld.licenceRef') | ||
.innerJoin('licenceDocumentRoles AS ldr', 'ldr.licenceDocumentId', '=', 'ld.id') | ||
.innerJoin('licenceRoles AS lr', 'lr.id', '=', 'ldr.licenceRoleId') | ||
.innerJoin('companies AS cmp', 'cmp.id', '=', 'ldr.companyId') | ||
.leftJoin('contacts AS con', 'con.id', '=', 'ldr.contactId') | ||
.innerJoin('addresses AS a', 'a.id', '=', 'ldr.addressId') | ||
.where('l.id', '=', licenceId) | ||
.andWhere((builder) => { | ||
builder.whereNull('ldr.end_date').orWhere('ldr.end_date', '>', db.raw('NOW()')) | ||
}) | ||
.orderBy('lr.label', 'desc') | ||
} | ||
|
||
module.exports = { | ||
go | ||
} |
19 changes: 11 additions & 8 deletions
19
app/services/licences/view-licence-contact-details.service.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.