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 #585 from bcgov/ccfri-3756-afs-update
CCFRI-3756 - finishing AFS pages
- Loading branch information
Showing
21 changed files
with
1,045 additions
and
162 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
'use strict'; | ||
const { MappableObjectForFront, MappableObjectForBack } = require('../util/mapping/MappableObject'); | ||
const { ApplicationDocumentsMappings, DocumentsMappings } = require('../util/mapping/Mappings'); | ||
const { postApplicationDocument, getApplicationDocument, deleteDocument, patchOperationWithObjectId } = require('./utils'); | ||
const HttpStatus = require('http-status-codes'); | ||
const log = require('./logger'); | ||
|
||
const { getFileExtension, convertHeicDocumentToJpg } = require('../util/uploadFileUtils'); | ||
|
||
async function createApplicationDocuments(req, res) { | ||
try { | ||
const documents = req.body; | ||
for (let document of documents) { | ||
let payload = new MappableObjectForBack(document, ApplicationDocumentsMappings).toJSON(); | ||
payload.ccof_applicationid = document.ccof_applicationid; | ||
payload.ccof_facility = document.ccof_facility; | ||
if (getFileExtension(payload.filename) === 'heic') { | ||
log.verbose(`createApplicationDocuments :: heic detected for file name ${payload?.filename} starting conversion`); | ||
payload = await convertHeicDocumentToJpg(payload); | ||
} | ||
await postApplicationDocument(payload); | ||
} | ||
return res.sendStatus(HttpStatus.OK); | ||
} catch (e) { | ||
log.error(e); | ||
return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(e.data ? e.data : e?.status); | ||
} | ||
} | ||
|
||
async function getApplicationDocuments(req, res) { | ||
try { | ||
const documents = []; | ||
const response = await getApplicationDocument(req.params.applicationId); | ||
response?.value?.forEach((document) => documents.push(new MappableObjectForFront(document, ApplicationDocumentsMappings).toJSON())); | ||
return res.status(HttpStatus.OK).json(documents); | ||
} catch (e) { | ||
log.error(e); | ||
return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(e.data ? e.data : e?.status); | ||
} | ||
} | ||
|
||
async function updateDocument(req, res) { | ||
try { | ||
const payload = new MappableObjectForBack(req.body, DocumentsMappings).toJSON(); | ||
const response = await patchOperationWithObjectId('annotations', req.params.annotationId, payload); | ||
return res.status(HttpStatus.OK).json(response); | ||
} catch (e) { | ||
log.error(e); | ||
return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(e.data ? e.data : e?.status); | ||
} | ||
} | ||
|
||
async function deleteDocuments(req, res) { | ||
try { | ||
const deletedDocuments = req.body; | ||
await Promise.all( | ||
deletedDocuments.map(async (annotationId) => { | ||
await deleteDocument(annotationId); | ||
}), | ||
); | ||
return res.sendStatus(HttpStatus.OK); | ||
} catch (e) { | ||
log.error(e); | ||
return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(e.data ? e.data : e?.status); | ||
} | ||
} | ||
|
||
module.exports = { | ||
createApplicationDocuments, | ||
getApplicationDocuments, | ||
updateDocument, | ||
deleteDocuments, | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const express = require('express'); | ||
const passport = require('passport'); | ||
const router = express.Router(); | ||
const auth = require('../components/auth'); | ||
const { param, validationResult } = require('express-validator'); | ||
const isValidBackendToken = auth.isValidBackendToken(); | ||
const { createApplicationDocuments, getApplicationDocuments, deleteDocuments, updateDocument } = require('../components/document'); | ||
|
||
module.exports = router; | ||
|
||
router.post('/application/', passport.authenticate('jwt', { session: false }), isValidBackendToken, createApplicationDocuments); | ||
|
||
router.get( | ||
'/application/:applicationId', | ||
passport.authenticate('jwt', { session: false }), | ||
isValidBackendToken, | ||
[param('applicationId', 'URL param: [applicationId] is required').notEmpty().isUUID()], | ||
(req, res) => { | ||
validationResult(req).throw(); | ||
return getApplicationDocuments(req, res); | ||
}, | ||
); | ||
|
||
router.delete('/', passport.authenticate('jwt', { session: false }), isValidBackendToken, deleteDocuments); | ||
|
||
router.patch( | ||
'/:annotationId', | ||
passport.authenticate('jwt', { session: false }), | ||
isValidBackendToken, | ||
[param('annotationId', 'URL param: [annotationId] is required').notEmpty().isUUID()], | ||
(req, res) => { | ||
validationResult(req).throw(); | ||
return updateDocument(req, res); | ||
}, | ||
); |
Oops, something went wrong.