mirror of
https://github.com/OpenSquawk/OpenSquawk
synced 2026-08-10 11:33:26 +08:00
Add unsubscribe endpoint and email footers
This commit is contained in:
@@ -57,8 +57,8 @@ export default defineEventHandler(async () => {
|
||||
entry.invitationSentAt = sentAt
|
||||
await entry.save()
|
||||
|
||||
const html = await renderInvitationEmail(invitation.code)
|
||||
const text = renderInvitationText(invitation.code)
|
||||
const html = await renderInvitationEmail(invitation.code, email)
|
||||
const text = renderInvitationText(invitation.code, email)
|
||||
|
||||
await sendMail({
|
||||
to: email,
|
||||
@@ -88,8 +88,8 @@ export default defineEventHandler(async () => {
|
||||
|
||||
const requestedAt = new Date()
|
||||
|
||||
const text = renderFeedbackText()
|
||||
const html = await renderFeedbackEmail()
|
||||
const text = renderFeedbackText(email)
|
||||
const html = await renderFeedbackEmail(email)
|
||||
|
||||
await sendMail({
|
||||
to: email,
|
||||
|
||||
33
server/api/service/updates.delete.ts
Normal file
33
server/api/service/updates.delete.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { createError, readBody } from 'h3'
|
||||
import { UpdateSubscriber } from '../../models/UpdateSubscriber'
|
||||
import { WaitlistEntry } from '../../models/WaitlistEntry'
|
||||
|
||||
interface UnsubscribeRequestBody {
|
||||
email?: string
|
||||
}
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readBody<UnsubscribeRequestBody>(event)
|
||||
const email = body.email?.trim().toLowerCase()
|
||||
|
||||
if (!email) {
|
||||
throw createError({ statusCode: 400, statusMessage: 'Email is required' })
|
||||
}
|
||||
|
||||
const [updateResult, waitlistResult] = await Promise.all([
|
||||
UpdateSubscriber.deleteOne({ email }),
|
||||
WaitlistEntry.deleteOne({ email }),
|
||||
])
|
||||
|
||||
const removed = Boolean(updateResult.deletedCount || waitlistResult.deletedCount)
|
||||
|
||||
if (!removed) {
|
||||
throw createError({ statusCode: 404, statusMessage: 'No matching email found' })
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
removedFromUpdates: updateResult.deletedCount > 0,
|
||||
removedFromWaitlist: waitlistResult.deletedCount > 0,
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user