Files
classroomio/apps/dashboard/src/routes/api/email/invite/+server.ts
T

47 lines
1.2 KiB
TypeScript
Raw Normal View History

2025-01-09 01:30:01 +01:00
import { json } from '@sveltejs/kit';
import sendEmail from '$mail/sendEmail';
// API to send invite to teacher
export async function POST({ fetch, request }) {
const body = await request.json();
const { org, email } = body;
console.log('/POST api/email/invite', body);
2025-01-09 01:30:01 +01:00
if (!org || !Object.keys(org).length || !email) {
2025-11-01 15:49:29 +01:00
return json({ success: false, message: 'Org data and Teacher name are required' }, { status: 400 });
}
const { id, name, siteName } = org;
const origin = request.headers.get('origin');
const inviteData = JSON.stringify({
email,
orgId: id,
orgSiteName: siteName
});
const inviteLink = `${origin}/invite/t/${encodeURIComponent(btoa(inviteData))}`;
console.log('inviteData', inviteData);
2024-04-12 04:57:19 +01:00
const emailData = [
{
2024-09-23 21:18:33 +01:00
from: `"Best from ClassroomIO" <notify@mail.classroomio.com>`,
2024-04-12 04:57:19 +01:00
to: email,
subject: `Join ${name} on ClassroomIO 😃`,
content: `
<p>Hey there,</p>
<p> You have been invited to join ${name} on ClassroomIO 🎉🎉🎉.</p>
<div>
<a class="button" href="${inviteLink}">Accept Invitation</a>
</div>
2024-09-23 21:18:33 +01:00
`
2024-04-12 04:57:19 +01:00
}
];
await sendEmail(fetch)(emailData);
return json({
success: true,
message: 'Email sent'
});
}