refactor phase 3a api admin auth documents email targeted actions imports

This commit is contained in:
2026-03-12 09:58:39 +00:00
parent cf99d8e466
commit 7bd5c7d833
9 changed files with 65 additions and 63 deletions
+22 -26
View File
@@ -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()
});
}
}
+3 -1
View File
@@ -1,7 +1,9 @@
import axios from "axios";
import CryptoJS from "crypto-js";
import _ from "lodash";
import { getToken, azureHeaders, consoleLogger } from "../../../actions";
import { azureHeaders } from "../../../actions/core/headers";
import { consoleLogger } from "../../../actions/core/logger";
import { getToken } from "../../../actions/core/token";
const WORDKEY = process.env.HASHKEY;
+5 -3
View File
@@ -1,7 +1,9 @@
import axios from "axios";
import CryptoJS from "crypto-js";
import _ from "lodash";
import { azureHeadersPaged, consoleLogger, getToken } from "../../../actions";
import { azureHeadersPaged } from "../../../actions/core/headers";
import { consoleLogger } from "../../../actions/core/logger";
import { getToken } from "../../../actions/core/token";
const WORDKEY = process.env.HASHKEY;
const WEBAPI_URL =
@@ -84,7 +86,7 @@ export default async function ApiProxy(req, res) {
...doc,
pinswg_hashlink: encryptDocReference(
doc.pinswg_isharedocumentreference
),
)
}));
res.status(200).json({ ...data, value: resultsWithLinks });
@@ -92,7 +94,7 @@ export default async function ApiProxy(req, res) {
consoleLogger(error);
res.status(500).json({
error: "Failed to fetch document details.",
details: error.message || error.toString(),
details: error.message || error.toString()
});
}
}
+4 -2
View File
@@ -1,7 +1,9 @@
import axios from "axios";
import CryptoJS from "crypto-js";
import _ from "lodash";
import { getToken, azureHeaders, consoleLogger } from "../../../actions";
import { azureHeaders } from "../../../actions/core/headers";
import { consoleLogger } from "../../../actions/core/logger";
import { getToken } from "../../../actions/core/token";
const WORDKEY = process.env.HASHKEY;
const WEBAPI_URL =
@@ -67,7 +69,7 @@ export default async function ApiProxy(req, res) {
consoleLogger(error);
res.status(500).json({
error: "An error occurred while retrieving data.",
details: error.message || error.toString(),
details: error.message || error.toString()
});
}
}
+3 -1
View File
@@ -1,7 +1,9 @@
import axios from "axios";
import CryptoJS from "crypto-js";
import _ from "lodash";
import { getToken, azureHeaders, consoleLogger } from "../../../actions";
import { azureHeaders } from "../../../actions/core/headers";
import { consoleLogger } from "../../../actions/core/logger";
import { getToken } from "../../../actions/core/token";
const WORDKEY = process.env.HASHKEY;