54 lines
2.1 KiB
TypeScript
54 lines
2.1 KiB
TypeScript
import { Body, Controller, Get, Post, Query } from "@nestjs/common";
|
|
import { ApiOperation, ApiResponse } from "@nestjs/swagger";
|
|
|
|
import { EmailSpamService } from "./services/email-spam.service";
|
|
import { AdminRoute } from "../../common/decorators/admin.decorator";
|
|
|
|
@Controller("email-blocking")
|
|
export class EmailBlockingController {
|
|
constructor(private readonly emailSpamService: EmailSpamService) {}
|
|
|
|
@Get("diagnose")
|
|
@AdminRoute()
|
|
@ApiOperation({
|
|
summary: "Diagnose email blocking issues (Admin only)",
|
|
description: "Check if a sender domain is blocked for a recipient and optionally unblock it",
|
|
})
|
|
@ApiResponse({ status: 200, description: "Diagnostic information" })
|
|
@ApiResponse({ status: 400, description: "Invalid parameters" })
|
|
@ApiResponse({ status: 403, description: "Not authorized (Admin only)" })
|
|
async diagnoseEmailBlocking(
|
|
@Query("recipient") recipientEmail: string,
|
|
@Query("senderDomain") senderDomain: string,
|
|
@Query("unblock") unblock?: string,
|
|
) {
|
|
if (!recipientEmail || !senderDomain) {
|
|
throw new Error("Both recipient and senderDomain query parameters are required");
|
|
}
|
|
const shouldUnblock = unblock === "true" || unblock === "1";
|
|
return this.emailSpamService.diagnoseEmailBlocking(recipientEmail, senderDomain, shouldUnblock);
|
|
}
|
|
|
|
@Post("allowlist")
|
|
@AdminRoute()
|
|
@ApiOperation({
|
|
summary: "Add domain to allowlist (Admin only)",
|
|
description: "Add a sender domain to the allowlist for a recipient's business",
|
|
})
|
|
@ApiResponse({ status: 200, description: "Domain added to allowlist" })
|
|
@ApiResponse({ status: 400, description: "Invalid parameters" })
|
|
@ApiResponse({ status: 403, description: "Not authorized (Admin only)" })
|
|
async addToAllowlist(
|
|
@Body() body: { recipientEmail: string; senderDomain: string; description?: string },
|
|
) {
|
|
if (!body.recipientEmail || !body.senderDomain) {
|
|
throw new Error("Both recipientEmail and senderDomain are required");
|
|
}
|
|
return this.emailSpamService.addDomainToAllowlistForUser(
|
|
body.recipientEmail,
|
|
body.senderDomain,
|
|
body.description,
|
|
);
|
|
}
|
|
}
|