107 lines
3.1 KiB
JavaScript
107 lines
3.1 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";
|
|
import { hashAPIPath } from "../../../actions/core/hash";
|
|
|
|
const WEBAPI_URL =
|
|
process.env.RELAY_ROOT ||
|
|
"https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/";
|
|
|
|
export default async function ApiProxy(req, res) {
|
|
var createCaseBody = req.body;
|
|
var contactid = req.query.contactid;
|
|
var appealTypeId = req.query.appealTypeId;
|
|
var containerName = req.query.containername;
|
|
var lpaID = req.query.lpaID;
|
|
var queryUrl = "incidents";
|
|
var token = await getToken();
|
|
|
|
var data = {
|
|
"title": "insertion test case",
|
|
"caseorigincode": 3,
|
|
"servicestage": 1,
|
|
"customerid_contact@odata.bind": "/contacts(" + contactid + ")",
|
|
"pinswg_appealcasetype": appealTypeId,
|
|
"pinswg_AssociatedLPA@odata.bind": "/accounts(" + lpaID + ")"
|
|
};
|
|
var newData = Object.assign(data, createCaseBody);
|
|
|
|
delete newData.lpaTypes;
|
|
delete newData.appealTypes;
|
|
|
|
console.log("/////Create Case:\n", newData, "\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(newData)
|
|
};
|
|
var apiResponse = _.isEmpty(req.query)
|
|
? res.status(400).json()
|
|
: axios(config)
|
|
.then(({ data }) => {
|
|
getCaseBlob(containerName, data.ticketnumber, createCaseBody);
|
|
|
|
res.status(200).json(data);
|
|
})
|
|
.catch((error) => {
|
|
//consoleLogger(error);
|
|
res.status(400).json(error);
|
|
});
|
|
|
|
return apiResponse;
|
|
}
|