Initial SeConectai briefing system
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
import { notFound } from "next/navigation";
|
||||
import { auth } from "@/auth";
|
||||
import { db } from "@/lib/db";
|
||||
|
||||
export async function getAnexoAutorizado(anexoId: string) {
|
||||
const session = await auth();
|
||||
|
||||
if (!session?.user?.id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const anexo = await db.anexo.findUnique({
|
||||
where: { id: anexoId },
|
||||
include: {
|
||||
briefing: {
|
||||
include: {
|
||||
cliente: true
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (!anexo) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (session.user.papel === "ADMIN") {
|
||||
return anexo;
|
||||
}
|
||||
|
||||
if (session.user.papel === "CLIENTE" && anexo.briefing.cliente.userId === session.user.id) {
|
||||
return anexo;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export async function getBriefingPerguntaParaUpload(briefingId: string, perguntaId: string) {
|
||||
const session = await auth();
|
||||
|
||||
if (!session?.user?.id || session.user.papel !== "CLIENTE") {
|
||||
notFound();
|
||||
}
|
||||
|
||||
const briefing = await db.briefing.findFirst({
|
||||
where: {
|
||||
id: briefingId,
|
||||
cliente: {
|
||||
userId: session.user.id
|
||||
}
|
||||
},
|
||||
include: {
|
||||
cliente: true
|
||||
}
|
||||
});
|
||||
|
||||
if (!briefing) {
|
||||
notFound();
|
||||
}
|
||||
|
||||
const pergunta = await db.pergunta.findFirst({
|
||||
where: {
|
||||
id: perguntaId,
|
||||
tipo: "ANEXO",
|
||||
ativo: true
|
||||
},
|
||||
select: { id: true }
|
||||
});
|
||||
|
||||
if (!pergunta) {
|
||||
notFound();
|
||||
}
|
||||
|
||||
return { briefing, pergunta };
|
||||
}
|
||||
Reference in New Issue
Block a user