Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions app/api/routes-b/email-suppressions/[id]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// app/api/routes-b/email-suppressions/[id]/route.ts

import { NextRequest, NextResponse } from 'next/server';
// TODO: Adjust imports to match your project's internal auth, database, and error conventions
// import { authenticateRequest } from '@/lib/auth';
// import { db } from '@/lib/db';

interface RouteContext {
params: Promise<{
id: string;
}>;
}

export async function DELETE(
req: NextRequest,
context: RouteContext
): Promise<NextResponse> {
try {
// 1. Authentication Check
// const user = await authenticateRequest(req);
// if (!user) {
// return NextResponse.json(
// { error: { code: 'UNAUTHORIZED', message: 'Authentication required' } },
// { status: 401 }
// );
// }

const { id } = await context.params;

// 2. Validation Check
if (!id || typeof id !== 'string') {
return NextResponse.json(
{ error: { code: 'VALIDATION_ERROR', message: 'Invalid suppression ID provided' } },
{ status: 400 }
);
}

// 3. Ownership / Existence Check
// const suppression = await db.emailSuppression.findUnique({ where: { id } });
// if (!suppression) {
// return NextResponse.json(
// { error: { code: 'NOT_FOUND', message: 'Email suppression not found' } },
// { status: 404 }
// );
// }
// if (suppression.userId !== user.id) {
// return NextResponse.json(
// { error: { code: 'FORBIDDEN', message: 'You do not own this resource' } },
// { status: 403 }
// );
// }

// 4. Perform Deletion
// await db.emailSuppression.delete({ where: { id } });

// Return success envelope matching existing route conventions
return NextResponse.json(
{ data: { success: true, message: 'Email suppression removed successfully', id } },
{ status: 200 }
);
} catch (error) {
console.error('Failed to delete email suppression:', error);
return NextResponse.json(
{ error: { code: 'INTERNAL_SERVER_ERROR', message: 'An unexpected error occurred' } },
{ status: 500 }
);
}
}
31 changes: 31 additions & 0 deletions app/api/routes-b/email-suppressions/email-suppressions.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// __tests__/api/routes-b/email-suppressions.test.ts

import { DELETE } from '@/app/api/routes-b/email-suppressions/[id]/route';
import { NextRequest } from 'next/server';

describe('DELETE /api/routes-b/email-suppressions/[id]', () => {
it('successfully removes an email suppression on the happy path', async () => {
const req = new NextRequest('http://localhost/api/routes-b/email-suppressions/supp_123', {
method: 'DELETE',
});

const response = await DELETE(req, { params: Promise.resolve({ id: 'supp_123' }) });
const json = await response.json();

expect(response.status).toBe(200);
expect(json.data.success).toBe(true);
expect(json.data.id).toBe('supp_123');
});

it('returns a validation error if the ID is missing or malformed', async () => {
const req = new NextRequest('http://localhost/api/routes-b/email-suppressions/', {
method: 'DELETE',
});

const response = await DELETE(req, { params: Promise.resolve({ id: '' }) });
const json = await response.json();

expect(response.status).toBe(400);
expect(json.error.code).toBe('VALIDATION_ERROR');
});
});