125 lines
3.9 KiB
JavaScript
125 lines
3.9 KiB
JavaScript
import { hashAPIPath, updateAccount } from "../../../actions";
|
|
import {
|
|
createCaseCompleteMessage,
|
|
getProgressBlobs,
|
|
downloadProgressFile,
|
|
createBlob,
|
|
getCaseBlob,
|
|
} from "../../../actions/azurestorage";
|
|
|
|
import nextConnect from "next-connect";
|
|
import middleware from "../middleware/middleware";
|
|
|
|
const ApiProxy = nextConnect();
|
|
ApiProxy.use(middleware);
|
|
|
|
ApiProxy.get(async (req, res) => {
|
|
var containerName = req.query.container;
|
|
var tempCaseRef = req.query.tempcaseref;
|
|
var typeofinvolvement = req.query.inv;
|
|
var checkHash = req.query.hash;
|
|
|
|
console.log("/////Create Case Message:\n", tempCaseRef, "\n//////////////");
|
|
|
|
//console.log(hashAPIPath(checkquerypath), checkHash);
|
|
//console.log(hashAPIPath(checkquerypath) == "&hash=" + checkHash);
|
|
var checkquerypath =
|
|
"/api/file/createappealcompletemessage_api?container=" +
|
|
containerName +
|
|
"&tempcaseref=" +
|
|
tempCaseRef;
|
|
|
|
const blobProgress = await getProgressBlobs(
|
|
containerName,
|
|
tempCaseRef
|
|
).then((data) => {
|
|
return downloadProgressFile(containerName, data.path, tempCaseRef);
|
|
});
|
|
|
|
const caseObj = await downloadProgressFile(
|
|
containerName,
|
|
tempCaseRef + "/" + tempCaseRef + "_case.json",
|
|
tempCaseRef
|
|
);
|
|
|
|
Object.assign(blobProgress, {
|
|
"appealComplete": tempCaseRef,
|
|
});
|
|
|
|
delete blobProgress["pinswg_name"];
|
|
|
|
//http: if (hashAPIPath(checkquerypath) == "&hash=" + checkHash) {
|
|
|
|
await createBlob(JSON.stringify(blobProgress), containerName, tempCaseRef)
|
|
.then(() => {
|
|
//update case.json with lpa ref and description
|
|
Object.assign(caseObj, {
|
|
"pinswg_lpareference":
|
|
blobProgress.pinswg_lpaapplicationreference,
|
|
"description": blobProgress.pinswg_developmentdescription,
|
|
});
|
|
|
|
//send update case.json and then create queue message
|
|
getCaseBlob(containerName, tempCaseRef, caseObj).then(() => {
|
|
let contactId = caseObj["customerid_contact@odata.bind"];
|
|
contactId = contactId.match(/\(([^)]+)\)/);
|
|
|
|
if (typeofinvolvement != 846040000) {
|
|
updateAccount(
|
|
contactId[1],
|
|
{
|
|
"pinswg_typeofinvolvement": 846040001,
|
|
},
|
|
true
|
|
).then((data) => {
|
|
console.log(
|
|
"uopdated account : " +
|
|
contactId +
|
|
" \nfrom: " +
|
|
data.pinswg_typeofinvolvement +
|
|
"\nto: " +
|
|
typeofinvolvement
|
|
);
|
|
});
|
|
}
|
|
|
|
createCaseCompleteMessage(containerName, tempCaseRef);
|
|
return res.status(200).json({
|
|
status: "success",
|
|
});
|
|
});
|
|
})
|
|
.catch((error) => {
|
|
console.log(
|
|
"///////////////////////\n createCaseCompleteMessage:",
|
|
error,
|
|
"///////////////////////\n"
|
|
);
|
|
return res.status(400).json(error);
|
|
});
|
|
|
|
// await createCaseCompleteMessage(containerName, tempCaseRef)
|
|
// .then((data) => {
|
|
// console.log(data);
|
|
// createBlob(
|
|
// JSON.stringify(blobProgress),
|
|
// containerName,
|
|
// tempCaseRef
|
|
// );
|
|
// return res.status(200).json(data);
|
|
// })
|
|
// .catch((error) => {
|
|
// console.log(error);
|
|
|
|
// return res.status(400).json(error);
|
|
// });
|
|
});
|
|
|
|
export const config = {
|
|
api: {
|
|
bodyParser: false,
|
|
},
|
|
};
|
|
|
|
export default ApiProxy;
|