202 lines
6.2 KiB
JavaScript
202 lines
6.2 KiB
JavaScript
/**
|
|
* @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,
|
|
getTempCaseBlob,
|
|
} 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 { getPickLists } from "../../../actions";
|
|
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;
|
|
var appealType = req.query.appealType;
|
|
|
|
let appealBodyObj = req.body; //JSON.parse(req.body);
|
|
var containerID = appealBodyObj.containerID;
|
|
var casefolderID = appealBodyObj.casefolderID;
|
|
var caseRef = appealBodyObj.caseRef;
|
|
var filesList = appealBodyObj.filesList;
|
|
var checkquerypath = "/api/file/generateappealpdf";
|
|
|
|
// 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 planningappeals78_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 tempCaseBlob = await getTempCaseBlob(containerID, casefolderID);
|
|
const blobProgress = await getProgressBlobs(containerID, casefolderID).then(
|
|
(data) => {
|
|
//console.log("Progress blob path:", data);
|
|
return downloadProgressFile(containerID, data.path, casefolderID);
|
|
}
|
|
);
|
|
|
|
let newFileListArr = blobProgress.filesList.concat(
|
|
appealBodyObj.filesList[0]
|
|
);
|
|
|
|
Object.assign(blobProgress, {
|
|
"filesList": newFileListArr,
|
|
"caseObj": tempCaseBlob,
|
|
});
|
|
|
|
const pickListData = await getPickLists(appealType);
|
|
|
|
ReactPDF.render(
|
|
<MyDocument docProps={blobProgress} pickListData={pickListData} />,
|
|
process.cwd() + `/tmp/${blobProgress.pinswg_name}.pdf`
|
|
);
|
|
|
|
console.log(
|
|
"///////////////////////////////////\nfile created: " +
|
|
process.cwd() +
|
|
`/tmp/${blobProgress.pinswg_name}.pdf` +
|
|
"\n folder:" +
|
|
process.cwd() +
|
|
"\n/////////////////////////"
|
|
);
|
|
|
|
uploadPDFAppealFiles(
|
|
process.cwd() + `/tmp/${appealBodyObj.pinswg_name}.pdf`,
|
|
containerID,
|
|
appealBodyObj.pinswg_name
|
|
);
|
|
|
|
// then remove from local folder
|
|
|
|
//fs.unlinkSync(process.cwd() + `/tmp/${appealBodyObj.repfile_name}.pdf`);
|
|
|
|
return res.status(200).json({
|
|
data: "success",
|
|
path: process.cwd() + `/tmp/${blobProgress.pinswg_name}.pdf`,
|
|
});
|
|
// } else {
|
|
// return res.status(400).json();
|
|
// }
|
|
}
|