diff --git a/app/presenters/licences/view-licence-returns.presenter.js b/app/presenters/licences/view-licence-returns.presenter.js index 93b0284157..81fd73c7ee 100644 --- a/app/presenters/licences/view-licence-returns.presenter.js +++ b/app/presenters/licences/view-licence-returns.presenter.js @@ -34,29 +34,36 @@ function _formatPurpose (purpose) { } function _formatReturnToTableRow (returns) { - return returns.map((r) => { + return returns.map((returnLog) => { return { - dates: `${formatLongDate(new Date(r.startDate))} to ${formatLongDate(new Date(r.endDate))}`, - description: r.metadata.description, - dueDate: formatLongDate(new Date(r.dueDate)), - id: r.id, - purpose: _formatPurpose(r.metadata.purposes), - reference: r.returnReference, - status: _formatStatus(r.status) + dates: `${formatLongDate(new Date(returnLog.startDate))} to ${formatLongDate(new Date(returnLog.endDate))}`, + description: returnLog.metadata.description, + dueDate: formatLongDate(new Date(returnLog.dueDate)), + id: returnLog.id, + purpose: _formatPurpose(returnLog.metadata.purposes), + reference: returnLog.returnReference, + status: _formatStatus(returnLog) } }) } -function _formatStatus (status) { +function _formatStatus (returnLog) { + const { status, dueDate } = returnLog + + // If the return is completed we are required to display it as 'complete'. This also takes priority over the other + // statues if (status === 'completed') { - return 'COMPLETE' + return 'complete' } - if (status === 'due') { - return 'OVERDUE' + // Work out if the return is overdue (status is still 'due' and it is past the due date) + const today = new Date() + if (status === 'due' && dueDate < today) { + return 'overdue' } - return 'NO STATUS' + // For all other cases we can just return the status and the return-status-tag macro will know how to display it + return status } function _noReturnsMessage (hasReturns, hasRequirements) { diff --git a/app/services/licences/fetch-licence-returns.service.js b/app/services/licences/fetch-licence-returns.service.js index a899f81c35..a78334693a 100644 --- a/app/services/licences/fetch-licence-returns.service.js +++ b/app/services/licences/fetch-licence-returns.service.js @@ -5,9 +5,9 @@ * @module FetchLicenceReturnsService */ -const ReturnLogModel = require('../../models/return-log.model') +const ReturnLogModel = require('../../models/return-log.model.js') -const DatabaseConfig = require('../../../config/database.config') +const DatabaseConfig = require('../../../config/database.config.js') /** * Fetches all return logs for a licence which is needed for the view '/licences/{id}/returns` page diff --git a/app/views/licences/tabs/returns.njk b/app/views/licences/tabs/returns.njk index db2861f6a5..fb8873657c 100644 --- a/app/views/licences/tabs/returns.njk +++ b/app/views/licences/tabs/returns.njk @@ -1,23 +1,7 @@ {% from "govuk/components/pagination/macro.njk" import govukPagination %} {% from "govuk/components/table/macro.njk" import govukTable %} -{% from "govuk/components/tag/macro.njk" import govukTag %} -{% macro formatStatus(status) %} - {% if status === 'COMPLETE' %} - {{ govukTag({ - text: status, - classes: "govuk-tag--green" - }) }} - - {% elseif status === 'OVERDUE' %} - {{ govukTag({ - text: status, - classes: "govuk-tag--red" - }) }} - {% else %} - {{ status }} - {% endif %} -{% endmacro %} +{% from "macros/return-status-tag.njk" import statusTag %}