get pending reps to dashboard from St Acc

This commit is contained in:
2023-01-16 09:56:37 +00:00
parent ee4d00a500
commit 0c1de7d26b
7 changed files with 239 additions and 34 deletions
+81 -1
View File
@@ -41,7 +41,7 @@ export const createContainerSas = async (containerName) => {
);
// Need only list permission to list blobs
const containerPermissions = "rcwltd";
const containerPermissions = "rcwltdf";
// Best practice: SAS options are time-limited
const sasOptions = {
@@ -472,6 +472,50 @@ export const downloadAllProgressFiles = async (
);
};
export const downloadAllRepsFiles = async (containerName, repsBlobObj) => {
console.log(
"/////////////////////////\n downloading files: " +
JSON.stringify(repsBlobObj) +
"\n/////////////////////////\n"
);
const containerToken = await createContainerSas(containerName);
const sasUrl = `${STORAGE_PATH}/${containerName}?${containerToken}`;
const containerClient = new ContainerClient(sasUrl);
let blobClient = {};
let downloadedBlob = {};
let repArr = [];
let downloaded = "";
let caseBlob = {};
let caseDownloaded = "";
let blobCount = 0;
for (const prop in repsBlobObj) {
console.log(`Progress - ${prop}: ${repsBlobObj[prop].name}`);
blobClient = containerClient.getBlobClient(repsBlobObj[prop].name);
downloadedBlob = await blobClient.download(0);
let repBlobObj = await streamToBuffer(
downloadedBlob.readableStreamBody
);
repBlobObj = JSON.parse(repBlobObj);
repBlobObj["casereference"] = repsBlobObj[prop].name.split("/")[0];
repBlobObj = JSON.stringify(repBlobObj);
downloaded = downloaded + repBlobObj + ",";
blobCount++;
}
downloaded = downloaded.substring(0, downloaded.length - 1);
return JSON.parse(
'{ "@odata.count": ' + blobCount + ',"value": [' + downloaded + "]}"
);
};
const streamToBuffer = async (readableStream) => {
return new Promise((resolve, reject) => {
const chunks = [];
@@ -605,3 +649,39 @@ export const getAllProgressBlobs = async (containerName) => {
return blobObj;
};
export const getRepslobs = async (containerName, caseReference) => {
const containerToken = await createContainerSas(containerName);
const sasUrl = `${STORAGE_PATH}/${containerName}?${containerToken}`;
const containerClient = new ContainerClient(sasUrl);
let blobCount = 0;
for await (const blob of containerClient.findBlobsByTags(
"blobType='Representation'"
)) {
blobCount++;
}
console.log("this is the caasefolder:", caseReference, blobCount);
let blobObj = [];
for await (const blob of containerClient.findBlobsByTags(
"blobType='Representation'"
)) {
console.log("in here");
console.log(blob);
blobObj.push(blob);
}
// blobObj = _.sortBy(blobObj, [
// function (o) {
// return o.lastModified;
// },
// ]).reverse()[0];
console.log("blobObjwwwww:", blobObj);
return blobObj;
};
+21
View File
@@ -793,6 +793,27 @@ export const getAwaitingSubmissionFromBlob = (containerName) => {
});
};
export const getRepsFromBlob = (containerName) => {
console.log(
"///////////////////////getRepsFromBlob: " +
containerName +
"\n///////////////////////\n"
);
return axios
.get(
BASE_URL +
"/api/file/getrepsblob?container=" +
containerName +
hashAPIPath("/api/file/getrepsblob?container=" + containerName)
)
.then((res) => {
return res.data;
})
.catch((error) => {
//console.log("API call error", error);
});
};
export const getAwaitingSubmissionFromBlobProxy = (containerName) => {
return axios
.get(
+19 -18
View File
@@ -288,7 +288,6 @@ const CaseSummary = (props) => {
</dl>
</div>
</div>
{props.currentView.showReps == true ||
(props.currentView.showReps == "true" &&
_.has(detailsObj, "pinswg_startdate") &&
@@ -335,26 +334,28 @@ const CaseSummary = (props) => {
</div>
</div>
))}
{props.currentView.showReps == true &&
_.has(detailsObj, "pinswg_startdate") &&
hasEndDate &&
showRepsEnded(
detailsObj.pinswg_startdate,
detailsObj.pinswg_representation_period_end_date
) && (
<div className="govuk-grid-row">
<div className="govuk-grid-column-full">
<div className="govuk-button-group">
<div className="govuk-body">
Representation Period ended on{" "}
{formatDates(
detailsObj.pinswg_representation_period_end_date
)}
{props.currentView.showReps == true ||
(props.currentView.showReps == "true" &&
_.has(detailsObj, "pinswg_startdate") &&
hasEndDate &&
showRepsEnded(
detailsObj.pinswg_startdate,
detailsObj.pinswg_representation_period_end_date
) && (
<div className="govuk-grid-row">
<div className="govuk-grid-column-full">
<div className="govuk-button-group">
<div className="govuk-body">
Representation Period ended on{" "}
{formatDates(
detailsObj.pinswg_representation_period_end_date
)}
</div>
</div>
</div>
</div>
</div>
)}
))}
{/* 1{" "}
{_.has(detailsObj, "pinswg_startdatetimeiftheevent") &&
detailsObj.pinswg_startdatetimeiftheevent}
@@ -0,0 +1,62 @@
import Link from "next/link";
import { useRouter } from "next/router";
import useTranslation from "next-translate/useTranslation";
import TopThree from "./topthree_reps";
import { connect } from "react-redux";
import { setCurrentView } from "../../store/currentView/action";
const MyRepresentations = (props) => {
let { t } = useTranslation();
const router = useRouter();
const { locale } = router;
const { setCurrentView } = props;
return (
<div className="card" id="casescomment-card">
<div className="card-body">
<h3 className="heading-small card-heading">
{t("myportal:myrepresentations-card-title")}dd
</h3>
<div className="cardModuleContainer">
<TopThree
showTopThree={props.myRepresentations.myRepresentations}
showDetails={
props.myRepresentations.myRepresentationsDetails
}
topThreeType={"myRepresentations"}
/>
</div>
{props.myRepresentations.myRepresentations["@odata.count"] >
3 && (
<div className="cardVieAll">
<Link href="/myportal/viewall" shallow>
<a
className="govuk-link--no-underline"
onClick={() => {
setCurrentView({
"viewName": "My Representations",
"viewKey": "myRepresentations",
});
}}
>
{t("myportal:viewall-link")}
</a>
</Link>
</div>
)}
</div>
</div>
);
};
const mapDispatchToProps = (dispatch) => {
return {
setCurrentView: (currentView) => {
dispatch(setCurrentView(currentView));
},
};
};
export default connect(null, mapDispatchToProps)(MyRepresentations);
+4 -9
View File
@@ -123,7 +123,7 @@ const TopThree = (props) => {
return objArr._pinswg_watchedcase_value;
break;
case "myRepresentations":
return objArr.ticketnumber;
return objArr.casereference;
break;
case "awaitingSubmission":
return objArr.ticketnumber;
@@ -152,9 +152,8 @@ const TopThree = (props) => {
"myRepresentations"
? showTopThreeArr[key]
.ticketnumber
: showTopThreeArr[key][
"_pinswg_case_value@OData.Community.Display.V1.FormattedValue"
]
: showTopThreeArr[key]
.casereference
: showTopThreeArr[key][
"_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue"
],
@@ -177,11 +176,7 @@ const TopThree = (props) => {
</div>
<div className="cardModuleReference">
<b>{t("myportal:case-reference")}:</b>{" "}
{
showTopThreeArr[key][
"_pinswg_case_value@OData.Community.Display.V1.FormattedValue"
]
}
{showTopThreeArr[key].casereference}
</div>
</div>
</div>
+49
View File
@@ -0,0 +1,49 @@
import {
downloadAllRepsFiles,
getRepslobs,
} from "../../../actions/azurestorage";
import _ from "lodash";
import nextConnect from "next-connect";
import middleware from "../middleware/middleware";
const ApiProxy = nextConnect();
ApiProxy.use(middleware);
ApiProxy.get(async (req, res) => {
var containerName = req.query.container;
var casefolderID = req.query.casefolderID;
var checkHash = req.query.hash;
var checkquerypath =
"/api/file/getrepsblob?container=" +
containerName +
"&casefolderID=" +
casefolderID;
console.log(checkquerypath);
// console.log(hashAPIPath(checkquerypath), checkHash);
// console.log(hashAPIPath(checkquerypath) == "&hash=" + checkHash);
//if (hashAPIPath(checkquerypath) == "&hash=" + checkHash) {
const blobObj = await getRepslobs(containerName, casefolderID)
.then((data) => {
console.log("ertyuikjhgfg", data);
return downloadAllRepsFiles(containerName, data);
})
.then((data) => {
return res.status(200).json(data);
});
// } else {
// return res.status(400).json();
// }
});
export const config = {
api: {
bodyParser: false,
},
};
export default ApiProxy;
+3 -6
View File
@@ -5,6 +5,7 @@ import Head from "next/head";
import { useRouter } from "next/router";
import { connect } from "react-redux";
import {
getRepsFromBlob,
getAwaitingSubmissionFromBlob,
getAwaitingSubmission,
getMyCases,
@@ -194,7 +195,7 @@ export const getServerSideProps = wrapper.getServerSideProps(
] = await Promise.all([
await getPersonalAccount(loggedInUser),
await getMyCases(loggedInUser),
await getMyRepresentations(loggedInUser),
await getRepsFromBlob(thisSession.user.id),
await getWatchedCases(loggedInUser),
await getAwaitingSubmission(loggedInUser),
await getAwaitingSubmissionFromBlob(thisSession.user.id),
@@ -216,12 +217,10 @@ export const getServerSideProps = wrapper.getServerSideProps(
} else {
const [
myCasesDetails,
myRepresentationsDetails,
watchedCasesDetails,
awaitingSubmissionDetails,
] = await Promise.all([
await getDetails(myCases, "myCases"),
await getDetails(myRepresentations, "myRepresentations"),
await getDetails(watchedCases, "myWatchedCases"),
await getDetails(awaitingSubmission, "awaitingSubmission"),
]);
@@ -231,9 +230,7 @@ export const getServerSideProps = wrapper.getServerSideProps(
store.dispatch(setMyCases(myCases));
store.dispatch(setMyCasesDetails(myCasesDetails));
store.dispatch(setMyRepresentations(myRepresentations));
store.dispatch(
setMyRepresentationsDetails(myRepresentationsDetails)
);
store.dispatch(setWatchedCases(watchedCases));
store.dispatch(setWatchedCasesDetails(watchedCasesDetails));
store.dispatch(setAwaitingSubmission(awaitingSubmission));