feat(user notifications): added the ability for users to sub to notifications and add multi email

This commit is contained in:
2026-04-06 09:29:46 -05:00
parent 3ecf5fb916
commit 637de857f9
7 changed files with 207 additions and 16 deletions

View File

@@ -25,8 +25,25 @@ r.post("/", async (req, res: Response) => {
try {
const validated = newSubscribe.parse(req.body);
const emails = validated.emails
.map((e) => e.trim().toLowerCase())
.filter(Boolean);
const uniqueEmails = [...new Set(emails)];
const { data, error } = await tryCatch(
db.insert(notificationSub).values(validated).returning(),
db
.insert(notificationSub)
.values({
userId: req?.user?.id ?? "",
notificationId: validated.notificationId,
emails: uniqueEmails,
})
.onConflictDoUpdate({
target: [notificationSub.userId, notificationSub.notificationId],
set: { emails: uniqueEmails },
})
.returning(),
);
await modifiedNotification(validated.notificationId);