From 814a8c08b7537ec73ba39fd01a1ea60f8b1bdc1c Mon Sep 17 00:00:00 2001 From: Le Date: Wed, 4 Dec 2024 13:56:20 -0800 Subject: [PATCH 1/3] ccfri-4027 - fix document upload bugs and code refactor --- .../components/supportingDocumentUpload.js | 56 +-- backend/src/routes/supportingDocuments.js | 9 +- backend/src/util/mapping/Mappings.js | 6 +- .../src/components/RFI/RFIDocumentUpload.vue | 82 +--- frontend/src/components/RFI/RFILanding.vue | 18 +- .../src/components/SummaryDeclaration.vue | 6 +- .../components/SupportingDocumentUpload.vue | 358 ++++++++---------- .../ccofApplication/group/LicenseUpload.vue | 119 ++---- .../requestChanges/ChangeFileUpload.vue | 108 +----- .../group/UploadedDocumentsSummary.vue | 131 +++---- .../src/components/util/AppDocumentUpload.vue | 76 +--- frontend/src/store/application.js | 4 + frontend/src/store/summaryDeclaration.js | 23 -- .../src/store/supportingDocumentUpload.js | 8 - frontend/src/utils/common.js | 4 - frontend/src/utils/constants.js | 36 ++ frontend/src/utils/file.js | 45 ++- frontend/src/utils/rules.js | 25 ++ 18 files changed, 423 insertions(+), 691 deletions(-) diff --git a/backend/src/components/supportingDocumentUpload.js b/backend/src/components/supportingDocumentUpload.js index 1ea7b8f03..e441ca9a8 100644 --- a/backend/src/components/supportingDocumentUpload.js +++ b/backend/src/components/supportingDocumentUpload.js @@ -1,8 +1,8 @@ 'use strict'; -const {postApplicationDocument, getApplicationDocument, deleteDocument, patchOperationWithObjectId} = require('./utils'); +const { postApplicationDocument, getApplicationDocument, patchOperationWithObjectId } = require('./utils'); const HttpStatus = require('http-status-codes'); const log = require('./logger'); -const {getFileExtension, convertHeicDocumentToJpg} = require('../util/uploadFileUtils'); +const { getFileExtension, convertHeicDocumentToJpg } = require('../util/uploadFileUtils'); async function saveDocument(req, res) { try { @@ -11,7 +11,7 @@ async function saveDocument(req, res) { let documentClone = document; let changeRequestNewFacilityId = documentClone.changeRequestNewFacilityId; delete documentClone.changeRequestNewFacilityId; - if (getFileExtension(documentClone.filename) === 'heic' ) { + if (getFileExtension(documentClone.filename) === 'heic') { log.verbose(`saveDocument :: heic detected for file name ${documentClone.filename} starting conversion`); documentClone = await convertHeicDocumentToJpg(documentClone); } @@ -19,12 +19,13 @@ async function saveDocument(req, res) { //if this is a new facility change request, link supporting documents to the New Facility Change Action if (changeRequestNewFacilityId) { await patchOperationWithObjectId('ccof_change_request_new_facilities', changeRequestNewFacilityId, { - 'ccof_Attachments@odata.bind': `/ccof_application_facility_documents(${response?.applicationFacilityDocumentId})` + 'ccof_Attachments@odata.bind': `/ccof_application_facility_documents(${response?.applicationFacilityDocumentId})`, }); } } return res.sendStatus(HttpStatus.OK); } catch (e) { + log.error(e); return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(e.data ? e.data : e?.status); } } @@ -39,7 +40,6 @@ function mapDocument(fileInfo) { document.ccof_application_facility_documentId = fileInfo['ApplicationFacilityDocument.ccof_application_facility_documentid']; document.description = fileInfo.notetext; return document; - } async function getUploadedDocuments(req, res) { @@ -49,61 +49,23 @@ async function getUploadedDocuments(req, res) { let documentFiles = []; if (response?.value?.length > 0) { for (let fileInfo of response?.value) { - if(getAllFiles){ + if (getAllFiles) { documentFiles.push(mapDocument(fileInfo)); - } - else{ - if(fileInfo.subject !== 'Facility License') { + } else { + if (fileInfo.subject !== 'Facility License') { documentFiles.push(mapDocument(fileInfo)); } } - } } return res.status(HttpStatus.OK).json(documentFiles); } catch (e) { + log.error(e); return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(e.data ? e.data : e?.status); } } -async function getAllUploadedDocuments(req, res) { - try { - let response = await getApplicationDocument(req.params.applicationId); - let documentFiles = []; - if (response?.value?.length > 0) { - for (let fileInfo of response?.value) { - const document = {}; - document.filename = fileInfo.filename; - document.annotationid = fileInfo.annotationid; - document.documentType = fileInfo.subject; - document.ccof_facility = fileInfo['ApplicationFacilityDocument.ccof_facility']; - document.ccof_facility_name = fileInfo['ApplicationFacilityDocument.ccof_facility@OData.Community.Display.V1.FormattedValue']; - document.ccof_application_facility_documentId = fileInfo['ApplicationFacilityDocument.ccof_application_facility_documentid']; - document.description=fileInfo.notetext; - documentFiles.push(document); - } - } - return res.status(HttpStatus.OK).json(documentFiles); - } catch (e) { - return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(e.data ? e.data : e?.status); - } -} - -async function deleteUploadedDocuments(req, res) { - try { - let deletedDocuments = req.body; - for (let annotationid of deletedDocuments) { - await deleteDocument(annotationid); - } - return res.sendStatus(HttpStatus.OK); - } catch (e) { - return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(e.data ? e.data : e?.status); - } - -} - module.exports = { saveDocument, getUploadedDocuments, - deleteUploadedDocuments }; diff --git a/backend/src/routes/supportingDocuments.js b/backend/src/routes/supportingDocuments.js index 0f2abdc28..d4c4b7872 100644 --- a/backend/src/routes/supportingDocuments.js +++ b/backend/src/routes/supportingDocuments.js @@ -3,13 +3,10 @@ const passport = require('passport'); const router = express.Router(); const auth = require('../components/auth'); const isValidBackendToken = auth.isValidBackendToken(); -const {saveDocument, getUploadedDocuments, deleteUploadedDocuments} = require('../components/supportingDocumentUpload'); +const { saveDocument, getUploadedDocuments } = require('../components/supportingDocumentUpload'); module.exports = router; -router.post('', passport.authenticate('jwt', {session: false}), isValidBackendToken, saveDocument); - -router.get('/:applicationId', passport.authenticate('jwt', {session: false}), isValidBackendToken, getUploadedDocuments); - -router.delete('', passport.authenticate('jwt', {session: false}), isValidBackendToken, deleteUploadedDocuments); +router.post('', passport.authenticate('jwt', { session: false }), isValidBackendToken, saveDocument); +router.get('/:applicationId', passport.authenticate('jwt', { session: false }), isValidBackendToken, getUploadedDocuments); diff --git a/backend/src/util/mapping/Mappings.js b/backend/src/util/mapping/Mappings.js index a73b4f144..25e7a41fe 100644 --- a/backend/src/util/mapping/Mappings.js +++ b/backend/src/util/mapping/Mappings.js @@ -485,7 +485,11 @@ const DocumentsMappings = [ { back: 'subject', front: 'documentType' }, ]; -const ApplicationDocumentsMappings = [...DocumentsMappings, { back: 'ApplicationFacilityDocument.ccof_facility', front: 'facilityId' }]; +const ApplicationDocumentsMappings = [ + ...DocumentsMappings, + { back: 'ApplicationFacilityDocument.ccof_facility', front: 'facilityId' }, + { back: 'ApplicationFacilityDocument.ccof_facility@OData.Community.Display.V1.FormattedValue', front: 'facilityName' }, +]; module.exports = { ApplicationDocumentsMappings, diff --git a/frontend/src/components/RFI/RFIDocumentUpload.vue b/frontend/src/components/RFI/RFIDocumentUpload.vue index 37a593138..d661ec5e7 100644 --- a/frontend/src/components/RFI/RFIDocumentUpload.vue +++ b/frontend/src/components/RFI/RFIDocumentUpload.vue @@ -9,8 +9,7 @@ Upload supporting documents (for example, receipts, quotes, invoices, and/or budget/finance documents) - The maximum file size is 2MB for each document. Accepted file types are jpg, jpeg, heic, png, pdf, docx, doc, - xls, and xlsx. + {{ FILE_REQUIREMENTS_TEXT }}
@@ -27,12 +26,16 @@ > @@ -178,8 +147,12 @@ export default { background-color: #f2f2f2; } ->>> ::placeholder { - color: #ff5252 !important; - opacity: 1; +:deep(::placeholder) { + color: red !important; + opacity: 1 !important; +} + +:deep(.v-field__input) { + padding-left: 0px; } diff --git a/frontend/src/components/util/AppDocumentUpload.vue b/frontend/src/components/util/AppDocumentUpload.vue index 5d6aac875..30526ee09 100644 --- a/frontend/src/components/util/AppDocumentUpload.vue +++ b/frontend/src/components/util/AppDocumentUpload.vue @@ -6,8 +6,7 @@ (Required)
- The maximum file size is 2MB for each document. Accepted file types are jpg, jpeg, heic, png, pdf, docx, doc, - xls, and xlsx. + {{ FILE_REQUIREMENTS_TEXT }}
@@ -28,8 +27,8 @@ v-model="item.file" label="Select a file" prepend-icon="mdi-file-upload" - :rules="[...fileRules]" - :accept="fileExtensionAccept" + :rules="rules.fileRules" + :accept="FILE_TYPES_ACCEPT" :disabled="loading" @update:model-value="validateFile(item.id)" /> @@ -73,11 +72,13 @@