/** * @swagger * /api/file/generatepdf: * 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, uploadPDFRepFiles, } 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 { lpaQuestionnaire_pdf } from "../../../components/pdftemplates/lpaQuestionnaire_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 function handler(req, res) { var checkHash = req.query.hash; let reqBodyobj = JSON.parse(req.body); console.log( "//////////////////////\nreqBodyobj" + req + "\n//////////////////////\n" ); console.log( "//////////////////////\nreqBodyobj" + req.body + "\n//////////////////////\n" ); var containerID = reqBodyobj.containerID; var casefolderID = reqBodyobj.casefolderID; var caseRef = reqBodyobj.caseRef; var representationType = reqBodyobj.representationType; var repRaiser = reqBodyobj.lastname; var localeSelect = reqBodyobj.locale; //console.log("there are files:", Object.keys(req.files).length); var checkquerypath = "/api/file/generatepdf"; //console.log("-------", checkHash); // console.log(hashAPIPath(checkquerypath) == "?hash=" + checkHash); //console.log(casefolderID, caseRef); // Create Document Component const MyDocument = (values) => { console.log(values.docProps.locale); switch (values.docProps.representationType) { case "Questionnaire": return lpaQuestionnaire_pdf(values, values.docProps.locale); break; case "Final comments": return finalComments_pdf(values, values.docProps.locale); break; case "Statement": return statement_pdf(values, values.docProps.locale); break; case "Written statement": return writtenStatement_pdf(values, values.docProps.locale); break; case "Other": return other_pdf(values, values.docProps.locale); break; default: return other_pdf(values, values.docProps.locale); } }; let repCapacity = ""; switch (reqBodyobj.representationCapacity) { case "Appellant": repCapacity = "APPELLANT"; break; case "Agent": repCapacity = "AGENT"; break; case "Interested Party/Person": repCapacity = "IP"; break; case "Land Owner": repCapacity = "LO"; break; case "lpa": repCapacity = "LPA"; break; default: // code block } let repType = ""; switch (reqBodyobj.representationType) { case "Statement": repType = "STATE"; break; case "Statement of common ground": repType = "SCG"; break; case "Written statement": repType = "WS"; break; case "Written statement of evidence": repType = "WSE"; break; case "Questionnaire": repType = "QUEST"; break; case "Final comments": repType = "FC"; break; case "Other": repType = "OTHER"; break; default: // code block } console.log( "///////////////////////////////////\n file created: \n" + `tmp/${reqBodyobj.repfile_name}.pdf` + "\n/////////////////////////" ); ReactPDF.render( , `tmp/${reqBodyobj.repfile_name}.pdf` ); // upload file to storage account uploadPDFRepFiles( `tmp/${reqBodyobj.repfile_name}.pdf`, containerID, caseRef + "/" + reqBodyobj.repfile_name, repType ); // remove from local folder // fs.unlinkSync( `tmp/${reqBodyobj.repfile_name}.pdf`,); return res.status(200).json({ data: "success", path: `tmp/${reqBodyobj.repfile_name}.pdf`, }); // } else { // return res.status(400).json(); // } }