TASK22102: slice7 complex file handler contract closeout
This commit is contained in:
@@ -104,6 +104,7 @@ import { finalComments_pdf } from "../../../components/pdftemplates/finalComment
|
||||
import { statement_pdf } from "../../../components/pdftemplates/statement_pdf";
|
||||
import { writtenStatement_pdf } from "../../../components/pdftemplates/writtenStatement_pdf";
|
||||
import { other_pdf } from "../../../components/pdftemplates/other_pdf";
|
||||
import { respondError, respondSuccess } from "../middleware/apiResponse";
|
||||
|
||||
//const ApiProxy = nextConnect();
|
||||
// ApiProxy.use(middleware);
|
||||
@@ -132,7 +133,12 @@ export default async function handler(req, res) {
|
||||
typeof casefolderID === "undefined" ||
|
||||
String(casefolderID).length === 0
|
||||
) {
|
||||
return res.status(400).json();
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
code: "MISSING_REQUIRED_QUERY",
|
||||
message:
|
||||
"hash, appealType, containerID and casefolderID are required"
|
||||
});
|
||||
}
|
||||
|
||||
checkquerypath =
|
||||
@@ -142,7 +148,11 @@ export default async function handler(req, res) {
|
||||
(isDownload ? "&download=true" : "");
|
||||
|
||||
if (hashAPIPath(checkquerypath) != "&hash=" + checkHash) {
|
||||
return res.status(400).json();
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
code: "INVALID_HASH",
|
||||
message: "Invalid hash"
|
||||
});
|
||||
}
|
||||
|
||||
// Create Document Component
|
||||
@@ -238,20 +248,28 @@ export default async function handler(req, res) {
|
||||
renderedPDFBuffer,
|
||||
containerID,
|
||||
blobProgress.pinswg_name || blobProgress.caseObj.ticketnumber
|
||||
).then((data) => {
|
||||
if (isDownload) {
|
||||
const filename = `${pdfFileName}.pdf`;
|
||||
res.setHeader("Content-Type", "application/pdf");
|
||||
res.setHeader(
|
||||
"Content-Disposition",
|
||||
`attachment; filename="${filename}"`
|
||||
);
|
||||
return res.status(200).send(renderedPDFBuffer);
|
||||
}
|
||||
return res.status(200).json({
|
||||
status: "success",
|
||||
data: data,
|
||||
path: `/files/${pdfFileName}.pdf`
|
||||
)
|
||||
.then((data) => {
|
||||
if (isDownload) {
|
||||
const filename = `${pdfFileName}.pdf`;
|
||||
res.setHeader("Content-Type", "application/pdf");
|
||||
res.setHeader(
|
||||
"Content-Disposition",
|
||||
`attachment; filename="${filename}"`
|
||||
);
|
||||
return res.status(200).send(renderedPDFBuffer);
|
||||
}
|
||||
return respondSuccess(res, {
|
||||
status: "success",
|
||||
data: data,
|
||||
path: `/files/${pdfFileName}.pdf`
|
||||
});
|
||||
})
|
||||
.catch(() => {
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
code: "GENERATE_APPEAL_PDF_FAILED",
|
||||
message: "Failed to generate appeal PDF"
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user