Skip to content

Commit

Permalink
Remove FetchReturnCyclesService
Browse files Browse the repository at this point in the history
Having demonstrated we can get the same results with a simple query I feel we no longer need the service.
  • Loading branch information
Cruikshanks committed Dec 6, 2024
1 parent 1638d6b commit 600cf91
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 125 deletions.
42 changes: 0 additions & 42 deletions app/services/return-logs/fetch-return-cycles.service.js

This file was deleted.

22 changes: 14 additions & 8 deletions app/services/return-logs/process-licence-return-logs.service.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,41 @@
'use strict'

/**
* Process voiding and issuing return logs for a given licence reference
* Process voiding and reissuing return logs for a given licence reference
* @module ProcessLicenceReturnLogsService
*/

const { calculateAndLogTimeTaken, currentTimeInNanoseconds } = require('../../lib/general.lib.js')
const CreateReturnLogsService = require('./create-return-logs.service.js')
const FetchReturnCyclesService = require('./fetch-return-cycles.service.js')
const FetchReturnRequirementsService = require('./fetch-return-requirements.service.js')
const GenerateReturnLogsService = require('./generate-return-logs.service.js')
const GenerateReturnLogService = require('./generate-return-log.service.js')
const ReturnCycleModel = require('../../models/return-cycle.model.js')
const VoidReturnLogsService = require('./void-return-logs.service.js')

/**
* Process voiding and issuing return logs for a given licence reference
* Process voiding and reissuing return logs for a given licence reference
*
* @param {string} licenceReference - The licence to create return logs for
* @param {Date} [endDate] - An optional end date to use when determining which return logs to void and reissue
*/
async function go(licenceReference, endDate = null) {
try {
const startTime = currentTimeInNanoseconds()
let returnCycles = []

if (endDate) {
await VoidReturnLogsService.go(licenceReference, endDate)
returnCycles = await FetchReturnCyclesService.go(endDate)
} else {
returnCycles = await FetchReturnCyclesService.go(new Date())
endDate = new Date()
}

const returnCycles = await _fetchReturnCycles(endDate)
const returnLogs = []

for (const returnCycle of returnCycles) {
const returnRequirements = await FetchReturnRequirementsService.go(returnCycle, licenceReference)

for (const returnRequirement of returnRequirements) {
const returnLog = await GenerateReturnLogsService.go(returnRequirement, returnCycle)
const returnLog = GenerateReturnLogService.go(returnRequirement, returnCycle)

returnLogs.push(returnLog)
}
Expand All @@ -50,6 +49,13 @@ async function go(licenceReference, endDate = null) {
}
}

async function _fetchReturnCycles(endDate) {
return ReturnCycleModel.query()
.select(['dueDate', 'endDate', 'id', 'startDate', 'summer'])
.where('endDate', '>=', endDate)
.orderBy('endDate', 'desc')
}

module.exports = {
go
}
75 changes: 0 additions & 75 deletions test/services/return-logs/fetch-return-cycles.service.test.js

This file was deleted.

0 comments on commit 600cf91

Please sign in to comment.