Skip to content

Commit

Permalink
Add start-for-ten fetch service
Browse files Browse the repository at this point in the history
This gives an initial starting example for how we can grab the data we need for the view without needing to make a request to the legacy service or parse its response.
  • Loading branch information
Cruikshanks committed Jan 13, 2025
1 parent 30d3ba2 commit 03ac67b
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions app/services/return-logs/fetch-return-log.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict'

const ReturnLogModel = require('../../../app/models/return-log.model.js')

/**
* Fetch the selected return log and all associated data needed for the view
*
* @param {string} returnId - The return log ID
*
* @returns {Promise<module:ReturnLogModel>} the matching `ReturnLogModel` instance
*/
async function go(returnId) {
return _fetch(returnId)
}

async function _fetch(returnId) {
return ReturnLogModel.query()
.findById(returnId)
.withGraphFetched('licence')
.withGraphFetched('returnSubmissions')
.modifyGraph('returnSubmissions', (returnSubmissionsBuilder) => {
returnSubmissionsBuilder.orderBy('version', 'desc').limit(1).withGraphFetched('returnSubmissionLines')
})
}

module.exports = {
go
}

0 comments on commit 03ac67b

Please sign in to comment.