link on portal for pdf download
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import axios from "axios";
|
||||
import CryptoJS from "crypto-js";
|
||||
import _ from "lodash";
|
||||
import { getToken, azureHeaders, consoleLogger } from "../../../actions";
|
||||
|
||||
const WORDKEY = process.env.HASHKEY;
|
||||
|
||||
const WEBAPI_URL =
|
||||
process.env.RELAY_ROOT ||
|
||||
"https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/";
|
||||
|
||||
const hashAPIPath = (queryPath) => {
|
||||
var hashlink = CryptoJS.HmacSHA256(
|
||||
queryPath,
|
||||
CryptoJS.enc.Hex.parse(WORDKEY)
|
||||
);
|
||||
hashlink = hashlink.toString(CryptoJS.enc.Hex);
|
||||
|
||||
//return "&hash=" + hashlink;
|
||||
|
||||
return (queryPath.indexOf("?") > -1 ? "&hash=" : "?hash=") + hashlink;
|
||||
};
|
||||
|
||||
function flattenWatchlistEntry(entry) {
|
||||
const flattened = { ...entry };
|
||||
|
||||
if (entry.pinswg_Contact) {
|
||||
flattened.contactid = entry.pinswg_Contact.contactid;
|
||||
flattened.contact_email = entry.pinswg_Contact.emailaddress1;
|
||||
delete flattened.pinswg_Contact; // Optional: remove nested object
|
||||
}
|
||||
|
||||
return flattened;
|
||||
}
|
||||
|
||||
export default async function ApiProxy(req, res) {
|
||||
const incidentID = req.query.incidentid;
|
||||
var token = await getToken();
|
||||
|
||||
var queryUrl =
|
||||
"pinswg_watchlists?$count=true&$filter=pinswg_emailnotifications ne null&$expand=pinswg_Contact($select=contactid,emailaddress1)&$select=pinswg_emailnotifications,_pinswg_watchedcase_value";
|
||||
|
||||
return axios
|
||||
.get(
|
||||
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
||||
azureHeaders(token.access_token)
|
||||
)
|
||||
.then(({ data }) => {
|
||||
var dataStr;
|
||||
|
||||
const flattenedResults = data.value.map(flattenWatchlistEntry);
|
||||
|
||||
res.status(200).json(flattenedResults);
|
||||
})
|
||||
.catch((error) => {
|
||||
consoleLogger(error);
|
||||
res.status(400).json(error);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/**
|
||||
* @swagger
|
||||
* /api/endpoint/getsearchdocumentTypes_api:
|
||||
* get:
|
||||
* tags: [Search,]
|
||||
* description: Returns types of documents for a case
|
||||
* parameters:
|
||||
* - name: incidentid
|
||||
* in: query
|
||||
* required: true
|
||||
* example: 50b533aa-43f1-ec11-aade-00224800be9c
|
||||
* schema:
|
||||
* type: string
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Success
|
||||
*/
|
||||
|
||||
import axios from "axios";
|
||||
import CryptoJS from "crypto-js";
|
||||
import { azureHeaders, consoleLogger, getToken } from "../../../actions";
|
||||
|
||||
const WORDKEY = process.env.HASHKEY;
|
||||
|
||||
const WEBAPI_URL =
|
||||
process.env.RELAY_ROOT ||
|
||||
"https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/";
|
||||
|
||||
const hashAPIPath = (queryPath) => {
|
||||
var hashlink = CryptoJS.HmacSHA256(
|
||||
queryPath,
|
||||
CryptoJS.enc.Hex.parse(WORDKEY)
|
||||
);
|
||||
hashlink = hashlink.toString(CryptoJS.enc.Hex);
|
||||
|
||||
//return "&hash=" + hashlink;
|
||||
|
||||
return (queryPath.indexOf("?") > -1 ? "&hash=" : "?hash=") + hashlink;
|
||||
};
|
||||
|
||||
const groupArray = (arr) => {
|
||||
const map = new Map();
|
||||
|
||||
// Count occurrences of each object
|
||||
arr.forEach((obj) => {
|
||||
const key = JSON.stringify(obj);
|
||||
map.set(key, (map.get(key) || 0) + 1);
|
||||
});
|
||||
|
||||
// Create a new array to store unique objects with count
|
||||
const result = [];
|
||||
map.forEach((count, key) => {
|
||||
const obj = JSON.parse(key);
|
||||
|
||||
const transformedObj = {
|
||||
pinswg_isharedocumentlocations: obj.pinswg_isharedocumentlocations, // Change 'id' to 'userId'
|
||||
pinswg_isharedocumentlocationsLabel:
|
||||
obj[
|
||||
"pinswg_isharedocumentlocations@OData.Community.Display.V1.FormattedValue"
|
||||
], // Change 'name' to 'userName'
|
||||
count: count, // Add 'count' as 'occurrences'
|
||||
};
|
||||
|
||||
result.push(transformedObj);
|
||||
});
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
export default async function ApiProxy(req, res) {
|
||||
var incidentID = req.query.incidentid;
|
||||
var token = await getToken();
|
||||
|
||||
var queryUrl =
|
||||
"pinswg_documents?$count=true&$filter=_pinswg_documentids_value eq " +
|
||||
incidentID +
|
||||
" and not(contains(pinswg_name,'_Appeal_Form.pdf'))&$select=pinswg_name,pinswg_isharedocumentlocations";
|
||||
|
||||
console.log("docu: ", WEBAPI_URL + queryUrl + hashAPIPath(queryUrl));
|
||||
|
||||
return axios
|
||||
.get(
|
||||
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
||||
azureHeaders(token.access_token)
|
||||
)
|
||||
.then(({ data }) => {
|
||||
// //delete data["pinswg_documentid"];
|
||||
// data.value.forEach(function (element) {
|
||||
// delete element["pinswg_documentid"];
|
||||
// });
|
||||
|
||||
// var dataArr = groupArray(data.value);
|
||||
|
||||
// // var dataStr;
|
||||
// // _.has(data, "@odata.nextLink") == true &&
|
||||
// // ((dataStr = JSON.stringify(data["@odata.nextLink"])),
|
||||
// // (data["@odata.nextLink"] = dataStr.split("/v8.2/")[1]));
|
||||
|
||||
data.value.forEach((item) => {
|
||||
item.name = item.pinswg_name;
|
||||
});
|
||||
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((error) => {
|
||||
consoleLogger(error);
|
||||
res.status(400).json(error);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* @swagger
|
||||
* /api/endpoint/getcase_api:
|
||||
* get:
|
||||
* tags: [Case]
|
||||
* summary: Not used
|
||||
* description: Get case
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Success
|
||||
*/
|
||||
|
||||
import axios from "axios";
|
||||
import CryptoJS from "crypto-js";
|
||||
import _ from "lodash";
|
||||
import { getToken, azureHeaders, consoleLogger } from "../../../actions";
|
||||
|
||||
const WORDKEY = process.env.HASHKEY;
|
||||
|
||||
const WEBAPI_URL =
|
||||
process.env.RELAY_ROOT ||
|
||||
"https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/";
|
||||
|
||||
const hashAPIPath = (queryPath) => {
|
||||
var hashlink = CryptoJS.HmacSHA256(
|
||||
queryPath,
|
||||
CryptoJS.enc.Hex.parse(WORDKEY)
|
||||
);
|
||||
hashlink = hashlink.toString(CryptoJS.enc.Hex);
|
||||
|
||||
//return "&hash=" + hashlink;
|
||||
|
||||
return (queryPath.indexOf("?") > -1 ? "&hash=" : "?hash=") + hashlink;
|
||||
};
|
||||
|
||||
export default async function ApiProxy(req, res) {
|
||||
var incidentID = req.query.incidentID;
|
||||
var token = await getToken();
|
||||
var queryUrl = "incidents(" + incidentID + ")";
|
||||
|
||||
//console.log(WEBAPI_URL + queryUrl + hashAPIPath(queryUrl));
|
||||
|
||||
return axios
|
||||
.get(
|
||||
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
||||
azureHeaders(token.access_token)
|
||||
)
|
||||
.then(({ data }) => {
|
||||
var dataStr;
|
||||
_.has(data, "@odata.nextLink") == true &&
|
||||
((dataStr = JSON.stringify(data["@odata.nextLink"])),
|
||||
(data["@odata.nextLink"] = dataStr.split("/v8.2/")[1]));
|
||||
res.status(200).json([data]);
|
||||
})
|
||||
.catch((error) => {
|
||||
consoleLogger(error);
|
||||
res.status(400).json(error);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
import {
|
||||
createContainer,
|
||||
getContainers,
|
||||
getBlobs,
|
||||
createRepBlob,
|
||||
uploadFile,
|
||||
uploadPDFAppealFiles,
|
||||
downloadProgressFile,
|
||||
getProgressBlobs,
|
||||
getTempCaseBlob,
|
||||
createAppealPDFBlob,
|
||||
} from "../../../actions/azurestorage";
|
||||
import {
|
||||
hashAPIPath,
|
||||
getSearchDocumentDetails,
|
||||
getCaseByID,
|
||||
getPortalModuleDetails,
|
||||
getAppealPDFDocs,
|
||||
} from "../../../actions";
|
||||
import { getFormCollectionByID } from "../../../components/utils";
|
||||
import ReactPDF, {
|
||||
Document,
|
||||
Page,
|
||||
Text,
|
||||
View,
|
||||
StyleSheet,
|
||||
PDFViewer,
|
||||
pdf,
|
||||
} from "@react-pdf/renderer";
|
||||
|
||||
import middleware from "../middleware/middleware";
|
||||
import nextConnect from "next-connect";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
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 getDetails = (resultsObj, detailsType) => {
|
||||
if (!Array.isArray(resultsObj)) {
|
||||
console.warn("getDetails: resultsObj is not an array");
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
|
||||
const detailsPromises = resultsObj
|
||||
.filter((searchDetail) => searchDetail.pinswg_appealcasetype != null)
|
||||
.map((searchDetail) => {
|
||||
const caseID = searchDetail.ticketnumber;
|
||||
const appealType = searchDetail.pinswg_appealcasetype;
|
||||
|
||||
const form = getFormCollectionByID(appealType);
|
||||
if (!form) {
|
||||
console.warn("No form found for appeal type:", appealType);
|
||||
return null;
|
||||
}
|
||||
|
||||
return getPortalModuleDetails(form.LogicalCollectionName, caseID);
|
||||
})
|
||||
.filter(Boolean); // Remove any `null` if form not found
|
||||
|
||||
return Promise.all(detailsPromises);
|
||||
};
|
||||
|
||||
export default async function handler(req, res) {
|
||||
const incidentid = req.body?.docProps;
|
||||
if (!incidentid) return res.status(400).send("Missing incident ID");
|
||||
|
||||
const caseObj = await getCaseByID(incidentid);
|
||||
if (!Array.isArray(caseObj) || caseObj.length === 0)
|
||||
return res.status(404).send("Case not found");
|
||||
|
||||
const caseDetailsObj = await getDetails(caseObj, "myCases");
|
||||
const fileList = (await getAppealPDFDocs(incidentid)) || [];
|
||||
|
||||
// Inject into the first item in `value` array
|
||||
|
||||
if (caseDetailsObj[0]?.value?.[0]) {
|
||||
caseDetailsObj[0].value[0].pinswg_developmentdescription =
|
||||
caseObj[0].description;
|
||||
caseDetailsObj[0].value[0].caseObj = caseObj[0];
|
||||
caseDetailsObj[0].value[0].filesList = fileList;
|
||||
}
|
||||
|
||||
const whichForm = getFormCollectionByID(caseObj[0].pinswg_appealcasetype);
|
||||
const pickListData = await getPickLists(whichForm.UrlName);
|
||||
|
||||
const appealTypeMap = {
|
||||
846040000: planningappeals78_pdf,
|
||||
846040004: planningappeals78_pdf,
|
||||
};
|
||||
|
||||
//console.log(caseDetailsObj[0].value[0]);
|
||||
|
||||
const MyDocument = (values) => {
|
||||
const type = caseObj[0].pinswg_appealcasetype;
|
||||
const renderDocument = appealTypeMap[type] || other_pdf;
|
||||
return renderDocument(values);
|
||||
};
|
||||
|
||||
const pdfComponent = MyDocument({
|
||||
docProps: caseDetailsObj[0].value[0],
|
||||
pickListData,
|
||||
});
|
||||
|
||||
const pdfBuffer = await pdf(pdfComponent).toBuffer();
|
||||
|
||||
const repDate = new Date();
|
||||
const formattedDate = repDate.toISOString().split("T")[0];
|
||||
|
||||
res.setHeader("Content-Type", "application/pdf");
|
||||
res.setHeader(
|
||||
"Content-Disposition",
|
||||
`attachment; filename=${formattedDate}_-_Appeal_Form.pdf`
|
||||
);
|
||||
res.send(pdfBuffer);
|
||||
}
|
||||
Reference in New Issue
Block a user