sendemail function for gov notify

This commit is contained in:
2022-11-17 13:16:57 +00:00
parent b0a9b721a3
commit 6fe3fc51a6
9 changed files with 100 additions and 54 deletions
+9 -2
View File
@@ -328,6 +328,10 @@ export const uploadFile = async (formContent, containerName, foldername) => {
const tags = {
containerid: containerName,
caseID: foldername,
documentType: files[prop][0].fieldName.slice(
0,
files[prop][0].fieldName.indexOf("_")
),
};
const withTags = await blockBlobClient.setTags(tags);
const withMeta = await blockBlobClient.setMetadata(tags);
@@ -362,10 +366,13 @@ export const downloadProgressFile = async (
const sasUrl = `${STORAGE_PATH}/${containerName}?${containerToken}`;
const containerClient = new ContainerClient(sasUrl);
const blobClient = containerClient.getBlobClient(blobName);
const downloadedBlob = await blobClient.download(0);
const downloadedBlob = await blobClient.download();
const downloaded = await streamToBuffer(downloadedBlob.readableStreamBody);
return downloaded;
console.log("Downloaded blob content:", downloaded.toString());
return JSON.parse(downloaded.toString());
};
export const downloadAllProgressFiles = async (
+9 -9
View File
@@ -1371,19 +1371,19 @@ export const getProgressFromBlob = async (containerName, casereference) => {
};
export const sendEmail = async (
emailToAddress,
emailSubject,
emailContentTitle,
emailContent
templateId,
emailAddress,
personalisation,
reference
) => {
var mailData = {
"email": emailToAddress,
"subject": emailSubject,
"emailcontenttitle": emailContentTitle,
"emailcontent": emailContent,
"templateId": templateId,
"emailAddress": emailAddress,
"reference": reference,
"personalisation": personalisation,
};
var queryUrl = "/api/email";
var queryUrl = "/api/email/notify";
var config = {
method: "post",
+4 -2
View File
@@ -1540,7 +1540,8 @@ const RenderFileUpload = (field) => {
width="50"
/>
<span className="govuk-body govuk-!-font-size-14 govuk-!-padding-left-5">
{file.name} ({bytesToSize(file.size)})
{file.name.slice(file.name.indexOf("_") + 1)} (
({bytesToSize(file.size)})
</span>
</div>
))}
@@ -1588,7 +1589,8 @@ const RenderFileUpload = (field) => {
}
>
<a className="govuk-body govuk-!-font-size-14 govuk-!-padding-left-5 govuk-link">
{blob.name} ({bytesToSize(blob.contentLength)})
{blob.name.slice(blob.name.indexOf("_") + 1)} (
{bytesToSize(blob.contentLength)})
</a>
</Link>
</div>
+14 -5
View File
@@ -139,9 +139,9 @@ let BuildCheckSection = (props) => {
</dl>
<dl className="govuk-summary-list govuk-!-margin-bottom-9 at-summary-list">
<div className="govuk-summary-list__row" key={"9999"}>
<dt>
{_.has(props.props.appealType.fileList.files) &&
props.props.appealType.fileList.files.length > 0
<dt className="govuk-summary-list__key">
{props.props.appealType.fileList.files.length >
0
? props.props.appealType.fileList.files.map(
(blob, i) => (
<div
@@ -152,12 +152,21 @@ let BuildCheckSection = (props) => {
src={getThumbnailIconByExtension(
blob.name
)}
alt={blob.name}
alt={blob.name.slice(
blob.name.indexOf(
"_"
) + 1
)}
width="50"
/>
<span className="govuk-body govuk-!-font-size-14 govuk-!-padding-left-5">
{blob.name} (
{blob.name.slice(
blob.name.indexOf(
"_"
) + 1
)}
(
{bytesToSize(
blob.contentLength
)}
+26 -28
View File
@@ -125,7 +125,11 @@ let BuildSection = (props) => {
});
};
const updateCaseProgress = (values, sendSavedEmail, useSaveStatus) => {
const updateCaseProgress = async (
values,
sendSavedEmail,
useSaveStatus
) => {
let incidentId = props.appealType.caseReference.incidentid;
let updateBody = values || {};
@@ -169,35 +173,29 @@ let BuildSection = (props) => {
let updateFormCollection = appTypeCollection.LogicalCollectionName;
let primaryAttribute = appTypeCollection.PrimaryIdAttribute;
// updateCase(
// incidentId,
// updateBody,
// updateFormCollection,
// primaryAttribute,
// props.appealType.caseReference.ticketnumber
// );
const reference = "PEDW-PARTIAL";
const templateId = "021b0a7b-df00-41f1-b94e-c269bee98c75";
const emailAddress = props.props.accountDetails.loggedinUserEmail;
const personalisation = {
"caseReference": props.appealType.caseReference.ticketnumber,
"emailAddress": props.props.accountDetails.loggedinUserEmail,
"returnLink":
props.props.url +
"/myportal/" +
appTypeCollection.UrlName +
"?lpa=" +
props.appealType.appealLPA +
"&apt=" +
appTypeCollection.appealTypeID +
"&casereference=" +
props.appealType.caseReference.ticketnumber +
"&inid=" +
props.appealType.caseReference.incidentid,
"linkExpiry": 10 * 60,
};
sendSavedEmail == true &&
sendEmail(
props.props.accountDetails.loggedinUserEmail,
"Saved progress for appeal " +
props.appealType.caseReference.ticketnumber,
"Your saved appeal " +
props.appealType.caseReference.ticketnumber,
"You can resume your application at a later date <a href='" +
props.props.url +
"/myportal/" +
appTypeCollection.UrlName +
"?lpa=" +
props.appealType.appealLPA +
"&apt=" +
appTypeCollection.appealTypeID +
"&casereference=" +
props.appealType.caseReference.ticketnumber +
"&inid=" +
props.appealType.caseReference.incidentid +
"'> from here </a>"
);
sendEmail(templateId, emailAddress, personalisation, reference);
useSaveStatus &&
router.replace(
+9 -7
View File
@@ -50,13 +50,15 @@ let CompleteAppeal = (props) => {
props.appealType.caseReference.ticketnumber
);
sendEmail(
props.props.accountDetails.loggedinUserEmail,
"Saved progress for appeal " +
props.appealType.caseReference.ticketnumber,
"Your saved appeal " + props.appealType.caseReference.ticketnumber,
"You have now completed your appeal."
);
const reference = "PEDW-COMPLETE";
const templateId = "618e0463-b092-4733-a024-bf8a3bbde808";
const emailAddress = props.props.accountDetails.loggedinUserEmail;
const personalisation = {
"caseReference": props.appealType.caseReference.ticketnumber,
"emailAddress": props.props.accountDetails.loggedinUserEmail,
"linkExpiry": 10 * 60,
};
sendEmail(templateId, emailAddress, personalisation, reference);
console.log("patching////////");
patchCase(incidentId);
+26
View File
@@ -0,0 +1,26 @@
import { consoleLogger } from "../../../actions";
export default async function ApiProxy(req, res) {
var data = req.body;
var NotifyClient = require("notifications-node-client").NotifyClient;
const notifyClient = new NotifyClient(process.env.NOTIFY_API_KEY);
//const emailReplyToId = process.env.EMAIL_REPLY_TO_ID;
notifyClient
.sendEmail(data.templateId, data.emailAddress, {
personalisation: data.personalisation,
reference: data.reference,
// emailReplyToId: emailReplyToId,
})
.then((response) => {
//console.log("thisis the response", response);
return res.status(200).json(data);
})
.catch((err) => {
consoleLogger(err);
return res.status(400).json(err);
});
//return res.status(200).json(data);
}
+2 -1
View File
@@ -32,7 +32,8 @@ ApiProxy.get(async (req, res) => {
res.setHeader(
"content-disposition",
"attachment; filename=" + decodeURI(blobName)
"attachment; filename=" +
decodeURI(blobName.slice(blobName.indexOf("_") + 1))
);
return res.status(200).send(downloaded);
} else {
+1
View File
@@ -26,6 +26,7 @@ ApiProxy.get(async (req, res) => {
//if (hashAPIPath(checkquerypath) == "&hash=" + checkHash) {
const blobObj = await getProgressBlobs(containerName, casefolderID)
.then((data) => {
console.log("ertyuikjhgfg", data.path);
return downloadProgressFile(containerName, data.path, casefolderID);
})
.then((data) => {