diff --git a/backend/src/components/pdf.js b/backend/src/components/pdf.js index b6bda685..b1cbdbd8 100644 --- a/backend/src/components/pdf.js +++ b/backend/src/components/pdf.js @@ -1,7 +1,7 @@ /* eslint-disable quotes */ 'use strict'; const { - getOperation, + getSubmissionPDFHistory, getDocument } = require('./utils'); const HttpStatus = require('http-status-codes'); @@ -30,37 +30,12 @@ async function getPdf(req, res) { async function getPdfs(req, res) { try { - const operationParentApplication = `ccof_applications?$filter=ccof_applicationid eq ${req.params.applicationId}`; - const parentApplicationResponse = await getOperation(operationParentApplication); - const type = parentApplicationResponse.value[0]['ccof_applicationtype@OData.Community.Display.V1.FormattedValue']; - const fiscalYear = parentApplicationResponse.value[0]['_ccof_programyear_value@OData.Community.Display.V1.FormattedValue']; - - const operationSummaryDeclaration = `ccof_applicationsummaries?$filter=_ccof_application_value eq ${req.params.applicationId}&$expand=ccof_applicationsummary_Annotations($select=annotationid,filename,subject,filesize, createdon)`; - const summaryDeclarationResponse = await getOperation(operationSummaryDeclaration); - - const operationRequestChange = `ccof_change_request_summaries?$select=ccof_name&$expand=ccof_change_request_summary_Annotations($select=filename,annotationid,subject,filesize,createdon),ccof_changerequest($select=ccof_change_requestid, ccof_name,_ccof_application_value,ccof_changetypes)&$filter=(ccof_changerequest/_ccof_application_value eq ${req.params.applicationId})`; - const requestChangeResponse = await getOperation(operationRequestChange); - - let documentList = [] - - for (let document of summaryDeclarationResponse.value) { - let documentForFront = new MappableObjectForFront(document.ccof_applicationsummary_Annotations[0], PdfDocumentMappings); - documentForFront.data.appId = document['_ccof_application_value@OData.Community.Display.V1.FormattedValue']; - documentForFront.data.subject = type; - documentForFront.data.fiscalYear = fiscalYear; - documentList.push(documentForFront); - } - - for (let document of requestChangeResponse.value) { - if(document?.ccof_change_request_summary_Annotations?.length>0){ - let documentForFront = new MappableObjectForFront(document.ccof_change_request_summary_Annotations[0], PdfDocumentMappings); - documentForFront.data.appId = document.ccof_changerequest.ccof_name; - documentForFront.data.subject = document.ccof_changerequest['ccof_changetypes@OData.Community.Display.V1.FormattedValue']; - documentForFront.data.fiscalYear = fiscalYear; - documentList.push(documentForFront); - } - } - return res.status(HttpStatus.CREATED).json(documentList); + const response = await getSubmissionPDFHistory(req.params.organizationId); + log.info('getSubmissionPDFHistory for organization: ' + req.params.organizationId); + log.info(response); + let documentList = []; + response?.forEach(document => documentList.push(new MappableObjectForFront(document, PdfDocumentMappings))); + return res.status(HttpStatus.OK).json(documentList); } catch (e) { log.error('error', e); return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(e.data ? e.data : e?.status); diff --git a/backend/src/components/utils.js b/backend/src/components/utils.js index aa020271..7fdf5519 100644 --- a/backend/src/components/utils.js +++ b/backend/src/components/utils.js @@ -237,6 +237,18 @@ async function postChangeRequestSummaryDocument(payload) { } } +async function getSubmissionPDFHistory(organizationId){ + try { + const url = config.get('dynamicsApi:apiEndpoint') + '/api/SubmissionPDFHistory?OrgId=' + organizationId; + log.info('get Data Url', url); + const response = await axios.get(url, getHttpHeader()); + return response.data; + } catch (e) { + log.error(' getSubmissionPDFHistory Error', e.response ? e.response.status : e.message); + throw new ApiError(HttpStatus.INTERNAL_SERVER_ERROR, {message: 'API Get error'}, e); + } +} + async function getDocument(annotationId){ try { const url = config.get('dynamicsApi:apiEndpoint') + '/api/Document?annotationId=' + annotationId; @@ -397,6 +409,7 @@ const utils = { postChangeActionDocument, updateChangeRequestNewFacility, postChangeRequestSummaryDocument, + getSubmissionPDFHistory }; module.exports = utils; diff --git a/backend/src/routes/pdf.js b/backend/src/routes/pdf.js index 115702db..8725a32f 100644 --- a/backend/src/routes/pdf.js +++ b/backend/src/routes/pdf.js @@ -13,8 +13,8 @@ router.get('/getDocument/:annotationId', auth.refreshJWT,isValidBackendToken, [ }); //Gets all the pdfs for summaryDeclaration and changeRequest submissions -router.get('/:applicationId', passport.authenticate('jwt', {session: false}, undefined),isValidBackendToken, [ - param('applicationId', 'URL param: [applicationId] is required').not().isEmpty()], (req, res) => { +router.get('/:organizationId', passport.authenticate('jwt', {session: false}, undefined),isValidBackendToken, [ + param('organizationId', 'URL param: [organizationId] is required').not().isEmpty()], (req, res) => { return getPdfs(req, res); }); diff --git a/backend/src/util/mapping/Mappings.js b/backend/src/util/mapping/Mappings.js index 9bb1be36..4b621731 100644 --- a/backend/src/util/mapping/Mappings.js +++ b/backend/src/util/mapping/Mappings.js @@ -433,9 +433,11 @@ const ChangeRequestMappings = [ const PdfDocumentMappings = [ {back: 'annotationid', front: 'annotationId'}, {back: 'filename', front: 'fileName'}, - {back: 'subject', front: 'subject'}, + {back: 'type', front: 'type'}, + {back: 'submissiondate', front: 'submissionDate'}, + {back: 'fiscalyear', front: 'fiscalYear'}, + {back: 'id', front: 'appId'}, {back: 'filesize', front: 'fileSize'}, - {back: 'createdon', front: 'createDate'}, ]; module.exports = { diff --git a/frontend/src/components/SubmissionHistory.vue b/frontend/src/components/SubmissionHistory.vue index 70f88454..929be427 100644 --- a/frontend/src/components/SubmissionHistory.vue +++ b/frontend/src/components/SubmissionHistory.vue @@ -23,8 +23,8 @@ fixed-header class="elevation-4 my-4" disable-pagination hide-default-footer - :sort-by="['priority', 'submissionDate']" - :sort-desc="[true, true]" + :sort-by="['submissionDate']" + :sort-desc="[true]" v-if="!processing" >