Add self-service teams and assigned post approvals
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { prisma } from "@/lib/db";
|
||||
import { requireUser } from "@/lib/auth/user";
|
||||
|
||||
export async function requireTeamManager(teamId: string) {
|
||||
const auth = await requireUser();
|
||||
if (!auth.ok) return auth;
|
||||
const member = await prisma.teamMember.findUnique({
|
||||
where: { teamId_userId: { teamId, userId: auth.user.id } },
|
||||
select: { role: true },
|
||||
});
|
||||
if (auth.user.globalRole !== "SUPERADMIN" && member?.role !== "OWNER" && member?.role !== "ADMIN") {
|
||||
return { ok: false as const, response: NextResponse.json({ error: "ไม่มีสิทธิ์จัดการทีมนี้" }, { status: 404 }) };
|
||||
}
|
||||
const team = await prisma.team.findUnique({ where: { id: teamId }, select: { id: true, ownerId: true } });
|
||||
if (!team) return { ok: false as const, response: NextResponse.json({ error: "ไม่พบทีม" }, { status: 404 }) };
|
||||
return { ok: true as const, user: auth.user, team, member };
|
||||
}
|
||||
Reference in New Issue
Block a user