Add self-service teams and assigned post approvals

This commit is contained in:
Loma Bot Ops
2026-11-24 11:13:20 +07:00
parent b14a9286cd
commit 55235718c3
31 changed files with 958 additions and 28 deletions
+25
View File
@@ -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 });
}