Initial SeConectai briefing system
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
import { notFound, redirect } from "next/navigation";
|
||||
import { auth } from "@/auth";
|
||||
import { db } from "@/lib/db";
|
||||
import { decryptCpf } from "@/lib/crypto";
|
||||
|
||||
export async function getClienteConta() {
|
||||
const session = await auth();
|
||||
|
||||
if (!session?.user?.id || session.user.papel !== "CLIENTE") {
|
||||
redirect("/login");
|
||||
}
|
||||
|
||||
const cliente = await db.cliente.findUnique({
|
||||
where: { userId: session.user.id },
|
||||
include: {
|
||||
user: true,
|
||||
briefings: {
|
||||
include: {
|
||||
respostas: true,
|
||||
anexos: {
|
||||
select: {
|
||||
id: true,
|
||||
nomeOriginal: true,
|
||||
mime: true,
|
||||
tamanho: true,
|
||||
criadoEm: true
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
solicitacoesExclusao: {
|
||||
orderBy: { criadoEm: "desc" }
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (!cliente) {
|
||||
notFound();
|
||||
}
|
||||
|
||||
return cliente;
|
||||
}
|
||||
|
||||
export async function getExportacaoDadosCliente() {
|
||||
const cliente = await getClienteConta();
|
||||
|
||||
return {
|
||||
exportadoEm: new Date().toISOString(),
|
||||
cliente: {
|
||||
id: cliente.id,
|
||||
nomeCompleto: cliente.nomeCompleto,
|
||||
cpf: decryptCpf(cliente.cpfCifrado),
|
||||
whatsapp: cliente.whatsapp,
|
||||
email: cliente.user.email,
|
||||
tipo: cliente.tipo,
|
||||
razaoSocial: cliente.razaoSocial,
|
||||
cnpj: cliente.cnpj,
|
||||
endereco: {
|
||||
cep: cliente.cep,
|
||||
logradouro: cliente.logradouro,
|
||||
numero: cliente.numero,
|
||||
complemento: cliente.complemento,
|
||||
bairro: cliente.bairro,
|
||||
cidade: cliente.cidade,
|
||||
uf: cliente.uf
|
||||
},
|
||||
lgpdAceiteEm: cliente.lgpdAceiteEm
|
||||
},
|
||||
briefings: cliente.briefings.map((briefing) => ({
|
||||
id: briefing.id,
|
||||
titulo: briefing.titulo,
|
||||
status: briefing.status,
|
||||
criadoEm: briefing.criadoEm,
|
||||
atualizadoEm: briefing.atualizadoEm,
|
||||
enviadoEm: briefing.enviadoEm,
|
||||
confirmadoEm: briefing.confirmadoEm,
|
||||
respostas: briefing.respostas.map((resposta) => ({
|
||||
perguntaId: resposta.perguntaId,
|
||||
texto: resposta.texto,
|
||||
complemento: resposta.complemento,
|
||||
selecionadas: resposta.selecionadas,
|
||||
atualizadoEm: resposta.atualizadoEm
|
||||
})),
|
||||
anexos: briefing.anexos
|
||||
})),
|
||||
solicitacoesExclusao: cliente.solicitacoesExclusao
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user