Skip to content

Commit

Permalink
Merge pull request #446 from bcgov/report-changes-Viet
Browse files Browse the repository at this point in the history
Bug fixes for release 195 - CCFRI-1840 and CCFRI-2847
  • Loading branch information
jenbeckett authored Sep 29, 2023
2 parents f8da8dc + 4f4d6af commit cbaa0ac
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 50 deletions.
39 changes: 7 additions & 32 deletions backend/src/components/pdf.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable quotes */
'use strict';
const {
getOperation,
getSubmissionPDFHistory,
getDocument
} = require('./utils');
const HttpStatus = require('http-status-codes');
Expand Down Expand Up @@ -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]['[email protected]'];
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['[email protected]'];
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);
Expand Down
13 changes: 13 additions & 0 deletions backend/src/components/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -397,6 +409,7 @@ const utils = {
postChangeActionDocument,
updateChangeRequestNewFacility,
postChangeRequestSummaryDocument,
getSubmissionPDFHistory
};

module.exports = utils;
4 changes: 2 additions & 2 deletions backend/src/routes/pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down
6 changes: 4 additions & 2 deletions backend/src/util/mapping/Mappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
14 changes: 7 additions & 7 deletions frontend/src/components/SubmissionHistory.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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"
>
<template v-slot:item.facilityNames="{ item }">
Expand Down Expand Up @@ -78,7 +78,7 @@
};
},
computed: {
...mapState('application', ['applicationId']),
...mapState('organization', ['organizationId']),
...mapState('document',['pdfs']),
isReadOnly() {
return false;
Expand All @@ -90,10 +90,10 @@
index: index,
annotationId: submission?.annotationId,
appId: submission?.appId,
type: submission?.subject,
type: submission?.type,
fiscalYear: submission?.fiscalYear.replace(/[^\d/]/g, ''),
submissionDate: submission?.createDate,
submissionDateString: this.getSubmissionDateString(submission?.createDate),
submissionDate: submission?.submissionDate,
submissionDateString: this.getSubmissionDateString(submission?.submissionDate),
fileName: submission?.fileName,
fileSize: Math.round(submission?.fileSize/100)/10,
};
Expand Down Expand Up @@ -129,7 +129,7 @@
},
async mounted() {
this.processing = true;
await this.getPDFs(this.applicationId);
await this.getPDFs(this.organizationId);
this.processing = false;
},
beforeRouteLeave(_to, _from, next) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
<v-row>
<v-col>
<label>If you only offer care for <strong>4 days or fewer </strong> per week, enter daily parent fees.</label><br>
<label>Enter your <strong>highest {{item.feeFrequency?.toLowerCase()}} parent fee before CCFRI is applied</strong> in every month below. If you do not charge a parent fee (e.g. if the facility is closed) enter zero.</label>
<label>Enter your <strong>highest {{item.feeFrequency?.toLowerCase()}} parent fee before CCFRI is applied</strong> in every month below. If there is a month where you do not charge a parent fee, enter zero.</label>
</v-col>
</v-row>
<v-row>
Expand Down
9 changes: 3 additions & 6 deletions frontend/src/store/modules/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,11 @@ export default {
const documents = getters.unsubmittedDocuments.filter(document => document.documentID !== documentID);
commit('setUnsubmittedDocuments', documents);
},
async getPDFs({commit}, applicationId) {
console.log('trying to get pdfs for ', applicationId);
async getPDFs({commit}, organizationId) {
checkSession();
try {
let response = (await ApiService.apiAxios.get(ApiRoutes.PDFS + '/' + applicationId))?.data;
console.log('THIS IS PDFs RESPONSE = ');
console.log(response);
commit('setPDFs',response);
let response = await ApiService.apiAxios.get(ApiRoutes.PDFS + '/' + organizationId);
commit('setPDFs',response?.data);
return response;
} catch(e) {
console.log(`Failed to get pdfs with error - ${e}`);
Expand Down

0 comments on commit cbaa0ac

Please sign in to comment.