From 24e612858f47dbbc821d2e359a37ca27c77e6991 Mon Sep 17 00:00:00 2001 From: LaGodxy <83363896+LaGodxy@users.noreply.github.com> Date: Sat, 25 Apr 2026 01:03:59 -0700 Subject: [PATCH] =?UTF-8?q?Revert=20"feat(email):=20unsubscribe=20+=20noti?= =?UTF-8?q?fication=20throttling=20with=20preferences=20a=E2=80=A6"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/email/email-report.entity.ts | 0 src/email/email-report.service.ts | 34 ------------------- src/email/email-template.ts | 0 src/email/email.controller.ts | 12 ------- src/email/preferences.entity.ts | 0 src/email/unsubscribe.controller.ts | 0 .../notification-preferences.entity.ts | 0 .../notification-throttle.util.ts | 30 ---------------- src/notifications/notification.controller.ts | 16 --------- src/notifications/notification.service.ts | 15 -------- src/utils/observability.ts | 10 ------ 11 files changed, 117 deletions(-) delete mode 100644 src/email/email-report.entity.ts delete mode 100644 src/email/email-report.service.ts delete mode 100644 src/email/email-template.ts delete mode 100644 src/email/email.controller.ts delete mode 100644 src/email/preferences.entity.ts delete mode 100644 src/email/unsubscribe.controller.ts delete mode 100644 src/notifications/notification-preferences.entity.ts delete mode 100644 src/notifications/notification-throttle.util.ts delete mode 100644 src/notifications/notification.controller.ts delete mode 100644 src/notifications/notification.service.ts delete mode 100644 src/utils/observability.ts diff --git a/src/email/email-report.entity.ts b/src/email/email-report.entity.ts deleted file mode 100644 index e69de29b..00000000 diff --git a/src/email/email-report.service.ts b/src/email/email-report.service.ts deleted file mode 100644 index a5e0fc08..00000000 --- a/src/email/email-report.service.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { Injectable } from '@nestjs/common'; -import { PrismaService } from '../prisma/prisma.service'; - -@Injectable() -export class EmailReportService { - constructor(private readonly prisma: PrismaService) {} - - async recordDelivery(emailId: string, status: 'delivered' | 'bounced' | 'opened' | 'clicked') { - return this.prisma.emailReport.create({ - data: { - emailId, - delivered: status === 'delivered', - bounced: status === 'bounced', - opened: status === 'opened', - clicked: status === 'clicked', - }, - }); - } - - async getMetrics() { - const total = await this.prisma.emailReport.count(); - const delivered = await this.prisma.emailReport.count({ where: { delivered: true } }); - const bounced = await this.prisma.emailReport.count({ where: { bounced: true } }); - const opened = await this.prisma.emailReport.count({ where: { opened: true } }); - const clicked = await this.prisma.emailReport.count({ where: { clicked: true } }); - - return { - deliveryRate: delivered / total, - bounceRate: bounced / total, - openRate: opened / total, - clickRate: clicked / total, - }; - } -} diff --git a/src/email/email-template.ts b/src/email/email-template.ts deleted file mode 100644 index e69de29b..00000000 diff --git a/src/email/email.controller.ts b/src/email/email.controller.ts deleted file mode 100644 index 45898554..00000000 --- a/src/email/email.controller.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Controller, Get } from '@nestjs/common'; -import { EmailReportService } from './email-report.service'; - -@Controller('emails') -export class EmailController { - constructor(private readonly reportService: EmailReportService) {} - - @Get('reports') - async getReports() { - return this.reportService.getMetrics(); - } -} diff --git a/src/email/preferences.entity.ts b/src/email/preferences.entity.ts deleted file mode 100644 index e69de29b..00000000 diff --git a/src/email/unsubscribe.controller.ts b/src/email/unsubscribe.controller.ts deleted file mode 100644 index e69de29b..00000000 diff --git a/src/notifications/notification-preferences.entity.ts b/src/notifications/notification-preferences.entity.ts deleted file mode 100644 index e69de29b..00000000 diff --git a/src/notifications/notification-throttle.util.ts b/src/notifications/notification-throttle.util.ts deleted file mode 100644 index 235d0000..00000000 --- a/src/notifications/notification-throttle.util.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { Request } from "express"; -import { PrismaClient } from "@prisma/client"; - -const prisma = new PrismaClient(); - -export async function canSendNotification(userId: string, type: string): Promise { - const prefs = await prisma.notificationPreferences.findUnique({ where: { userId } }); - const now = new Date(); - - // Check cooldown - const last = await prisma.notification.findFirst({ - where: { userId, type }, - orderBy: { createdAt: "desc" }, - }); - if (last && prefs && prefs.cooldownSecs) { - const diff = (now.getTime() - last.createdAt.getTime()) / 1000; - if (diff < prefs.cooldownSecs) return false; - } - - // Check per-hour limit - const count = await prisma.notification.count({ - where: { - userId, - createdAt: { gte: new Date(now.getTime() - 60 * 60 * 1000) }, - }, - }); - if (prefs && count >= prefs.maxPerHour) return false; - - return true; -} diff --git a/src/notifications/notification.controller.ts b/src/notifications/notification.controller.ts deleted file mode 100644 index a80a9c6a..00000000 --- a/src/notifications/notification.controller.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { Controller, Post, Body, Req } from "@nestjs/common"; -import { PrismaService } from "../prisma/prisma.service"; - -@Controller("notifications") -export class NotificationController { - constructor(private readonly prisma: PrismaService) {} - - @Post("preferences") - async updatePreferences(@Req() req, @Body() body) { - return this.prisma.notificationPreferences.upsert({ - where: { userId: req.user.id }, - update: body, - create: { userId: req.user.id, ...body }, - }); - } -} diff --git a/src/notifications/notification.service.ts b/src/notifications/notification.service.ts deleted file mode 100644 index 5ebb4cc4..00000000 --- a/src/notifications/notification.service.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { canSendNotification } from "./notification-throttle.util"; - -async sendNotification(userId: string, type: string, payload: any) { - const allowed = await canSendNotification(userId, type); - if (!allowed) { - // log throttling event - logInfo("Notification throttled", { userId, type }); - return; - } - - // proceed with sending - await this.prisma.notification.create({ - data: { userId, type, payload }, - }); -} diff --git a/src/utils/observability.ts b/src/utils/observability.ts deleted file mode 100644 index e79acfde..00000000 --- a/src/utils/observability.ts +++ /dev/null @@ -1,10 +0,0 @@ -export function logEmailEvent(emailId: string, event: string, correlationId?: string) { - console.log(JSON.stringify({ - level: 'info', - type: 'email', - emailId, - event, - correlationId, - timestamp: new Date().toISOString(), - })); -}