fix format

This commit is contained in:
Erza Bytyci
2026-05-19 06:35:47 +00:00
parent e2968974f7
commit b5046d2c02
2 changed files with 57 additions and 52 deletions
+1 -1
View File
@@ -51,4 +51,4 @@ export async function POST(req) {
{ status: 500 }
);
}
};
}
+56 -51
View File
@@ -3,63 +3,68 @@ const isDevelopment = process.env.NODE_ENV === "development";
const isCI = process.env.CI === "true";
const settings = {
hideToska: false,
disableToska: true,
color: "orange",
header: "GRADESA",
headerFontColor: "white",
dryrun: false,
hideToska: false,
disableToska: true,
color: "orange",
header: "GRADESA",
headerFontColor: "white",
dryrun: false,
};
const sendEmail = async ({ to, subject, text }) => {
if (!to || !subject || !text) {
throw new Error("Missing email fields: to, subject and text are required");
}
if (!to || !subject || !text) {
throw new Error("Missing email fields: to, subject and text are required");
}
const mail = {
template: {
from: "GRADESA",
text,
const mail = {
template: {
from: "GRADESA",
text,
},
emails: [
{
to,
subject,
},
],
settings,
};
if (isCI || isDevelopment) {
console.info("Skipping email sending in CI/development", {
to,
subject,
nodeEnv: process.env.NODE_ENV,
});
return;
}
if (!process.env.PATE_TOKEN) {
throw new Error("PATE_TOKEN missing");
}
try {
const response = await fetch(
`${PATE_URL}?token=${process.env.PATE_TOKEN}`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
emails: [
{
to,
subject,
},
],
settings,
};
body: JSON.stringify(mail),
}
);
if (isCI || isDevelopment) {
console.info("Skipping email sending in CI/development", {
to,
subject,
nodeEnv: process.env.NODE_ENV,
});
return;
}
if (!process.env.PATE_TOKEN) {
throw new Error("PATE_TOKEN missing");
}
try {
const response = await fetch(`${PATE_URL}?token=${process.env.PATE_TOKEN}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(mail),
});
if (!response.ok) {
const errorBody = await response.text();
throw new Error(`PATE email sending failed with status ${response.status}: ${errorBody}`);
}
} catch (error) {
console.error("PATE fetch error:", error);
throw error;
if (!response.ok) {
const errorBody = await response.text();
throw new Error(
`PATE email sending failed with status ${response.status}: ${errorBody}`
);
}
} catch (error) {
console.error("PATE fetch error:", error);
throw error;
}
};
export default sendEmail;
export default sendEmail;