TASK22224: big parity bundle for completion message routes
This commit is contained in:
@@ -18,10 +18,10 @@ 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;
|
||||
const containerName = req.query.container;
|
||||
const tempCaseRef = req.query.tempcaseref;
|
||||
const typeofinvolvement = req.query.inv;
|
||||
const checkHash = req.query.hash;
|
||||
|
||||
if (
|
||||
typeof containerName === "undefined" ||
|
||||
@@ -38,13 +38,22 @@ ApiProxy.get(async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
var checkquerypath =
|
||||
const hashCandidatePaths = [
|
||||
"/api/file/createappealcompletemessage_api?container=" +
|
||||
containerName +
|
||||
"&tempcaseref=" +
|
||||
tempCaseRef;
|
||||
containerName +
|
||||
"&tempcaseref=" +
|
||||
tempCaseRef,
|
||||
"/api/file/createappealcompletemessage_api?container=" +
|
||||
encodeURIComponent(containerName) +
|
||||
"&tempcaseref=" +
|
||||
encodeURIComponent(tempCaseRef)
|
||||
];
|
||||
|
||||
if (hashAPIPath(checkquerypath) != "&hash=" + checkHash) {
|
||||
const isHashValid = hashCandidatePaths.some(
|
||||
(candidatePath) => hashAPIPath(candidatePath) == "&hash=" + checkHash
|
||||
);
|
||||
|
||||
if (!isHashValid) {
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
code: "INVALID_HASH",
|
||||
@@ -52,83 +61,83 @@ ApiProxy.get(async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const blobProgress = await getProgressBlobs(
|
||||
containerName,
|
||||
tempCaseRef
|
||||
).then((data) => {
|
||||
return downloadProgressFile(containerName, data.path, tempCaseRef);
|
||||
});
|
||||
try {
|
||||
const progressBlob = await getProgressBlobs(containerName, tempCaseRef);
|
||||
const blobProgress = await downloadProgressFile(
|
||||
containerName,
|
||||
progressBlob.path,
|
||||
tempCaseRef
|
||||
);
|
||||
|
||||
const caseObj = await downloadProgressFile(
|
||||
containerName,
|
||||
tempCaseRef + "/" + tempCaseRef + "_case.json",
|
||||
tempCaseRef
|
||||
);
|
||||
const caseObj = await downloadProgressFile(
|
||||
containerName,
|
||||
tempCaseRef + "/" + tempCaseRef + "_case.json",
|
||||
tempCaseRef
|
||||
);
|
||||
|
||||
Object.assign(blobProgress, {
|
||||
"appealComplete": tempCaseRef
|
||||
});
|
||||
|
||||
delete blobProgress["pinswg_name"];
|
||||
|
||||
await createBlob(JSON.stringify(blobProgress), containerName, tempCaseRef)
|
||||
.then(() => {
|
||||
//update case.json with lpa ref and description
|
||||
|
||||
let combinedAddress =
|
||||
blobProgress.pinswg_siteaddressline1 +
|
||||
(!_.isEmpty(blobProgress.pinswg_siteaddressline2)
|
||||
? ", " + blobProgress.pinswg_siteaddressline2
|
||||
: "") +
|
||||
(!_.isEmpty(blobProgress.pinswg_siteaddresstown)
|
||||
? ", " + blobProgress.pinswg_siteaddresstown
|
||||
: "");
|
||||
|
||||
combinedAddress =
|
||||
combinedAddress +
|
||||
", " +
|
||||
blobProgress.pinswg_siteaddresscounty +
|
||||
", " +
|
||||
blobProgress.pinswg_siteaddresspostcode;
|
||||
|
||||
Object.assign(caseObj, {
|
||||
"pinswg_lpareference":
|
||||
blobProgress.pinswg_lpaapplicationreference,
|
||||
"description": blobProgress.pinswg_developmentdescription,
|
||||
"pinswg_caseaddress": combinedAddress
|
||||
});
|
||||
|
||||
//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
|
||||
).catch((error) => {
|
||||
consoleLogger(error);
|
||||
});
|
||||
}
|
||||
|
||||
createCaseCompleteMessage(containerName, tempCaseRef);
|
||||
return respondSuccess(res, {
|
||||
status: "success"
|
||||
});
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
consoleLogger(error);
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
code: "CREATE_APPEAL_COMPLETE_MESSAGE_FAILED",
|
||||
message: "Failed to create appeal complete message"
|
||||
});
|
||||
Object.assign(blobProgress, {
|
||||
appealComplete: tempCaseRef
|
||||
});
|
||||
|
||||
delete blobProgress.pinswg_name;
|
||||
|
||||
await createBlob(
|
||||
JSON.stringify(blobProgress),
|
||||
containerName,
|
||||
tempCaseRef
|
||||
);
|
||||
|
||||
let combinedAddress =
|
||||
blobProgress.pinswg_siteaddressline1 +
|
||||
(!_.isEmpty(blobProgress.pinswg_siteaddressline2)
|
||||
? ", " + blobProgress.pinswg_siteaddressline2
|
||||
: "") +
|
||||
(!_.isEmpty(blobProgress.pinswg_siteaddresstown)
|
||||
? ", " + blobProgress.pinswg_siteaddresstown
|
||||
: "");
|
||||
|
||||
combinedAddress =
|
||||
combinedAddress +
|
||||
", " +
|
||||
blobProgress.pinswg_siteaddresscounty +
|
||||
", " +
|
||||
blobProgress.pinswg_siteaddresspostcode;
|
||||
|
||||
Object.assign(caseObj, {
|
||||
pinswg_lpareference: blobProgress.pinswg_lpaapplicationreference,
|
||||
description: blobProgress.pinswg_developmentdescription,
|
||||
pinswg_caseaddress: combinedAddress
|
||||
});
|
||||
|
||||
await getCaseBlob(containerName, tempCaseRef, caseObj);
|
||||
|
||||
let contactId = caseObj["customerid_contact@odata.bind"];
|
||||
contactId = contactId.match(/\(([^)]+)\)/);
|
||||
|
||||
if (typeofinvolvement != 846040000) {
|
||||
updateAccount(
|
||||
contactId[1],
|
||||
{
|
||||
pinswg_typeofinvolvement: 846040001
|
||||
},
|
||||
true
|
||||
).catch((error) => {
|
||||
consoleLogger(error);
|
||||
});
|
||||
}
|
||||
|
||||
await createCaseCompleteMessage(containerName, tempCaseRef);
|
||||
return respondSuccess(res, {
|
||||
status: "success"
|
||||
});
|
||||
} catch (error) {
|
||||
consoleLogger(error);
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
code: "CREATE_APPEAL_COMPLETE_MESSAGE_FAILED",
|
||||
message: "Failed to create appeal complete message"
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
export const config = {
|
||||
|
||||
Reference in New Issue
Block a user