create rep pdf tweaks prior to multi types matrix

This commit is contained in:
2023-10-11 13:51:35 +01:00
parent 1f669a5efe
commit f53faf47e2
10 changed files with 1824 additions and 799 deletions
+211
View File
@@ -0,0 +1,211 @@
/**
* @swagger
* /api/file/generateappealpdf:
* post:
* tags: [Azure Storage]
* summary: Phase 2
* description: Create reps pdf from text field
* consumes:
* - application/json
* requestBody:
* name: PDF
* description: PDF content body
* required: true
* content:
* 'application/json':
* schema:
* type: object
* properties:
* representationType:
* type: string
* example: "Questionnaire"
* representationQuestion1:
* type: string
* example: "question 111111"
* representationQuestion2:
* type: string
* example: "question 232222"
* representationCapacity:
* type: string
* example: "yes"
* representationDocuments:
* type: array
* example: [{}]
* pinswg_name:
* type: string
* example: "2023-8-24-1692882853853--REP_Bond"
* containerID:
* type: string
* example: "cljzkgyev0006f9tl4pk6u171"
* appealType:
* type: integer
* example: 846040000
* incidentID:
* type: string
* example: "50b533aa-43f1-ec11-aade-00224800be9c"
* caseRef:
* type: string
* example: "CAS-00764-L0Q9W2"
* parameters:
* - name: container
* in: query
* required: true
* example: cljzkgyev0006f9tl4pk6u171
* schema:
* type: string
* - name: casefolderID
* in: query
* required: true
* example: CAS-00764-L0Q9W2
* schema:
* type: string
* - name: hash
* in: query
* required: true
* example: 530b67db992ea277a236790be05b2e49bdd9dd02e6d790cc1c25f96cf39687cb
* schema:
* type: string
*
* responses:
* 200:
* description: Success
*/
import {
createContainer,
getContainers,
getBlobs,
createRepBlob,
uploadFile,
uploadPDFAppealFiles,
downloadProgressFile,
getProgressBlobs,
} from "../../../actions/azurestorage";
import { hashAPIPath } from "../../../actions";
import ReactPDF, {
Document,
Page,
Text,
View,
StyleSheet,
PDFViewer,
} from "@react-pdf/renderer";
import middleware from "../middleware/middleware";
import nextConnect from "next-connect";
import fs from "fs";
import { planningappeals78_pdf } from "../../../components/pdftemplates/planningappeals78_pdf";
import { finalComments_pdf } from "../../../components/pdftemplates/finalComments_pdf";
import { statement_pdf } from "../../../components/pdftemplates/statement_pdf";
import { writtenStatement_pdf } from "../../../components/pdftemplates/writtenStatement_pdf";
import { other_pdf } from "../../../components/pdftemplates/other_pdf";
// const ApiProxy = nextConnect();
// ApiProxy.use(middleware);
// ApiProxy.post(async (req, res) => {
export default async function handler(req, res) {
var checkHash = req.query.hash;
let appealBodyObj = req.body; //JSON.parse(req.body);
console.log(
"//////////////////////\nappealBodyObj" +
req +
"\n//////////////////////\n"
);
console.log(
"//////////////////////\nappealBodyObj" +
req.body +
"\n//////////////////////\n"
);
var containerID = req.query.containerID;
var casefolderID = req.query.casefolderID;
var caseRef = req.query.caseRef;
//console.log("there are files:", Object.keys(req.files).length);
var checkquerypath = "/api/file/generateappealpdf";
//console.log("-------", checkHash);
// console.log(hashAPIPath(checkquerypath) == "?hash=" + checkHash);
console.log(casefolderID, caseRef);
// Create Document Component
const MyDocument = (values) => {
switch (values.docProps.pinswg_appealcasetype) {
case "846040000":
return planningappeals78_pdf(values);
break;
case "846040025":
return listedbuildingandconservationareaconsen_pdf(values);
break;
case "846040004":
return householderappealhas_pdf(values);
break;
case "846040018":
return adverts_pdf(values);
break;
case "846040024":
return nonvalidation_pdf(values);
break;
case "846040005":
return enforcement_pdf(values);
break;
case "846040017":
return highhedgestpo_pdf(values);
break;
default:
return other_pdf(values);
}
};
const blobProgress = await getProgressBlobs(containerID, casefolderID).then(
(data) => {
console.log("Progress blob path:", data);
return downloadProgressFile(containerID, data.path, casefolderID);
}
);
console.log(blobProgress);
//if (hashAPIPath(checkquerypath) == "?hash=" + checkHash) {
// //createContainer(containerID).then((containerName) => {
// console.log("does this get folder name:", containerID, casefolderID);
console.log(
"///////////////////////////////////\n file created: \n" +
`tmp/${blobProgress.pinswg_name}.pdf` +
"\n/////////////////////////"
);
// createRepBlob(req.body, containerID, caseRef);
ReactPDF.render(
<MyDocument docProps={blobProgress} />,
`tmp/${blobProgress.pinswg_name}.pdf`
);
// uploadPDFAppealFiles(
// `tmp/${appealBodyObj.repfile_name}.pdf`,
// containerID,
// caseRef + "/" + appealBodyObj.pinswg_name
// );
// to do upload file to storage account
// then remove from local folder
// fs.unlinkSync( `tmp/${appealBodyObj.repfile_name}.pdf`,);
return res.status(200).json({
data: "success",
path: `tmp/${blobProgress.pinswg_name}.pdf`,
});
// } else {
// return res.status(400).json();
// }
}
+2 -25
View File
@@ -207,38 +207,18 @@ export default function handler(req, res) {
// code block
}
// const repDate = new Date();
// let day = ("0" + repDate.getDate()).slice(-2);
// let month = ("0" + (repDate.getMonth() + 1)).slice(-2);
// let year = repDate.getFullYear();
// let time =
// ("0" + repDate.getHours()).slice(-2) +
// "" +
// ("0" + repDate.getMinutes()).slice(-2);
// let repDateStamp = "";
// repDateStamp = year + "" + month + day; //+ "-" + time;
//console.log(reqBodyobj);
//if (hashAPIPath(checkquerypath) == "?hash=" + checkHash) {
// //createContainer(containerID).then((containerName) => {
// console.log("does this get folder name:", containerID, casefolderID);
console.log(
"///////////////////////////////////\n file created: \n" +
`tmp/${reqBodyobj.repfile_name}.pdf` +
"\n/////////////////////////"
);
// createRepBlob(req.body, containerID, caseRef);
ReactPDF.render(
<MyDocument docProps={reqBodyobj} />,
`tmp/${reqBodyobj.repfile_name}.pdf`
);
// upload file to storage account
uploadPDFRepFiles(
`tmp/${reqBodyobj.repfile_name}.pdf`,
containerID,
@@ -246,10 +226,7 @@ export default function handler(req, res) {
repType
);
// to do upload file to storage account
// then remove from local folder
// remove from local folder
// fs.unlinkSync( `tmp/${reqBodyobj.repfile_name}.pdf`,);
return res.status(200).json({