Lint errors
Signed-off-by: Rodrigo Martins <rodrigo.sousa.577@gmail.com>
This commit is contained in:
1 parent
ff59d8f090
commit
bdf3729b32
1 file changed
+55
-39
@@ -28,33 +28,32 @@ router.get("/agendamentos", async (req, res) => {
|
|||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
try {
|
try {
|
||||||
// Simplificar a validação - aceitar qualquer formato de data válido
|
// Aceitar e validar o formato da data de forma mais flexível
|
||||||
const parsedDate = new Date(data as string);
|
const parsedDate = new Date(data as string);
|
||||||
|
|
||||||
// Verificar se a data é válida
|
// Verificar se a data é válida
|
||||||
if (isNaN(parsedDate.getTime())) {
|
if (isNaN(parsedDate.getTime())) {
|
||||||
return res.status(400).json({
|
console.error("Data inválida recebida:", data);
|
||||||
error: "Data inválida",
|
// Em vez de retornar erro, continue sem filtro
|
||||||
details: "A data fornecida não pode ser interpretada corretamente."
|
console.log("Continuando sem filtro de data devido a data inválida");
|
||||||
|
} else {
|
||||||
|
console.log("Data parseada:", parsedDate);
|
||||||
|
|
||||||
|
const weekStart = startOfWeek(parsedDate, { locale: ptBR });
|
||||||
|
const weekEnd = endOfWeek(parsedDate, { locale: ptBR });
|
||||||
|
|
||||||
|
console.log("Período de busca:", {
|
||||||
|
weekStart: weekStart.toISOString(),
|
||||||
|
weekEnd: weekEnd.toISOString()
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
console.log("Data parseada:", parsedDate);
|
|
||||||
|
|
||||||
const weekStart = startOfWeek(parsedDate, { locale: ptBR });
|
|
||||||
const weekEnd = endOfWeek(parsedDate, { locale: ptBR });
|
|
||||||
|
|
||||||
console.log("Período de busca:", {
|
|
||||||
weekStart: weekStart.toISOString(),
|
|
||||||
weekEnd: weekEnd.toISOString()
|
|
||||||
});
|
|
||||||
|
|
||||||
dateFilter = {
|
dateFilter = {
|
||||||
data: {
|
data: {
|
||||||
gte: weekStart,
|
gte: weekStart,
|
||||||
lte: weekEnd,
|
lte: weekEnd,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
}
|
||||||
} catch (parseError) {
|
} catch (parseError) {
|
||||||
console.error("Erro ao analisar data:", parseError);
|
console.error("Erro ao analisar data:", parseError);
|
||||||
// Continuar sem filtro de data em caso de erro, em vez de falhar
|
// Continuar sem filtro de data em caso de erro, em vez de falhar
|
||||||
@@ -64,28 +63,45 @@ router.get("/agendamentos", async (req, res) => {
|
|||||||
|
|
||||||
console.log("Filtro de data:", JSON.stringify(dateFilter));
|
console.log("Filtro de data:", JSON.stringify(dateFilter));
|
||||||
|
|
||||||
// Usando o modelo AgendamentoAtendimento, que corresponde à tabela agendamentos_atendimento
|
// Usando o modelo correto e com tratamento de erro adequado
|
||||||
const agendamentos = await prisma.agendamentoAtendimento.findMany({
|
try {
|
||||||
where: dateFilter,
|
const agendamentos = await prisma.agendamentoAtendimento.findMany({
|
||||||
include: {
|
where: dateFilter,
|
||||||
cliente: {
|
include: {
|
||||||
select: {
|
cliente: {
|
||||||
id: true,
|
select: {
|
||||||
nome: true,
|
id: true,
|
||||||
|
nome: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
usuario: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
nome: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
orderBy: {
|
||||||
orderBy: {
|
data: 'asc',
|
||||||
data: 'asc',
|
},
|
||||||
},
|
});
|
||||||
});
|
|
||||||
|
|
||||||
console.log(`Encontrados ${agendamentos.length} agendamentos`);
|
console.log(`Encontrados ${agendamentos.length} agendamentos`);
|
||||||
|
|
||||||
res.json(agendamentos);
|
return res.json(agendamentos);
|
||||||
|
} catch (dbError) {
|
||||||
|
console.error("Erro na consulta do banco de dados:", dbError);
|
||||||
|
return res.status(500).json({
|
||||||
|
error: "Erro ao buscar agendamentos no banco de dados",
|
||||||
|
details: dbError.message
|
||||||
|
});
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Erro ao listar agendamentos:", error);
|
console.error("Erro geral ao listar agendamentos:", error);
|
||||||
res.status(500).json({ error: "Erro ao listar agendamentos" });
|
return res.status(500).json({
|
||||||
|
error: "Erro ao listar agendamentos",
|
||||||
|
details: error.message
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user