Lint errors
Signed-off-by: Rodrigo Martins <rodrigo.sousa.577@gmail.com>
This commit is contained in:
1 parent
1e27604668
commit
ff59d8f090
1 file changed
+22
-64
@@ -28,27 +28,10 @@ router.get("/agendamentos", async (req, res) => {
|
||||
|
||||
if (data) {
|
||||
try {
|
||||
// Validar se o formato da data é válido
|
||||
if (typeof data !== 'string') {
|
||||
return res.status(400).json({
|
||||
error: "Formato de data inválido",
|
||||
details: "O parâmetro 'data' deve ser uma string."
|
||||
});
|
||||
}
|
||||
// Simplificar a validação - aceitar qualquer formato de data válido
|
||||
const parsedDate = new Date(data as string);
|
||||
|
||||
// Verificar se a data está no formato YYYY-MM-DD
|
||||
const dateRegex = /^\d{4}-\d{2}-\d{2}$/;
|
||||
if (!dateRegex.test(data)) {
|
||||
return res.status(400).json({
|
||||
error: "Formato de data inválido",
|
||||
details: "A data deve estar no formato YYYY-MM-DD."
|
||||
});
|
||||
}
|
||||
|
||||
// Criar objeto de data com a data completa (início do dia)
|
||||
const parsedDate = new Date(`${data}T00:00:00.000Z`);
|
||||
|
||||
// Verificar se a data é válida após a conversão
|
||||
// Verificar se a data é válida
|
||||
if (isNaN(parsedDate.getTime())) {
|
||||
return res.status(400).json({
|
||||
error: "Data inválida",
|
||||
@@ -74,16 +57,15 @@ router.get("/agendamentos", async (req, res) => {
|
||||
};
|
||||
} catch (parseError) {
|
||||
console.error("Erro ao analisar data:", parseError);
|
||||
return res.status(400).json({
|
||||
error: "Erro ao processar data",
|
||||
details: "O formato da data fornecida é inválido."
|
||||
});
|
||||
// Continuar sem filtro de data em caso de erro, em vez de falhar
|
||||
console.log("Continuando sem filtro de data devido ao erro");
|
||||
}
|
||||
}
|
||||
|
||||
console.log("Filtro de data:", JSON.stringify(dateFilter));
|
||||
|
||||
const agendamentos = await prisma.agendamento.findMany({
|
||||
// Usando o modelo AgendamentoAtendimento, que corresponde à tabela agendamentos_atendimento
|
||||
const agendamentos = await prisma.agendamentoAtendimento.findMany({
|
||||
where: dateFilter,
|
||||
include: {
|
||||
cliente: {
|
||||
@@ -100,31 +82,6 @@ router.get("/agendamentos", async (req, res) => {
|
||||
|
||||
console.log(`Encontrados ${agendamentos.length} agendamentos`);
|
||||
|
||||
// Log para depuração
|
||||
if (agendamentos.length > 0) {
|
||||
console.log("Primeiro agendamento:", {
|
||||
id: agendamentos[0].id,
|
||||
data: agendamentos[0].data,
|
||||
clienteNome: agendamentos[0].cliente?.nome
|
||||
});
|
||||
} else {
|
||||
// Se não encontrou nenhum, vamos buscar todos os agendamentos sem filtro para depuração
|
||||
const todosAgendamentos = await prisma.agendamento.count();
|
||||
console.log(`Existem ${todosAgendamentos} agendamentos no total no banco de dados`);
|
||||
|
||||
if (todosAgendamentos > 0) {
|
||||
const amostra = await prisma.agendamento.findMany({
|
||||
take: 3,
|
||||
include: { cliente: true }
|
||||
});
|
||||
console.log("Amostra de agendamentos no banco:", amostra.map(a => ({
|
||||
id: a.id,
|
||||
data: a.data,
|
||||
clienteNome: a.cliente?.nome
|
||||
})));
|
||||
}
|
||||
}
|
||||
|
||||
res.json(agendamentos);
|
||||
} catch (error) {
|
||||
console.error("Erro ao listar agendamentos:", error);
|
||||
@@ -151,14 +108,15 @@ router.post("/agendamentos", async (req, res) => {
|
||||
return res.status(404).json({ error: "Cliente não encontrado" });
|
||||
}
|
||||
|
||||
// Criar o agendamento
|
||||
const agendamento = await prisma.agendamento.create({
|
||||
// Criar o agendamento - usando agendamentoAtendimento
|
||||
const agendamento = await prisma.agendamentoAtendimento.create({
|
||||
data: {
|
||||
clienteId,
|
||||
data: new Date(data),
|
||||
observacoes,
|
||||
tipo,
|
||||
status: "AGENDADO"
|
||||
status: "AGENDADO",
|
||||
usuarioId: req.user?.id // Adicionando usuarioId do middleware auth
|
||||
},
|
||||
include: {
|
||||
cliente: {
|
||||
@@ -179,7 +137,7 @@ router.post("/agendamentos", async (req, res) => {
|
||||
res.status(201).json(agendamento);
|
||||
} catch (error) {
|
||||
console.error("Erro ao criar agendamento:", error);
|
||||
res.status(500).json({ error: "Erro ao criar agendamento" });
|
||||
res.status(500).json({ error: "Erro ao criar agendamento", details: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -200,8 +158,8 @@ router.put("/agendamentos/:id", async (req, res) => {
|
||||
|
||||
console.log("Atualizando agendamento:", { id, clienteId, data, observacoes, tipo });
|
||||
|
||||
// Verificar se o agendamento existe
|
||||
const existingAgendamento = await prisma.agendamento.findUnique({
|
||||
// Verificar se o agendamento existe usando a tabela correta
|
||||
const existingAgendamento = await prisma.agendamentoAtendimento.findUnique({
|
||||
where: { id }
|
||||
});
|
||||
|
||||
@@ -209,8 +167,8 @@ router.put("/agendamentos/:id", async (req, res) => {
|
||||
return res.status(404).json({ error: "Agendamento não encontrado" });
|
||||
}
|
||||
|
||||
// Atualizar o agendamento
|
||||
const agendamento = await prisma.agendamento.update({
|
||||
// Atualizar o agendamento usando a tabela correta
|
||||
const agendamento = await prisma.agendamentoAtendimento.update({
|
||||
where: { id },
|
||||
data: {
|
||||
clienteId,
|
||||
@@ -237,7 +195,7 @@ router.put("/agendamentos/:id", async (req, res) => {
|
||||
res.json(agendamento);
|
||||
} catch (error) {
|
||||
console.error("Erro ao atualizar agendamento:", error);
|
||||
res.status(500).json({ error: "Erro ao atualizar agendamento" });
|
||||
res.status(500).json({ error: "Erro ao atualizar agendamento", details: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -256,8 +214,8 @@ router.delete("/agendamentos/:id", async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
// Verificar se o agendamento existe
|
||||
const agendamento = await prisma.agendamento.findUnique({
|
||||
// Verificar se o agendamento existe usando a tabela correta
|
||||
const agendamento = await prisma.agendamentoAtendimento.findUnique({
|
||||
where: { id },
|
||||
include: { cliente: true }
|
||||
});
|
||||
@@ -273,8 +231,8 @@ router.delete("/agendamentos/:id", async (req, res) => {
|
||||
clienteNome: agendamento.cliente?.nome
|
||||
});
|
||||
|
||||
// Excluir o agendamento
|
||||
await prisma.agendamento.delete({
|
||||
// Excluir o agendamento usando a tabela correta
|
||||
await prisma.agendamentoAtendimento.delete({
|
||||
where: { id }
|
||||
});
|
||||
|
||||
@@ -282,7 +240,7 @@ router.delete("/agendamentos/:id", async (req, res) => {
|
||||
res.status(200).json({ message: "Agendamento excluído com sucesso" });
|
||||
} catch (error) {
|
||||
console.error("Erro ao excluir agendamento:", error);
|
||||
res.status(500).json({ error: "Erro ao excluir agendamento" });
|
||||
res.status(500).json({ error: "Erro ao excluir agendamento", details: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user