refactor phase 3a api admin auth documents email targeted actions imports
This commit is contained in:
+22
-26
@@ -1,13 +1,9 @@
|
||||
import axios from "axios";
|
||||
import CryptoJS from "crypto-js";
|
||||
import _ from "lodash";
|
||||
import {
|
||||
getToken,
|
||||
azureHeaders,
|
||||
azureHeadersPaged,
|
||||
consoleLogger,
|
||||
sendEmail,
|
||||
} from "../../../actions";
|
||||
import { azureHeaders, azureHeadersPaged } from "../../../actions/core/headers";
|
||||
import { consoleLogger } from "../../../actions/core/logger";
|
||||
import { getToken } from "../../../actions/core/token";
|
||||
import { formatDates } from "../../../components/utils";
|
||||
|
||||
var NotifyClient = require("notifications-node-client").NotifyClient;
|
||||
@@ -79,14 +75,14 @@ const buildNotifyPayloads = (watchlistByEmail) => {
|
||||
noRef: "No Ref",
|
||||
untitled: "Untitled",
|
||||
noDate: "No Date",
|
||||
link: "Link",
|
||||
link: "Link"
|
||||
},
|
||||
cy: {
|
||||
noRef: "Dim Cyfeirnod",
|
||||
untitled: "Heb Deitl",
|
||||
noDate: "Dim Dyddiad",
|
||||
link: "Dolen",
|
||||
},
|
||||
link: "Dolen"
|
||||
}
|
||||
};
|
||||
|
||||
const t = labels[language] || labels.en;
|
||||
@@ -114,13 +110,13 @@ const buildNotifyPayloads = (watchlistByEmail) => {
|
||||
en: {
|
||||
unnamed: "Unnamed Event",
|
||||
noDate: "No Date",
|
||||
on: "on",
|
||||
on: "on"
|
||||
},
|
||||
cy: {
|
||||
unnamed: "Digwyddiad Heb Enw",
|
||||
noDate: "Dim Dyddiad",
|
||||
on: "ar",
|
||||
},
|
||||
on: "ar"
|
||||
}
|
||||
};
|
||||
|
||||
const t = labels[language] || labels.en;
|
||||
@@ -144,14 +140,14 @@ const buildNotifyPayloads = (watchlistByEmail) => {
|
||||
open: "Open",
|
||||
to: "to",
|
||||
close: "Close",
|
||||
na: "N/A",
|
||||
na: "N/A"
|
||||
},
|
||||
cy: {
|
||||
open: "Agor",
|
||||
to: "i",
|
||||
close: "Cau",
|
||||
na: "Dim ar gael",
|
||||
},
|
||||
na: "Dim ar gael"
|
||||
}
|
||||
};
|
||||
|
||||
const t = labels[language] || labels.en;
|
||||
@@ -234,7 +230,7 @@ const buildNotifyPayloads = (watchlistByEmail) => {
|
||||
docSection,
|
||||
sipSection,
|
||||
repsSection,
|
||||
caseUnsubscribelink,
|
||||
caseUnsubscribelink
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join("\n")}`;
|
||||
@@ -242,7 +238,7 @@ const buildNotifyPayloads = (watchlistByEmail) => {
|
||||
.join("\n\n"),
|
||||
unsubscribeLink: `Unsubscribe by selecting this link if you no longer want to receive any updates ${
|
||||
process.env.NEXTAUTH_URL + "/unsubscribeall/" + contactId
|
||||
}`,
|
||||
}`
|
||||
};
|
||||
|
||||
const personalisationCY = {
|
||||
@@ -281,7 +277,7 @@ const buildNotifyPayloads = (watchlistByEmail) => {
|
||||
docSection,
|
||||
sipSection,
|
||||
repsSection,
|
||||
caseUnsubscribelink,
|
||||
caseUnsubscribelink
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join("\n")}`;
|
||||
@@ -289,7 +285,7 @@ const buildNotifyPayloads = (watchlistByEmail) => {
|
||||
.join("\n\n"),
|
||||
unsubscribeLink: `Dad-danysgrifiwch drwy ddewis y ddolen hon os nad ydych chi eisiau derbyn unrhyw ddiweddariadau mwyach ${
|
||||
process.env.NEXTAUTH_URL + "/unsubscribeall/" + contactId
|
||||
}`,
|
||||
}`
|
||||
};
|
||||
|
||||
return {
|
||||
@@ -305,7 +301,7 @@ const buildNotifyPayloads = (watchlistByEmail) => {
|
||||
process.env.NEXTAUTH_URL +
|
||||
(prefLanguage == 846040001 ? "en" : "cy") +
|
||||
"/unsubscribeall/" +
|
||||
contactId,
|
||||
contactId
|
||||
};
|
||||
})
|
||||
.filter(Boolean); // Remove any nulls from filtered-out users
|
||||
@@ -348,7 +344,7 @@ export default async function CombinedApiProxy(req, res) {
|
||||
...doc,
|
||||
pinswg_hashlink: encryptDocReference(
|
||||
doc.pinswg_isharedocumentreference
|
||||
),
|
||||
)
|
||||
}));
|
||||
} catch (err) {
|
||||
consoleLogger(
|
||||
@@ -401,7 +397,7 @@ export default async function CombinedApiProxy(req, res) {
|
||||
...entry,
|
||||
repsPeriods,
|
||||
documents,
|
||||
sipEvents,
|
||||
sipEvents
|
||||
};
|
||||
})
|
||||
);
|
||||
@@ -428,7 +424,7 @@ export default async function CombinedApiProxy(req, res) {
|
||||
reference: payload.reference,
|
||||
template_id: payload.template_id,
|
||||
language:
|
||||
payload.pinswg_preferredlanguage == 846040001 ? "en" : "cy",
|
||||
payload.pinswg_preferredlanguage == 846040001 ? "en" : "cy"
|
||||
};
|
||||
|
||||
try {
|
||||
@@ -437,7 +433,7 @@ export default async function CombinedApiProxy(req, res) {
|
||||
payload.email_address,
|
||||
{
|
||||
personalisation: payload.personalisation,
|
||||
reference: payload.reference,
|
||||
reference: payload.reference
|
||||
}
|
||||
);
|
||||
result.status = "success";
|
||||
@@ -455,7 +451,7 @@ export default async function CombinedApiProxy(req, res) {
|
||||
consoleLogger(error);
|
||||
res.status(500).json({
|
||||
error: "An error occurred while retrieving combined data.",
|
||||
details: error.message || error.toString(),
|
||||
details: error.message || error.toString()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user