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 = { const tags = {
containerid: containerName, containerid: containerName,
caseID: foldername, caseID: foldername,
documentType: files[prop][0].fieldName.slice(
0,
files[prop][0].fieldName.indexOf("_")
),
}; };
const withTags = await blockBlobClient.setTags(tags); const withTags = await blockBlobClient.setTags(tags);
const withMeta = await blockBlobClient.setMetadata(tags); const withMeta = await blockBlobClient.setMetadata(tags);
@@ -362,10 +366,13 @@ export const downloadProgressFile = async (
const sasUrl = `${STORAGE_PATH}/${containerName}?${containerToken}`; const sasUrl = `${STORAGE_PATH}/${containerName}?${containerToken}`;
const containerClient = new ContainerClient(sasUrl); const containerClient = new ContainerClient(sasUrl);
const blobClient = containerClient.getBlobClient(blobName); const blobClient = containerClient.getBlobClient(blobName);
const downloadedBlob = await blobClient.download(0); const downloadedBlob = await blobClient.download();
const downloaded = await streamToBuffer(downloadedBlob.readableStreamBody); const downloaded = await streamToBuffer(downloadedBlob.readableStreamBody);
return downloaded;
console.log("Downloaded blob content:", downloaded.toString());
return JSON.parse(downloaded.toString());
}; };
export const downloadAllProgressFiles = async ( export const downloadAllProgressFiles = async (
+9 -9
View File
@@ -1371,19 +1371,19 @@ export const getProgressFromBlob = async (containerName, casereference) => {
}; };
export const sendEmail = async ( export const sendEmail = async (
emailToAddress, templateId,
emailSubject, emailAddress,
emailContentTitle, personalisation,
emailContent reference
) => { ) => {
var mailData = { var mailData = {
"email": emailToAddress, "templateId": templateId,
"subject": emailSubject, "emailAddress": emailAddress,
"emailcontenttitle": emailContentTitle, "reference": reference,
"emailcontent": emailContent, "personalisation": personalisation,
}; };
var queryUrl = "/api/email"; var queryUrl = "/api/email/notify";
var config = { var config = {
method: "post", method: "post",
+4 -2
View File
@@ -1540,7 +1540,8 @@ const RenderFileUpload = (field) => {
width="50" width="50"
/> />
<span className="govuk-body govuk-!-font-size-14 govuk-!-padding-left-5"> <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> </span>
</div> </div>
))} ))}
@@ -1588,7 +1589,8 @@ const RenderFileUpload = (field) => {
} }
> >
<a className="govuk-body govuk-!-font-size-14 govuk-!-padding-left-5 govuk-link"> <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> </a>
</Link> </Link>
</div> </div>
+14 -5
View File
@@ -139,9 +139,9 @@ let BuildCheckSection = (props) => {
</dl> </dl>
<dl className="govuk-summary-list govuk-!-margin-bottom-9 at-summary-list"> <dl className="govuk-summary-list govuk-!-margin-bottom-9 at-summary-list">
<div className="govuk-summary-list__row" key={"9999"}> <div className="govuk-summary-list__row" key={"9999"}>
<dt> <dt className="govuk-summary-list__key">
{_.has(props.props.appealType.fileList.files) && {props.props.appealType.fileList.files.length >
props.props.appealType.fileList.files.length > 0 0
? props.props.appealType.fileList.files.map( ? props.props.appealType.fileList.files.map(
(blob, i) => ( (blob, i) => (
<div <div
@@ -152,12 +152,21 @@ let BuildCheckSection = (props) => {
src={getThumbnailIconByExtension( src={getThumbnailIconByExtension(
blob.name blob.name
)} )}
alt={blob.name} alt={blob.name.slice(
blob.name.indexOf(
"_"
) + 1
)}
width="50" width="50"
/> />
<span className="govuk-body govuk-!-font-size-14 govuk-!-padding-left-5"> <span className="govuk-body govuk-!-font-size-14 govuk-!-padding-left-5">
{blob.name} ( {blob.name.slice(
blob.name.indexOf(
"_"
) + 1
)}
(
{bytesToSize( {bytesToSize(
blob.contentLength 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 incidentId = props.appealType.caseReference.incidentid;
let updateBody = values || {}; let updateBody = values || {};
@@ -169,35 +173,29 @@ let BuildSection = (props) => {
let updateFormCollection = appTypeCollection.LogicalCollectionName; let updateFormCollection = appTypeCollection.LogicalCollectionName;
let primaryAttribute = appTypeCollection.PrimaryIdAttribute; let primaryAttribute = appTypeCollection.PrimaryIdAttribute;
// updateCase( const reference = "PEDW-PARTIAL";
// incidentId, const templateId = "021b0a7b-df00-41f1-b94e-c269bee98c75";
// updateBody, const emailAddress = props.props.accountDetails.loggedinUserEmail;
// updateFormCollection, const personalisation = {
// primaryAttribute, "caseReference": props.appealType.caseReference.ticketnumber,
// 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 && sendSavedEmail == true &&
sendEmail( sendEmail(templateId, emailAddress, personalisation, reference);
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>"
);
useSaveStatus && useSaveStatus &&
router.replace( router.replace(
+9 -7
View File
@@ -50,13 +50,15 @@ let CompleteAppeal = (props) => {
props.appealType.caseReference.ticketnumber props.appealType.caseReference.ticketnumber
); );
sendEmail( const reference = "PEDW-COMPLETE";
props.props.accountDetails.loggedinUserEmail, const templateId = "618e0463-b092-4733-a024-bf8a3bbde808";
"Saved progress for appeal " + const emailAddress = props.props.accountDetails.loggedinUserEmail;
props.appealType.caseReference.ticketnumber, const personalisation = {
"Your saved appeal " + props.appealType.caseReference.ticketnumber, "caseReference": props.appealType.caseReference.ticketnumber,
"You have now completed your appeal." "emailAddress": props.props.accountDetails.loggedinUserEmail,
); "linkExpiry": 10 * 60,
};
sendEmail(templateId, emailAddress, personalisation, reference);
console.log("patching////////"); console.log("patching////////");
patchCase(incidentId); 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( res.setHeader(
"content-disposition", "content-disposition",
"attachment; filename=" + decodeURI(blobName) "attachment; filename=" +
decodeURI(blobName.slice(blobName.indexOf("_") + 1))
); );
return res.status(200).send(downloaded); return res.status(200).send(downloaded);
} else { } else {
+1
View File
@@ -26,6 +26,7 @@ ApiProxy.get(async (req, res) => {
//if (hashAPIPath(checkquerypath) == "&hash=" + checkHash) { //if (hashAPIPath(checkquerypath) == "&hash=" + checkHash) {
const blobObj = await getProgressBlobs(containerName, casefolderID) const blobObj = await getProgressBlobs(containerName, casefolderID)
.then((data) => { .then((data) => {
console.log("ertyuikjhgfg", data.path);
return downloadProgressFile(containerName, data.path, casefolderID); return downloadProgressFile(containerName, data.path, casefolderID);
}) })
.then((data) => { .then((data) => {