diff --git a/actions/index.js b/actions/index.js index a988fc54..5060f5c1 100644 --- a/actions/index.js +++ b/actions/index.js @@ -1969,36 +1969,12 @@ export const sendEmail = async ( "personalisation": personalisation }; - //console.log( - // "hwewwew: ", - // templateId, - // emailAddress, - // personalisation, - // reference - // ); - // var queryUrl = "/api/email/notify"; - - // var config = { - // method: "post", - // url: queryUrl, - // data: mailData, - // }; - - // return axios(config) - // .then((res) => { - // //console.log("posted ", res.data); - // return res.data; - // }) - // .catch((error) => { - // consoleLogger(error); - // }); - try { const response = await axios.post("/api/email/notify", mailData); return response.data; } catch (error) { consoleLogger(error); // Optional custom logging - throw error; // ✅ Ensure the calling function sees the error + throw error; } }; diff --git a/pages/api/email/notify.js b/pages/api/email/notify.js index 9647876d..299e93b5 100644 --- a/pages/api/email/notify.js +++ b/pages/api/email/notify.js @@ -25,11 +25,25 @@ * description: Failed */ -import { consoleLogger } from "../../../actions"; +import { consoleLogger, getPreferredLanguage } from "../../../actions"; export default async function ApiProxy(req, res) { var data = req.body; + if (data?.reference === "PEDW-NEW-CASEREF") { + try { + const prefLang = await getPreferredLanguage(data.emailAddress); + const preferredLanguage = + prefLang?.value?.[0]?.pinswg_preferredlanguage; + + if (preferredLanguage === 846040000) { + data.templateId = "d2d9d0dc-e5d4-4da5-9156-775521d69c5c"; + } + } catch (error) { + consoleLogger(error); + } + } + var NotifyClient = require("notifications-node-client").NotifyClient; const notifyClient = new NotifyClient(process.env.NOTIFY_API_KEY); @@ -40,7 +54,7 @@ export default async function ApiProxy(req, res) { notifyClient .sendEmail(data.templateId, data.emailAddress, { personalisation: data.personalisation, - reference: data.reference, + reference: data.reference // emailReplyToId: emailReplyToId, }) .then((response) => {