Skip to content

Commit

Permalink
Add ability to unsubscribe
Browse files Browse the repository at this point in the history
  • Loading branch information
Timothy-Gonzalez committed Jan 23, 2025
1 parent 97a5f91 commit 18b2957
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/services/newsletter/newsletter-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,30 @@ newsletterRouter.post(
},
);

newsletterRouter.delete(
"/subscribe/",
specification({
method: "delete",
path: "/newsletter/subscribe/",
tag: Tag.NEWSLETTER,
role: null,
summary: "Unsubscribes the requested email to the requested newsletter",
body: SubscribeRequestSchema,
responses: {
[StatusCode.SuccessOK]: {
description:
"If the email was subscribed, it no longer is. For privacy reasons, whether this email was subscribed or not is hidden.",
schema: SuccessResponseSchema,
},
},
}),
async (req, res) => {
const { listName, emailAddress } = req.body;

const updateQuery: UpdateQuery<NewsletterSubscription> = { $pull: { subscribers: emailAddress } };
await Models.NewsletterSubscription.findOneAndUpdate({ newsletterId: listName }, updateQuery, { upsert: true });
return res.status(StatusCode.SuccessOK).send({ success: true });
},
);

export default newsletterRouter;

0 comments on commit 18b2957

Please sign in to comment.