Skip to content

Commit

Permalink
Merge pull request #255 from bcgov/ofmcc-3498-supp-app-timing-issue
Browse files Browse the repository at this point in the history
omfcc-1629 PDF for supp apps
  • Loading branch information
jenbeckett authored Jun 21, 2024
2 parents 06ee1b4 + 7624aaa commit eee0a01
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 22 deletions.
12 changes: 12 additions & 0 deletions backend/src/components/applications.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,17 @@ async function deleteSupplementaryApplication(req, res) {
}
}

async function getSupplementaryApplicationPDF(req, res) {
try {
const operation = `ofm_allowances(${req.params.applicationId})/ofm_supplementaryapplicationpdf`
const response = await getOperation(operation)
return res.status(HttpStatus.OK).json(response?.value)
} catch (e) {
log.error(e)
return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(e.data ? e.data : e?.status)
}
}

async function createEmployeeCertificate(req, res) {
try {
const payload = {
Expand Down Expand Up @@ -240,4 +251,5 @@ module.exports = {
updateEmployeeCertificate,
deleteEmployeeCertificate,
getApplicationPDF,
getSupplementaryApplicationPDF,
}
18 changes: 17 additions & 1 deletion backend/src/routes/applications.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const {
updateEmployeeCertificate,
deleteEmployeeCertificate,
getApplicationPDF,
getSupplementaryApplicationPDF,
} = require('../components/applications')
const { param, validationResult, checkSchema } = require('express-validator')
const validatePermission = require('../middlewares/validatePermission.js')
Expand Down Expand Up @@ -97,7 +98,7 @@ router.get(
)

/**
* Get Funding Agreement PDF by ID
* Get OFM Application PDF by ID
*/
router.get(
'/:applicationId/pdf',
Expand Down Expand Up @@ -179,6 +180,21 @@ router.delete(
},
)

/**
* Get Supplementary Application PDF by ID
*/
router.get(
'/supplementary/:applicationId/pdf',
passport.authenticate('jwt', { session: false }),
isValidBackendToken,
validatePermission(PERMISSIONS.VIEW_APPLICATIONS),
[param('applicationId', 'URL param: [applicationId] is required').not().isEmpty()],
(req, res) => {
validationResult(req).throw()
return getSupplementaryApplicationPDF(req, res)
},
)

/**
* Create a new provider employee certificate
*/
Expand Down
11 changes: 11 additions & 0 deletions frontend/src/services/applicationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,17 @@ export default {
}
},

async getSupplementaryApplicationPDF(applicationId) {
try {
if (!applicationId) return
const response = await ApiService.apiAxios.get(`${ApiRoutes.SUPPLEMENTARY_APPLICATIONS}/${applicationId}/pdf`)
return response?.data
} catch (error) {
console.log(`Failed to get the supp application PDF by application id - ${error}`)
throw error
}
},

isValidApplication(application) {
return this.checkApplicationStatus(application) && this.checkFundingAgreement(application?.fundingAgreement)
},
Expand Down
44 changes: 23 additions & 21 deletions frontend/src/views/applications/ApplicationsHistoryView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,11 @@ export default {
},
isApplicationDownloadable(application) {
return !this.DRAFT_STATUS_CODES.includes(application?.statusCode)
//OFM core generates PDF upon submit - Supp App generates PDF only once approved
if (application.applicationType === APPLICATION_TYPES.OFM) {
return !this.DRAFT_STATUS_CODES.includes(application?.statusCode)
}
return application.statusCode === SUPPLEMENTARY_APPLICATION_STATUS_CODES.APPROVED
},
toggleCancelDialog(item) {
Expand Down Expand Up @@ -367,28 +371,26 @@ export default {
})
return applicationItems
},
//TODO - Add Supp App PDF function will look very similar, but it will hit a seperate endpoint
//the supp app PDF's do not generate yet in Dynamics, so holding off on including that code
async downloadPDF(application) {
if (application.applicationType === APPLICATION_TYPES.OFM) {
try {
const resp = await ApplicationService.getApplicationPDF(application.applicationId)
const link = document.createElement('a')
link.href = `data:application/pdf;base64,${resp}`
link.target = '_blank'
link.download = application.referenceNumber
// Simulate a click on the element <a>
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
} catch (error) {
this.setFailureAlert('Failed to download OFM PDF', error)
try {
let resp
if (application.applicationType === APPLICATION_TYPES.OFM) {
resp = await ApplicationService.getApplicationPDF(application.applicationId)
} else {
resp = await ApplicationService.getSupplementaryApplicationPDF(application.supplementaryApplicationId)
}
} else {
//it's a supp app
this.setSuccessAlert(`COMING SOON! A supplementary PDF will be downloaded here.`)
const link = document.createElement('a')
link.href = `data:application/pdf;base64,${resp}`
link.target = '_blank'
link.download = application.referenceNumber
// Simulate a click on the element <a>
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
} catch (error) {
this.setWarningAlert('PDF Generation is still in progress. Please wait a few minutes before you try again.')
}
},
},
Expand Down

0 comments on commit eee0a01

Please sign in to comment.