Add self-service teams and assigned post approvals
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { prisma } from "@/lib/db";
|
||||
import { requireUser } from "@/lib/auth/user";
|
||||
|
||||
export async function GET(_req: Request, ctx: { params: Promise<{ id: string }> }) {
|
||||
const { id } = await ctx.params;
|
||||
const auth = await requireUser();
|
||||
if (!auth.ok) return auth.response;
|
||||
const team = await prisma.team.findFirst({
|
||||
where: { id, ...(auth.user.globalRole === "SUPERADMIN" ? {} : { members: { some: { userId: auth.user.id } } }) },
|
||||
select: {
|
||||
id: true, name: true, ownerId: true,
|
||||
members: { select: { userId: true, role: true, user: { select: { name: true, email: true, isActive: true } } }, orderBy: { createdAt: "asc" } },
|
||||
pages: {
|
||||
select: {
|
||||
pageId: true,
|
||||
page: { select: { name: true, pictureUrl: true, members: { select: { userId: true, role: true } } } },
|
||||
},
|
||||
},
|
||||
invites: { where: { status: "PENDING" }, select: { id: true, email: true, expiresAt: true, pageRoles: true }, orderBy: { createdAt: "desc" } },
|
||||
},
|
||||
});
|
||||
if (!team) return NextResponse.json({ error: "ไม่พบทีม" }, { status: 404 });
|
||||
return NextResponse.json({ team });
|
||||
}
|
||||
Reference in New Issue
Block a user