added garys api endpoint
This commit is contained in:
+92
-11
@@ -11,8 +11,19 @@ if (process.browser) {
|
|||||||
BASE_URL = window.apiRoot;
|
BASE_URL = window.apiRoot;
|
||||||
} else {
|
} else {
|
||||||
BASE_URL = process.env.API_ROOT || `http://localhost:${port}`;
|
BASE_URL = process.env.API_ROOT || `http://localhost:${port}`;
|
||||||
|
|
||||||
|
// BASE_URL =
|
||||||
|
"https://org042f59af.api.crm11.dynamics.com/api/data/v9.2/" ||
|
||||||
|
`http://localhost:${port}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let TOKEN_URL =
|
||||||
|
"https://login.microsoftonline.com/513f475e-ef51-4de1-9e85-a9fbe486f8cf/oauth2/v2.0/token/";
|
||||||
|
|
||||||
|
let WEBAPI_URL = "https://org042f59af.crm11.dynamics.com/api/data/v9.2/";
|
||||||
|
|
||||||
|
const cache = {};
|
||||||
|
|
||||||
const agent = new https.Agent({
|
const agent = new https.Agent({
|
||||||
rejectUnauthorized: false,
|
rejectUnauthorized: false,
|
||||||
});
|
});
|
||||||
@@ -32,6 +43,64 @@ const crmHeaders = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const tokenBody =
|
||||||
|
// "grant_type=" +
|
||||||
|
// process.env.GRANT_TYPE +
|
||||||
|
// "&scope=" +
|
||||||
|
// process.env.SCOPE +
|
||||||
|
// "&client_id=" +
|
||||||
|
// process.env.CLIENT_ID +
|
||||||
|
// "&client_secret=" +
|
||||||
|
// process.env.CLIENT_SECRET;
|
||||||
|
"client_id=86345cdb-d4fd-4a59-a5e4-1c718512c913&client_secret=AE7Hz2D8Pyx2M~Y6Z_-qoOUcnq67jR9o_3&scope=https%3A%2F%2Forg042f59af.crm11.dynamics.com%2F.default&grant_type=client_credentials";
|
||||||
|
|
||||||
|
const tokenConfig = {
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/x-www-form-urlencoded",
|
||||||
|
"Cache-Control": "no-cache",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const accessToken = (authToken) => {
|
||||||
|
console.log("access toekn", authToken);
|
||||||
|
return {
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/x-www-form-urlencoded",
|
||||||
|
"Cache-Control": "no-cache",
|
||||||
|
Authorization: "Bearer " + authToken,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const jsonAccessToken = (authToken) => {
|
||||||
|
return {
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: "Bearer " + authToken,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getToken = () => {
|
||||||
|
if (cache.tokenResponse) {
|
||||||
|
return cache.tokenResponse;
|
||||||
|
} else {
|
||||||
|
return (
|
||||||
|
axios
|
||||||
|
//.post(`${BASE_URL}/oauth/token`, tokenBody, tokenConfig)
|
||||||
|
.post(`${TOKEN_URL}/`, tokenBody, tokenConfig)
|
||||||
|
.then((res) => res.data)
|
||||||
|
.then((data) => {
|
||||||
|
cache.tokenResponse = data;
|
||||||
|
return data;
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.log("error :", error.response);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export const getBasicSearch = (searchString) => {
|
export const getBasicSearch = (searchString) => {
|
||||||
console.log("got to axios", searchString);
|
console.log("got to axios", searchString);
|
||||||
console.log("api_root: ", BASE_URL);
|
console.log("api_root: ", BASE_URL);
|
||||||
@@ -39,9 +108,15 @@ export const getBasicSearch = (searchString) => {
|
|||||||
axios
|
axios
|
||||||
//.get("https://devcrm2016.llcdt.gov.wales/DVPINS/api/data/v8.2/incidents?$select=_accountid_value,_customerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title&$filter=contains(title, '" + searchString + "')&$count=true", crmHeaders)
|
//.get("https://devcrm2016.llcdt.gov.wales/DVPINS/api/data/v8.2/incidents?$select=_accountid_value,_customerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title&$filter=contains(title, '" + searchString + "')&$count=true", crmHeaders)
|
||||||
//.get("https://jsonplaceholder.typicode.com/todos/1",{proxy:{protocol: 'http',host:'lon3.sme.zscloud.net',port: 80}})
|
//.get("https://jsonplaceholder.typicode.com/todos/1",{proxy:{protocol: 'http',host:'lon3.sme.zscloud.net',port: 80}})
|
||||||
.get(BASE_URL + "/api/searchresults2", {
|
//.get(BASE_URL + "/api/searchresults2", {
|
||||||
httpsAgent: new https.Agent({ rejectUnauthorized: false }),
|
.get(
|
||||||
})
|
WEBAPI_URL +
|
||||||
|
"incidents?$select=_accountid_value,_customerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title&$filter=contains(title, '" +
|
||||||
|
searchString +
|
||||||
|
"')&$count=true",
|
||||||
|
accessToken(cache.tokenResponse.access_token)
|
||||||
|
)
|
||||||
|
|
||||||
.then((res) => res.data)
|
.then((res) => res.data)
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log("thiserror", error);
|
console.log("thiserror", error);
|
||||||
@@ -304,16 +379,23 @@ export const createCase = (lpaType, appealType) => {
|
|||||||
// }
|
// }
|
||||||
// });
|
// });
|
||||||
|
|
||||||
export const getMyCases = () => {
|
export const getMyCases = (authToken) => {
|
||||||
return axios
|
return (
|
||||||
|
axios
|
||||||
.get(BASE_URL + "/api/lookups/myCases", {
|
//.get(BASE_URL + "/api/lookups/myCases", {
|
||||||
httpsAgent: new https.Agent({ rejectUnauthorized: false }),
|
.get(
|
||||||
})
|
WEBAPI_URL +
|
||||||
|
"incidents?$select=_accountid_value,_customerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title",
|
||||||
|
accessToken(cache.tokenResponse.access_token)
|
||||||
|
// {
|
||||||
|
// httpsAgent: new https.Agent({ rejectUnauthorized: false }),
|
||||||
|
// }
|
||||||
|
)
|
||||||
.then((res) => res.data)
|
.then((res) => res.data)
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log("thi serror", error);
|
console.log("thi serror", error);
|
||||||
});
|
})
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getMyRepresentations = () => {
|
export const getMyRepresentations = () => {
|
||||||
@@ -336,7 +418,6 @@ export const getWatchedCases = () => {
|
|||||||
})
|
})
|
||||||
.then((res) => res.data)
|
.then((res) => res.data)
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
w;
|
|
||||||
console.log("thi serror", error);
|
console.log("thi serror", error);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -32,12 +32,13 @@ const TopThree = (props) => {
|
|||||||
onClick={() => {
|
onClick={() => {
|
||||||
setCurrentReference({
|
setCurrentReference({
|
||||||
"currentReference":
|
"currentReference":
|
||||||
showTopThree.value[i].reference,
|
showTopThree.value[i]
|
||||||
|
.ticketnumber,
|
||||||
"currentType": topThreeType,
|
"currentType": topThreeType,
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{showTopThree.value[i].reference}
|
{showTopThree.value[i].ticketnumber}
|
||||||
</a>
|
</a>
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import { setMyRepresentations } from "../../store/myRepresentations/action";
|
|||||||
import { setWatchedCases } from "../../store/watchedCases/action";
|
import { setWatchedCases } from "../../store/watchedCases/action";
|
||||||
import { setAwaitingSubmission } from "../../store/awaitingSubmission/action";
|
import { setAwaitingSubmission } from "../../store/awaitingSubmission/action";
|
||||||
import {
|
import {
|
||||||
|
getToken,
|
||||||
getMyCases,
|
getMyCases,
|
||||||
getMyRepresentations,
|
getMyRepresentations,
|
||||||
getWatchedCases,
|
getWatchedCases,
|
||||||
@@ -75,6 +76,9 @@ export const getServerSideProps = wrapper.getServerSideProps(
|
|||||||
"public, s-maxage=604800, stale-while-revalidate"
|
"public, s-maxage=604800, stale-while-revalidate"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const token = await getToken();
|
||||||
|
console.log(token);
|
||||||
|
|
||||||
const [
|
const [
|
||||||
myCases,
|
myCases,
|
||||||
myRepresentations,
|
myRepresentations,
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import {
|
|||||||
setSearchResults,
|
setSearchResults,
|
||||||
getSearchResultsObj,
|
getSearchResultsObj,
|
||||||
} from "../store/searchOutput/action";
|
} from "../store/searchOutput/action";
|
||||||
import { getBasicSearch } from "../actions";
|
import { getToken, getBasicSearch } from "../actions";
|
||||||
|
|
||||||
const Home = (props) => {
|
const Home = (props) => {
|
||||||
const { footerLinks, pages } = props;
|
const { footerLinks, pages } = props;
|
||||||
@@ -56,6 +56,8 @@ const Home = (props) => {
|
|||||||
export const getServerSideProps = wrapper.getServerSideProps(
|
export const getServerSideProps = wrapper.getServerSideProps(
|
||||||
(store) =>
|
(store) =>
|
||||||
async ({ query, req, res }) => {
|
async ({ query, req, res }) => {
|
||||||
|
const token = await getToken();
|
||||||
|
console.log(token);
|
||||||
console.log("query-", query);
|
console.log("query-", query);
|
||||||
const searchResultsObj = (await getBasicSearch(query.q)) || null;
|
const searchResultsObj = (await getBasicSearch(query.q)) || null;
|
||||||
store.dispatch(setSearchResults(searchResultsObj));
|
store.dispatch(setSearchResults(searchResultsObj));
|
||||||
|
|||||||
Reference in New Issue
Block a user