diff --git a/src/email/email-report.entity.ts b/src/email/email-report.entity.ts deleted file mode 100644 index e69de29..0000000 diff --git a/src/email/email-report.service.ts b/src/email/email-report.service.ts deleted file mode 100644 index a5e0fc0..0000000 --- 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 e69de29..0000000 diff --git a/src/email/email.controller.ts b/src/email/email.controller.ts deleted file mode 100644 index 4589855..0000000 --- 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 e69de29..0000000 diff --git a/src/email/unsubscribe.controller.ts b/src/email/unsubscribe.controller.ts deleted file mode 100644 index e69de29..0000000 diff --git a/src/notifications/notification-preferences.entity.ts b/src/notifications/notification-preferences.entity.ts deleted file mode 100644 index e69de29..0000000 diff --git a/src/notifications/notification-throttle.util.ts b/src/notifications/notification-throttle.util.ts deleted file mode 100644 index 235d000..0000000 --- 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 a80a9c6..0000000 --- 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 5ebb4cc..0000000 --- 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 e79acfd..0000000 --- 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(), - })); -}