Skip to content

Commit

Permalink
PP-11877 adding filter persistence logic, preventing submission to le…
Browse files Browse the repository at this point in the history
…dger api, applying validation logic to all services transaction UI page.
  • Loading branch information
olatomgds committed Dec 14, 2023
1 parent ef484ad commit a1701ca
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 27 deletions.
2 changes: 1 addition & 1 deletion app/controllers/all-service-transactions/get.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module.exports = async function getTransactionsForAllServices (req, res, next) {
const searchResultOutput = await transactionService.search(userPermittedAccountsSummary.gatewayAccountIds, filters.result)
const cardTypes = await client.getAllCardTypes()
const downloadRoute = filterLiveAccounts ? paths.allServiceTransactions.download : paths.formattedPathFor(paths.allServiceTransactions.downloadStatusFilter, 'test')
const model = buildPaymentList(searchResultOutput, cardTypes, null, filters.result, downloadRoute, req.session.backPath)
const model = buildPaymentList(searchResultOutput, cardTypes, null, filters.result,filters.dateRangeState, downloadRoute, req.session.backPath)
delete req.session.backPath
model.search_path = filterLiveAccounts ? paths.allServiceTransactions.index : paths.formattedPathFor(paths.allServiceTransactions.indexStatusFilter, 'test')
model.filtersDescription = describeFilters(filters.result)
Expand Down
24 changes: 14 additions & 10 deletions app/controllers/transactions/transaction-list.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,26 @@ module.exports = async function showTransactionList (req, res, next) {

req.session.filters = url.parse(req.url).query

// This ssort of error handling may not be appropriate
//if (!filters.dateRangeState.validDateRange) {
// console.log('You have entered an invalid date range')
// return next(new Error('You have entered an invalid date range'))
//}

if (!filters.valid) {
return next(new Error('Invalid search'))
}

let noTransactionSearchResults = {
total: 0,
count: 0,
page: 1,
results: [],
_links: {},
filters: {},
}
let result

try {
result = await Promise.all([
transactionService.search([accountId], filters.result),
client.getAllCardTypes()
])
result = await Promise.all([
(filters.dateRangeState.isInvalidDateRange) ?
noTransactionSearchResults : transactionService.search([accountId], filters.result) ,
client.getAllCardTypes()
])
} catch (error) {
return next(error)
}
Expand Down
13 changes: 6 additions & 7 deletions app/utils/filters.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

const qs = require('qs')
const moment = require('moment-timezone')
const check = require('check-types')
const Paginator = require('../utils/paginator.js')
const states = require('../utils/states')
Expand All @@ -25,16 +26,14 @@ function trimFilterValues (filters) {
}

function validateDateRange(filters){
var fromDate = new Date(filters.fromDate).getTime()
var toDate = new Date(filters.toDate).getTime()
var isValid = false
let result = moment(filters.fromDate, 'DD/MM/YYYY').isAfter(moment(filters.toDate, 'DD/MM/YYYY'))? 1: -1;
var isInvalid = false

if (fromDate < toDate) {
isValid = true
if (result == 1) {
isInvalid = true
}

return {
validDateRange: isValid,
isInvalidDateRange: isInvalid,
fromDateParam: filters.fromDate,
toDateParam: filters.toDate
}
Expand Down
5 changes: 3 additions & 2 deletions app/utils/transaction-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ module.exports = {
connectorData.total = connectorData.total || (connectorData.results && connectorData.results.length)
connectorData.totalOverLimit = connectorData.total > LEDGER_TRANSACTION_COUNT_LIMIT
connectorData.showCsvDownload = showCsvDownload(connectorData, filtersResult)
connectorData.filtersDateRangeState = filtersDateRangeState
connectorData.isInvalidDateRange = filtersDateRangeState.isInvalidDateRange === true
connectorData.fromDateParam = filtersDateRangeState.fromDateParam
connectorData.toDateParam = filtersDateRangeState.toDateParam
connectorData.totalFormatted = connectorData.total.toLocaleString()
connectorData.maxLimitFormatted = parseInt(LEDGER_TRANSACTION_COUNT_LIMIT).toLocaleString()
connectorData.paginationLinks = getPaginationLinks(connectorData)
connectorData.hasPaginationLinks = !!getPaginationLinks(connectorData)

connectorData.hasPageSizeLinks = hasPageSizeLinks(connectorData)
connectorData.pageSizeLinks = getPageSizeLinks(connectorData)

Expand Down
12 changes: 6 additions & 6 deletions app/views/transactions/index.njk
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,19 @@

{% include "transactions/display-size.njk" %}

<h3 class="govuk-heading-s govuk-!-font-weight-regular govuk-!-margin-top-3" id="total-results">
{% if (isInvalidDateRange) %}
<p class="govuk-body" id="invalid-date-range">End date must be after start date</p>
<p class="govuk-body" id="invalid-date-range">The from date entered is <strong>{{fromDateParam}}</strong> and the to date entered is <strong>{{toDateParam}}</strong> </p>
{% else %}
<h3 class="govuk-heading-s govuk-!-font-weight-regular govuk-!-margin-top-3" id="total-results">
{% if totalOverLimit %}
Over {{maxLimitFormatted}} transactions
{% else %}
{{totalFormatted}} transactions
{% endif %}
{{ filtersDescription | safe }}
</h3>
{% endif %}

{% if allServiceTransactions or permissions.transactions_download_read %}

Expand All @@ -92,11 +97,6 @@
{% include "transactions/paginator.njk" %}

{% include "transactions/list.njk" %}

{% if (!filtersDateRangeState.isValid) %}
<p class="govuk-body" id="invalid-date-range">You have entered an invalid date range, the from date must be earlier than the to date.</p>
<p class="govuk-body" id="invalid-date-range">The from date entered is {{showInvalidDateRangeError.fromDateParam}} and the to date entered is {{showInvalidDateRangeError.toDateParam}} </p>
{% endif %}

{% include "transactions/paginator.njk" %}
</div>
Expand Down
5 changes: 4 additions & 1 deletion app/views/transactions/list.njk
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,8 @@
</tbody>
</table>
{% else %}
<p class="govuk-body" id="no-results">There are no results for the filters you used.</p>
{% if (isInvalidDateRange) %}
{% else %}
<p class="govuk-body" id="no-results">There are no results for the filters you used.</p>
{% endif %}
{% endif %}

0 comments on commit a1701ca

Please sign in to comment.