Skip to content

Commit

Permalink
Update ProcessLicenceReturnLogs to create in place
Browse files Browse the repository at this point in the history
We make a similar change to the service that we did to `ProcessReturnLogs` on the jobs side, and instead of saving the results to an array we then pass to the CreateReturnLogsService, we instead create in place.

You'll notice there is no error handling in this version as well. But more on that in the next change!
  • Loading branch information
Cruikshanks committed Dec 6, 2024
1 parent 600cf91 commit 9d04f7e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 173 deletions.
27 changes: 0 additions & 27 deletions app/services/return-logs/create-return-logs.service.js

This file was deleted.

18 changes: 10 additions & 8 deletions app/services/return-logs/process-licence-return-logs.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
* @module ProcessLicenceReturnLogsService
*/

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

/**
Expand All @@ -29,26 +29,28 @@ async function go(licenceReference, endDate = null) {
}

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 = GenerateReturnLogService.go(returnRequirement, returnCycle)

returnLogs.push(returnLog)
await _createReturnLog(returnRequirement, returnCycle)
}
}

await CreateReturnLogsService.go(returnLogs)

calculateAndLogTimeTaken(startTime, 'Create licence return logs job complete', { licenceReference })
} catch (error) {
global.GlobalNotifier.omfg('Create licence return logs job failed', { error })
}
}

async function _createReturnLog(returnRequirement, returnCycle) {
const returnLog = GenerateReturnLogService.go(returnRequirement, returnCycle)
const timestamp = timestampForPostgres()

await ReturnLogModel.query().insert({ ...returnLog, createdAt: timestamp, updatedAt: timestamp })
}

async function _fetchReturnCycles(endDate) {
return ReturnCycleModel.query()
.select(['dueDate', 'endDate', 'id', 'startDate', 'summer'])
Expand Down
138 changes: 0 additions & 138 deletions test/services/return-logs/create-return-logs.service.test.js

This file was deleted.

0 comments on commit 9d04f7e

Please sign in to comment.