TASK22224: modernize involvement and updatecase handlers
This commit is contained in:
@@ -11,7 +11,6 @@
|
||||
*/
|
||||
|
||||
import axios from "axios";
|
||||
import CryptoJS from "crypto-js";
|
||||
import { consoleLogger } from "../../../actions/core/logger";
|
||||
import { getToken } from "../../../actions/core/token";
|
||||
import { hashAPIPath } from "../../../actions/core/hash";
|
||||
@@ -36,20 +35,20 @@ export default async function ApiProxy(req, res) {
|
||||
});
|
||||
}
|
||||
|
||||
var token = await getToken();
|
||||
var contactid = req.body.contactid;
|
||||
var queryUrl =
|
||||
const token = await getToken();
|
||||
const contactid = req.body.contactid;
|
||||
const queryUrl =
|
||||
"incidents(" +
|
||||
req.body.incidentid +
|
||||
")/pinswg_incident_contact_case_involvement/$ref";
|
||||
|
||||
var crmUrl = "https://" + process.env.CRMURL;
|
||||
const crmUrl = "https://" + process.env.CRMURL;
|
||||
|
||||
var data = {
|
||||
const data = {
|
||||
"@odata.id": crmUrl + "/api/data/v8.2/contacts(" + contactid + ")"
|
||||
};
|
||||
|
||||
var config = {
|
||||
const config = {
|
||||
method: "post",
|
||||
url: WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
||||
headers: {
|
||||
@@ -64,18 +63,20 @@ export default async function ApiProxy(req, res) {
|
||||
data: data
|
||||
};
|
||||
|
||||
return axios(config)
|
||||
.then(({ data }) => {
|
||||
return respondSuccess(res, data);
|
||||
})
|
||||
.catch((error) => {
|
||||
return error.status == 412
|
||||
? respondSuccess(res, { "record": "exists" })
|
||||
: (consoleLogger(Object.assign(error, data)),
|
||||
respondError(res, {
|
||||
status: 400,
|
||||
code: "CREATE_CASE_INVOLVEMENT_FAILED",
|
||||
message: "Failed to create case involvement"
|
||||
}));
|
||||
try {
|
||||
const { data: responseData } = await axios(config);
|
||||
return respondSuccess(res, responseData);
|
||||
} catch (error) {
|
||||
const errorStatus = error?.status || error?.response?.status;
|
||||
if (errorStatus == 412) {
|
||||
return respondSuccess(res, { record: "exists" });
|
||||
}
|
||||
|
||||
consoleLogger(Object.assign(error, data));
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
code: "CREATE_CASE_INVOLVEMENT_FAILED",
|
||||
message: "Failed to create case involvement"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
*/
|
||||
|
||||
import axios from "axios";
|
||||
import CryptoJS from "crypto-js";
|
||||
import { consoleLogger } from "../../../actions/core/logger";
|
||||
import { getToken } from "../../../actions/core/token";
|
||||
import { hashAPIPath } from "../../../actions/core/hash";
|
||||
@@ -36,22 +35,22 @@ export default async function ApiProxy(req, res) {
|
||||
});
|
||||
}
|
||||
|
||||
var token = await getToken();
|
||||
var contactid = req.body.contactid;
|
||||
var queryUrl =
|
||||
const token = await getToken();
|
||||
const contactid = req.body.contactid;
|
||||
const queryUrl =
|
||||
"incidents(" +
|
||||
req.body.incidentid +
|
||||
")/pinswg_incident_contact_case_involvement/$ref";
|
||||
|
||||
var crmUrl = "https://" + process.env.CRMURL;
|
||||
var crmVersion = process.env.CRMURL_VERSION;
|
||||
const crmUrl = "https://" + process.env.CRMURL;
|
||||
const crmVersion = process.env.CRMURL_VERSION;
|
||||
|
||||
var data = {
|
||||
const data = {
|
||||
"@odata.id":
|
||||
crmUrl + "/api/data/" + crmVersion + "/contacts(" + contactid + ")"
|
||||
};
|
||||
|
||||
var config = {
|
||||
const config = {
|
||||
method: "post",
|
||||
url: WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
||||
headers: {
|
||||
@@ -66,18 +65,20 @@ export default async function ApiProxy(req, res) {
|
||||
data: data
|
||||
};
|
||||
|
||||
return axios(config)
|
||||
.then(({ data }) => {
|
||||
return respondSuccess(res, data);
|
||||
})
|
||||
.catch((error) => {
|
||||
return error.status == 412
|
||||
? respondSuccess(res, { "record": "exists" })
|
||||
: (consoleLogger(Object.assign(error, data)),
|
||||
respondError(res, {
|
||||
status: 400,
|
||||
code: "CREATE_REP_INVOLVEMENT_FAILED",
|
||||
message: "Failed to create representation involvement"
|
||||
}));
|
||||
try {
|
||||
const { data: responseData } = await axios(config);
|
||||
return respondSuccess(res, responseData);
|
||||
} catch (error) {
|
||||
const errorStatus = error?.status || error?.response?.status;
|
||||
if (errorStatus == 412) {
|
||||
return respondSuccess(res, { record: "exists" });
|
||||
}
|
||||
|
||||
consoleLogger(Object.assign(error, data));
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
code: "CREATE_REP_INVOLVEMENT_FAILED",
|
||||
message: "Failed to create representation involvement"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import axios from "axios";
|
||||
import CryptoJS from "crypto-js";
|
||||
import { consoleLogger } from "../../../actions/core/logger";
|
||||
import { getToken } from "../../../actions/core/token";
|
||||
import { hashAPIPath } from "../../../actions/core/hash";
|
||||
@@ -10,12 +9,12 @@ const WEBAPI_URL =
|
||||
"https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/";
|
||||
|
||||
export default async function ApiProxy(req, res) {
|
||||
var data = JSON.stringify(req.body);
|
||||
var appealObj = req.query.appealObj;
|
||||
var incidentID = req.query.incident;
|
||||
const data = JSON.stringify(req.body);
|
||||
const appealObj = req.query.appealObj;
|
||||
const incidentID = req.query.incident;
|
||||
|
||||
var updateFormCollection = req.query.updateFormCollection;
|
||||
var queryUrl = updateFormCollection + "(" + appealObj + ")";
|
||||
const updateFormCollection = req.query.updateFormCollection;
|
||||
const queryUrl = updateFormCollection + "(" + appealObj + ")";
|
||||
|
||||
if (
|
||||
typeof updateFormCollection === "undefined" ||
|
||||
@@ -35,9 +34,9 @@ export default async function ApiProxy(req, res) {
|
||||
});
|
||||
}
|
||||
|
||||
var token = await getToken();
|
||||
const token = await getToken();
|
||||
|
||||
var config = {
|
||||
const config = {
|
||||
method: "patch",
|
||||
url: WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
||||
headers: {
|
||||
@@ -53,16 +52,15 @@ export default async function ApiProxy(req, res) {
|
||||
|
||||
//console.log("update case:", data);
|
||||
|
||||
return axios(config)
|
||||
.then(({ data }) => {
|
||||
return respondSuccess(res, data);
|
||||
})
|
||||
.catch((error) => {
|
||||
consoleLogger(error);
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
code: "UPDATE_CASE_FAILED",
|
||||
message: "Failed to update case"
|
||||
});
|
||||
try {
|
||||
const { data: responseData } = await axios(config);
|
||||
return respondSuccess(res, responseData);
|
||||
} catch (error) {
|
||||
consoleLogger(error);
|
||||
return respondError(res, {
|
||||
status: 400,
|
||||
code: "UPDATE_CASE_FAILED",
|
||||
message: "Failed to update case"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user