generated from bcgov/vue-scaffold
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #591 from bcgov/ccfri-4027-document-upload-bugs
ccfri-4027 - fix document upload bugs and code refactor
- Loading branch information
Showing
18 changed files
with
436 additions
and
699 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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,20 +11,21 @@ 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); | ||
} | ||
let response = await postApplicationDocument(documentClone); | ||
//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, { | ||
'[email protected]': `/ccof_application_facility_documents(${response?.applicationFacilityDocumentId})` | ||
'[email protected]': `/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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.