Skip to content

Commit

Permalink
Make it work following merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Jozzey committed Dec 31, 2024
1 parent 6e508e9 commit 781a196
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 92 deletions.
20 changes: 8 additions & 12 deletions app/controllers/return-logs-edit.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
* @module ReturnLogsEditController
*/

const EditReturnLogService = require('../services/return-logs/edit-return-log.service.js')
const EditReturnLogService = require('../services/return-logs-edit/edit-return-log.service.js')
const InitiateSessionService = require('../services/return-logs-edit/initiate-session.service.js')

const basePath = 'return-log-edit'
const basePath = '/system/return-log-edit'

async function edit(request, h) {
const { returnLogId } = request.query
const pageData = await EditReturnLogService.go(returnLogId)
const { sessionId } = request.params
const pageData = await EditReturnLogService.go(sessionId)

return h.view('return-logs-edit/how-to-edit.njk', { activeNavBar: 'search', ...pageData })
}
Expand All @@ -21,14 +21,14 @@ async function setup(request, h) {
const { returnLogId } = request.query
const session = await InitiateSessionService.go(returnLogId)

return h.redirect(`/system/${basePath}/${session.id}/how-to-edit`)
return h.redirect(`${basePath}/${session.id}/how-to-edit`)
}

async function submitEdit(request, h) {
const { returnLogId } = request.query
const { sessionId } = request.params
const { howToEdit } = request.payload

const pageData = await EditReturnLogService.go(returnLogId)
const pageData = await EditReturnLogService.go(sessionId)

if (!howToEdit) {
return h.view('return-logs-edit/how-to-edit.njk', {
Expand All @@ -38,11 +38,7 @@ async function submitEdit(request, h) {
})
}

if (howToEdit === 'query') {
// TODO: Set/unset the query flag
}

return h.redirect(`/system/return-logs/edit/${howToEdit}?returnLogId=${returnLogId}`)
return h.redirect(`${basePath}/${sessionId}/${howToEdit}`)
}

module.exports = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ const { formatAbstractionPeriod, formatLongDate } = require('../base.presenter.j
/**
* Formats the data ready for presenting in the abstraction return page
*
* @param {module:ReturnLogModel} editReturnLog - instance of the `ReturnLogModel` returned from
* `FetchEditReturnLogService`
* @param {module:SessionModel} session - The session instance to format
*
* @returns {object} page date needed for the abstraction return page
*/
function go(editReturnLog) {
function go(session) {
const {
endDate,
licenceId,
Expand All @@ -31,7 +30,7 @@ function go(editReturnLog) {
startDate,
twoPartTariff,
underQuery
} = editReturnLog
} = session

return {
abstractionPeriod: `From ${formatAbstractionPeriod(
Expand All @@ -43,34 +42,16 @@ function go(editReturnLog) {
licenceId,
licenceRef,
pageTitle: 'Abstraction return',
purposes: _formatPurposes(purposes),
purposes,
queryText: underQuery ? 'Resolve query' : 'Record under query',
returnLogId,
returnsPeriod: `From ${formatLongDate(startDate)} to ${formatLongDate(endDate)}`,
returnsPeriod: `From ${formatLongDate(new Date(startDate))} to ${formatLongDate(new Date(endDate))}`,
returnReference,
siteDescription,
tariffType: twoPartTariff ? 'Two part tariff' : 'Standard tariff'
}
}

/**
* Format the purposes for a return log
*
* It is possible that a return log has more than one purpose associated it. If this is the case we need the description
* of each purpose from the array of purposes to be concatenated into a single comma separated string ready to present.
*
* @param {Array} purposes - the purposes taken from the return logs metadata
*
* @returns {string} the purpose descriptions as a string, separated by commas if more than one description exists
*/
function _formatPurposes(purposes) {
const purposeDescriptionArray = purposes.map((purpose) => {
return purpose.tertiary.description
})

return purposeDescriptionArray.join(', ')
}

module.exports = {
go
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@
* @module EditReturnLogService
*/

const FetchEditReturnLogService = require('./fetch-edit-return-log.service.js')
const EditReturnLogPresenter = require('../../presenters/return-logs/edit-return-log.presenter.js')
const SessionModel = require('../../models/session.model.js')
const EditReturnLogPresenter = require('../../presenters/return-logs-edit/edit-return-log.presenter.js')

/**
* Orchestrates fetching and presenting the data needed for the how to edit an abstraction return page
*
* @param {string} returnLogId - The ID of the return log to edit
* @param {string} sessionId - The UUID for setup bill run session record
*
* @returns {Promise<object>} page data needed by the view template
*/
async function go(returnLogId) {
const editReturnLog = await FetchEditReturnLogService.go(returnLogId)
const pageData = EditReturnLogPresenter.go(editReturnLog)
async function go(sessionId) {
const session = await SessionModel.query().findById(sessionId)

return pageData
return EditReturnLogPresenter.go(session)
}

module.exports = {
Expand Down
49 changes: 0 additions & 49 deletions app/services/return-logs/fetch-edit-return-log.service.js

This file was deleted.

0 comments on commit 781a196

Please sign in to comment.