diff --git a/actions/index.js b/actions/index.js index 60c8b26d..dfd370b0 100644 --- a/actions/index.js +++ b/actions/index.js @@ -314,7 +314,7 @@ export const getBasicDNSSearchDetails = (token, appealType, caseReference) => { }; export const getLinkedCases = (parentIncidentid) => { - console.log(parentIncidentid); + //console.log(parentIncidentid); var token = getSASToken(); return axios @@ -324,7 +324,7 @@ export const getLinkedCases = (parentIncidentid) => { " and pinswg_appealcasetype ne null and pinswg_publishtoweb eq true &$select=title, incidentid," ) .then((res) => { - console.log(" linked date", res.data); + //console.log(" linked date", res.data); return res.data; }) .catch((error) => { @@ -663,3 +663,18 @@ export const getPortalModuelDetails = (token, appealType, caseReference) => { console.log("thiserror", error); }); }; + +export const getFileFromCRM = (docRef) => { + const weburl = "/api/proxy/documents/download/" + docRef; + + console.log("proxy url", weburl); + return axios + .get(weburl, { responseType: "arraybuffer" }) + .then((res) => { + console.log(res); + return res; + }) + .catch((error) => { + console.log("thi serror", error); + }); +}; diff --git a/components/case/documents.js b/components/case/documents.js index 32a5fdab..593a6f12 100644 --- a/components/case/documents.js +++ b/components/case/documents.js @@ -95,7 +95,7 @@ const DocumentDetails = (props) => { detailsObj.pinswg_isharedocumentreference } > - + {t( "case:documents-name-label" @@ -212,6 +212,11 @@ const DocumentDetails = (props) => { }; const searchDocumentResultsObj = docDetailsObj(); + + const getFileFromCRM = (event, docRef) => { + console.log(e, docRef); + return alert(docRef); + }; }, [incidentid, setDocumentHistory, setDocumentDetails]); function formatDates(dateObj) { @@ -227,11 +232,13 @@ const DocumentDetails = (props) => {
-

Documents

+

{t("case:documents-heading-label")}

{_.isEmpty(documentHistoryObj) ? (
-

There are no documents for this appeal

+

+ {t("case:documents-non-available-label")} +

) : ( diff --git a/components/case/summary.js b/components/case/summary.js index 76b629b0..27de4e8e 100644 --- a/components/case/summary.js +++ b/components/case/summary.js @@ -607,7 +607,7 @@ const CaseSummary = (props) => { useEffect(() => { const linkCaseObj = async () => { let docObj = await getLinkedCases(incidentid).then((data) => { - console.log(data); + //console.log(data); setCurrentLinkedCases(data); return data; }); @@ -636,7 +636,7 @@ const CaseSummary = (props) => { } function linkedCasesList(linkedCasesReference) { - console.log(linkedCasesReference); + //console.log(linkedCasesReference); linkedCasesReference = linkedCasesReference.value || []; diff --git a/components/footer.js b/components/footer.js index 85b7dc7d..dd26c902 100644 --- a/components/footer.js +++ b/components/footer.js @@ -27,7 +27,7 @@ export default function Footer(props) { : setShowShareState(true); }; - console.log(router.asPath); + //console.log(router.asPath); const shareBodyStr = t("common:gov-wales-link") + router.asPath; const shareSubjectStr = t("common:social-shared-from") + diff --git a/locales/cy/case.json b/locales/cy/case.json index 876004ef..67ffb6b7 100644 --- a/locales/cy/case.json +++ b/locales/cy/case.json @@ -34,5 +34,7 @@ "documents-name-label": "Math y Ddogfen", "documents-doc-type-label": "Math y Ddogfen", "documents-date-published-label": "Dyddiad cyhoeddi", - "documents-size-label": "Maint y ffeil (kb)" + "documents-size-label": "Maint y ffeil (kb)", + "documents-non-available-label": "Nid oes unrhyw ddogfennau ar gyfer yr apĂȘl hon", + "documents-heading-label": "Dogfennau" } \ No newline at end of file diff --git a/locales/en/case.json b/locales/en/case.json index c86707c4..7f4129eb 100644 --- a/locales/en/case.json +++ b/locales/en/case.json @@ -34,5 +34,7 @@ "documents-name-label": "Name", "documents-doc-type-label": "Document type", "documents-date-published-label": "Date published", - "documents-size-label": "Size (KB)" + "documents-size-label": "Size (KB)", + "documents-non-available-label": "There are no documents for this appeal", + "documents-heading-label": "Documents" } \ No newline at end of file diff --git a/pages/api/proxy/[...route].js b/pages/api/proxy/[...route].js index 8fbad3f4..454592a9 100644 --- a/pages/api/proxy/[...route].js +++ b/pages/api/proxy/[...route].js @@ -1,6 +1,7 @@ import axios from "axios"; import https from "https"; import CryptoJS from "crypto-js"; +import { response } from "express"; const PROXY_RELAY_URL = "https://" + @@ -62,24 +63,9 @@ const getSASToken = () => { export default async function ApiProxy(req, res) { console.log(req.method); - var updateBody = { - "pinswg_areaofsiteinhectaresdec": 21, - "pinswg_developmentaffectsettingifalisted": false, - "pinswg_floorspaceinsquaremeters": "123123124", - "pinswg_incarelatestoca": false, - "pinswg_isfloodinganissue": true, - "pinswg_isthesitewithinanaonb": false, - "pinswg_landuse": "846040002", - "pinswg_sitewithinsssi": true, - "pinswg_sitewithinagreenbelt": false, - "pinswg_siteviewablefromroad": false, - "pinswg_typeofplanningapplication": "846040000", - }; var data = JSON.stringify(req.body); const SASToken = getSASToken(); - // console.log(SASToken); - var configNoData = { method: req.method, //url: PROXY_RELAY_URL + updateFormCollection + "(" + incidentId + ")", @@ -109,17 +95,44 @@ export default async function ApiProxy(req, res) { data: data, }; - console.log(req.url.split("/api/proxy/")[1]); + var configDocument = { + method: req.method, + url: PROXY_RELAY_URL + req.url.split("/api/proxy/")[1], + headers: { + "OData-MaxVersion": "4.0", + "OData-Version": "4.0", + "Accept": "application/json", + "Prefer": 'odata.include-annotations="*",return=representation', + "Authorization": SASToken, + "Content-Type": "application/json", + }, + responseType: "arraybuffer", + }; return new Promise((resolve, reject) => { - console.log(config); - axios(req.method == "GET" ? configNoData : config) + let apiPath = req.url.split("/api/proxy/")[1]; + let hasDocument = apiPath.indexOf("/download") > 0 ? true : false; + + axios( + req.method == "GET" + ? hasDocument + ? configDocument + : configNoData + : config + ) .then((response) => { + // console.log(response); res.statusCode = 200; - res.setHeader("Content-Type", "application/json"); - res.setHeader("Cache-Control", "max-age=1800000"); - res.end(JSON.stringify(response.data)); - console.log("response data", response.data); + if (hasDocument) { + res.setHeader("Content-Type", "text/plain"); + res.end(response.data); + } else { + res.setHeader("Content-Type", "application/json"); + res.setHeader("Cache-Control", "max-age=1800000"); + res.end(JSON.stringify(response.data)); + } + + //console.log("response data", response.data); resolve(); }) .catch((error) => {