Implement database migration, notification logs, and one-click Mailcow setup
This commit is contained in:
23
app/api/mappings/[id]/route.ts
Normal file
23
app/api/mappings/[id]/route.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { auth } from "@/auth";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
// DELETE /api/mappings/[id] — delete a mapping
|
||||
export async function DELETE(req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
||||
const session = await auth();
|
||||
const { id } = await params;
|
||||
|
||||
if (!session || session.user.role !== "SUPER_ADMIN") {
|
||||
return NextResponse.json({ error: "Forbidden" }, { status: 403 });
|
||||
}
|
||||
|
||||
try {
|
||||
await prisma.mailboxMapping.delete({
|
||||
where: { id },
|
||||
});
|
||||
|
||||
return NextResponse.json({ status: "ok" });
|
||||
} catch (error: any) {
|
||||
return NextResponse.json({ error: error.message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
43
app/api/mappings/route.ts
Normal file
43
app/api/mappings/route.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { auth } from "@/auth";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
// GET /api/mappings — list all mappings
|
||||
export async function GET() {
|
||||
const session = await auth();
|
||||
if (!session || session.user.role !== "SUPER_ADMIN") {
|
||||
return NextResponse.json({ error: "Forbidden" }, { status: 403 });
|
||||
}
|
||||
|
||||
const mappings = await prisma.mailboxMapping.findMany({
|
||||
include: { user: true },
|
||||
orderBy: { createdAt: "desc" },
|
||||
});
|
||||
|
||||
return NextResponse.json(mappings);
|
||||
}
|
||||
|
||||
// POST /api/mappings — create a new mapping
|
||||
export async function POST(req: NextRequest) {
|
||||
const session = await auth();
|
||||
if (!session || session.user.role !== "SUPER_ADMIN") {
|
||||
return NextResponse.json({ error: "Forbidden" }, { status: 403 });
|
||||
}
|
||||
|
||||
try {
|
||||
const body = await req.json();
|
||||
const { email, userId } = body;
|
||||
|
||||
const mapping = await prisma.mailboxMapping.create({
|
||||
data: {
|
||||
email: email.toLowerCase().trim(),
|
||||
userId,
|
||||
},
|
||||
include: { user: true },
|
||||
});
|
||||
|
||||
return NextResponse.json(mapping);
|
||||
} catch (error: any) {
|
||||
return NextResponse.json({ error: error.message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user