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

Handle returns without alias in friendly response #366

Merged
merged 1 commit into from
Aug 17, 2023
Merged
Changes from all commits
Commits
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
30 changes: 19 additions & 11 deletions app/services/check/friendly-response.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function _formatFriendlyReturns (returns, matchedReturns) {
const friendlyReturn = {
id: returnId,
siteDescription: _titleCaseAllWords(metadata.description),
purpose: _titleCaseAllWords(metadata.purposes[0].alias),
purpose: _formatPurpose(metadata.purposes[0]),
returnPeriod: `${formatLongDate(startDate)} to ${formatLongDate(endDate)}`,
abstractionPeriod: formatAbstractionPeriod(periodStartDay, periodStartMonth, periodEndDay, periodEndMonth),
twoPartTariff: metadata.isTwoPartTariff,
Expand Down Expand Up @@ -212,17 +212,12 @@ function _formatAdjustments (adjustments) {
return friendlyAdjustments
}

function _titleCaseAllWords (stringToBeTitleCased) {
const lowercaseWords = stringToBeTitleCased.toLowerCase().split(' ')

const titleCaseWords = lowercaseWords.reduce((words, lowercaseWord) => {
const titleCasedWord = `${lowercaseWord[0].toUpperCase()}${lowercaseWord.slice(1)}`
words.push(titleCasedWord)

return words
}, [])
function _formatPurpose (purpose) {
if (purpose.alias) {
return _titleCaseAllWords(purpose.alias)
}

return titleCaseWords.join(' ')
return _titleCaseAllWords(purpose.tertiary.description)
}

function _formatTimeLimit (startDate, endDate) {
Expand All @@ -241,6 +236,19 @@ function _formatWaterAvailability (isRestrictedSource) {
return 'Available'
}

function _titleCaseAllWords (stringToBeTitleCased) {
const lowercaseWords = stringToBeTitleCased.toLowerCase().split(' ')

const titleCaseWords = lowercaseWords.reduce((words, lowercaseWord) => {
const titleCasedWord = `${lowercaseWord[0].toUpperCase()}${lowercaseWord.slice(1)}`
words.push(titleCasedWord)

return words
}, [])

return titleCaseWords.join(' ')
}

module.exports = {
go
}