130 lines
4.0 KiB
JavaScript
130 lines
4.0 KiB
JavaScript
/**
|
|
* @swagger
|
|
* /api/endpoint/createcase_api:
|
|
* post:
|
|
* tags: [Case]
|
|
* description: Create case
|
|
* summary: Phase 2
|
|
* parameters:
|
|
* - name: body
|
|
* in: requestbody
|
|
* required: true
|
|
* example: {}
|
|
* schema:
|
|
* type: object
|
|
* - name: contactid
|
|
* in: query
|
|
* required: true
|
|
* example: pinswg_planningappeals78s
|
|
* schema:
|
|
* type: string
|
|
* - name: appealTypeId
|
|
* in: query
|
|
* required: true
|
|
* example: pinswg_planningappeals78id
|
|
* schema:
|
|
* type: string
|
|
* - name: containername
|
|
* in: query
|
|
* required: true
|
|
* example: pinswg_planningappeals78id
|
|
* schema:
|
|
* type: string
|
|
* - name: lpaID
|
|
* in: query
|
|
* required: true
|
|
* example: pinswg_planningappeals78id
|
|
* schema:
|
|
* type: string
|
|
* responses:
|
|
* 200:
|
|
* description: Success
|
|
*/
|
|
|
|
import axios from "axios";
|
|
import CryptoJS from "crypto-js";
|
|
import _ from "lodash";
|
|
import { getToken } from "../../../actions/core/token";
|
|
import { getCaseBlob } from "../../../actions/azurestorage";
|
|
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 createTaskBody = req.body;
|
|
var queryUrl = "tasks";
|
|
var token = await getToken();
|
|
|
|
let contactValue = createTaskBody.typeOfContact;
|
|
|
|
const teamMap = {
|
|
plq: "ec48450c-7e26-ec11-a97f-00224800e98c", //PET
|
|
ipq: "7fb9e598-7d26-ec11-a97f-00224800e98c", // Infrastructure
|
|
pcpq: "8ffabad9-7c26-ec11-a97f-00224800e98c", // Casework
|
|
pi: "5554882f-4606-ec11-a97f-00224800d374", // Digital Support Team
|
|
appadvice: "cc3d987e-7c26-ec11-a97f-00224800e98c",
|
|
repadvice: "cc3d987e-7c26-ec11-a97f-00224800e98c",
|
|
ceq: "4fddd7e8-7d26-ec11-a97f-00224800e98c", // Inspector Scheduling
|
|
other: "8ffabad9-7c26-ec11-a97f-00224800e98c", // Casework
|
|
postdec: "1357e457-7e26-ec11-a97f-00224800e98c", // SLT Team
|
|
comp: "1357e457-7e26-ec11-a97f-00224800e98c" // SLT Team
|
|
};
|
|
|
|
let teamId = teamMap[contactValue];
|
|
|
|
const payload = {
|
|
"subject": `Contact Us Enquiry - ${createTaskBody.contactSubject}`,
|
|
"description": `From: ${createTaskBody.contactEmail}\n\n${createTaskBody.contactbody}`,
|
|
"scheduledstart": new Date().toISOString(),
|
|
"scheduledend": new Date(
|
|
new Date().getTime() + 60 * 60000 * 24
|
|
).toISOString(), // 30 mins
|
|
...(teamId && { "ownerid@odata.bind": `/teams(${teamId})` })
|
|
};
|
|
|
|
//console.log("/////Create Task:\n", payload, "\n//////////////");
|
|
|
|
var config = {
|
|
method: "post",
|
|
url: WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
|
headers: {
|
|
"OData-MaxVersion": "4.0",
|
|
"OData-Version": "4.0",
|
|
"Accept": "application/json",
|
|
"Prefer": 'odata.include-annotations="*",return=representation',
|
|
"Authorization": "Bearer " + token.access_token,
|
|
"Content-Type": "application/json"
|
|
},
|
|
data: JSON.stringify(payload)
|
|
};
|
|
|
|
//console.log("/////Create Task config:\n", config, "\n//////////////");
|
|
|
|
try {
|
|
const { data } = await axios(config);
|
|
return res.status(200).json(data);
|
|
} catch (error) {
|
|
console.error(
|
|
"CRM Task Creation Error:",
|
|
error.response?.data || error
|
|
);
|
|
return res
|
|
.status(400)
|
|
.json({ error: "Failed to create CRM task", details: error });
|
|
}
|
|
}
|