57 lines
1.3 KiB
TypeScript
Raw Permalink Normal View History

2023-10-15 18:12:54 -07:00
import { currentProfile } from "@/lib/current-profile";
import { db } from "@/lib/db";
import { NextResponse } from "next/server";
export async function PATCH(req: Request, {params}: {params: {serverId: string}})
{
try
{
const profile = await currentProfile();
if (!profile)
{
return new NextResponse("Unauthorized", { status: 401 });
}
if (!params.serverId)
{
return new NextResponse("Server ID Missing", { status: 400 });
}
const server = await db.server.update
({
where:
{
id: params.serverId,
profileId:
{
not: profile.id
},
members:
{
some:
{
profileId: profile.id,
}
},
},
data:
{
members:
{
deleteMany:
{
profileId: profile.id
}
}
}
})
return NextResponse.json(server);
}
catch (error)
{
console.log("[SERVER_ID_LEAVE]", error);
return new NextResponse("Internal Error", { status: 500});
}
}