17025 email notiofications fixes
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
/**
|
||||
* @swagger
|
||||
* /api/endpoint/createmywatchedcases_api:
|
||||
* post:
|
||||
* tags: [Portal,Case]
|
||||
* summary: Phase 2
|
||||
* description: Create my watched cases
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Success
|
||||
*/
|
||||
// /**
|
||||
// * @swagger
|
||||
// * /api/endpoint/createmywatchedcases_api:
|
||||
// * post:
|
||||
// * tags: [Portal,Case]
|
||||
// * summary: Phase 2
|
||||
// * description: Create my watched cases
|
||||
// * responses:
|
||||
// * 200:
|
||||
// * description: Success
|
||||
// */
|
||||
|
||||
import axios from "axios";
|
||||
import CryptoJS from "crypto-js";
|
||||
@@ -32,31 +32,96 @@ const hashAPIPath = (queryPath) => {
|
||||
return (queryPath.indexOf("?") > -1 ? "&hash=" : "?hash=") + hashlink;
|
||||
};
|
||||
|
||||
export default async function ApiProxy(req, res) {
|
||||
var token = await getToken();
|
||||
var data = JSON.stringify(req.body);
|
||||
var queryUrl = "pinswg_watchlists";
|
||||
// export default async function ApiProxy(req, res) {
|
||||
// var token = await getToken();
|
||||
// var data = JSON.stringify(req.body);
|
||||
// var queryUrl = "pinswg_watchlists";
|
||||
|
||||
var config = {
|
||||
method: "post",
|
||||
// console.log(data);
|
||||
// var config = {
|
||||
// method: "put",
|
||||
// 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: data,
|
||||
// };
|
||||
|
||||
// return axios(config)
|
||||
// .then(({ data }) => {
|
||||
// res.status(200).json(data);
|
||||
// })
|
||||
// .catch((error) => {
|
||||
// consoleLogger(Object.assign(err, data));
|
||||
// res.status(400).json(error);
|
||||
// });
|
||||
// }
|
||||
const recordExists = async (incidentId, contactId, token) => {
|
||||
const filter = `$filter=pinswg_WatchedCase/incidentid eq ${incidentId} and pinswg_Contact/contactid eq ${contactId}`;
|
||||
const queryUrl = `pinswg_watchlists?${filter}`;
|
||||
const url = WEBAPI_URL + queryUrl + hashAPIPath(queryUrl);
|
||||
|
||||
try {
|
||||
const res = await axios.get(url, {
|
||||
headers: {
|
||||
Authorization: "Bearer " + token.access_token,
|
||||
Accept: "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
if (res.data.value && res.data.value.length > 0) {
|
||||
return res.data.value[0]; // return the existing record
|
||||
}
|
||||
|
||||
return null;
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
|
||||
export default async function ApiProxy(req, res) {
|
||||
const token = await getToken();
|
||||
const data = req.body;
|
||||
|
||||
const incidentId =
|
||||
data["pinswg_WatchedCase@odata.bind"].match(/\(([^)]+)\)/)[1];
|
||||
const contactId = data["pinswg_Contact@odata.bind"].match(/\(([^)]+)\)/)[1];
|
||||
|
||||
const existingRecord = await recordExists(incidentId, contactId, token);
|
||||
|
||||
let method, queryUrl;
|
||||
|
||||
if (existingRecord) {
|
||||
method = "patch";
|
||||
queryUrl = `pinswg_watchlists(${existingRecord.pinswg_watchlistid})`; // adjust with your primary key logical name
|
||||
} else {
|
||||
method = "post";
|
||||
queryUrl = "pinswg_watchlists";
|
||||
}
|
||||
|
||||
const config = {
|
||||
method: method,
|
||||
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,
|
||||
Accept: "application/json",
|
||||
Prefer: 'odata.include-annotations="*",return=representation',
|
||||
Authorization: "Bearer " + token.access_token,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
data: data,
|
||||
data: JSON.stringify(data),
|
||||
};
|
||||
|
||||
return axios(config)
|
||||
.then(({ data }) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((error) => {
|
||||
consoleLogger(Object.assign(err, data));
|
||||
res.status(400).json(error);
|
||||
.then(({ data }) => res.status(200).json(data))
|
||||
.catch((err) => {
|
||||
consoleLogger(err);
|
||||
res.status(400).json(err.response?.data || err);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user