Lint errors
Signed-off-by: Rodrigo Martins <rodrigo.sousa.577@gmail.com>
This commit is contained in:
1 parent
bdf3729b32
commit
76aa2eb9eb
1 file changed
+43
-13
+43
-13
@@ -1227,26 +1227,54 @@ app.get("/api/atendimentos/:id", async (req, res) => {
|
||||
});
|
||||
|
||||
// Rotas de Agendamento
|
||||
app.get("/api/agendamentos", async (req, res) => {
|
||||
app.get("/api/atendimentos/agendamentos", async (req, res) => {
|
||||
try {
|
||||
const { data } = req.query;
|
||||
const where = data
|
||||
? {
|
||||
data: {
|
||||
gte: new Date(data as string),
|
||||
lt: new Date(
|
||||
new Date(data as string).setDate(
|
||||
new Date(data as string).getDate() + 1,
|
||||
),
|
||||
),
|
||||
},
|
||||
console.log("Requisição de agendamentos recebida, data:", data);
|
||||
|
||||
let where = {};
|
||||
|
||||
if (data) {
|
||||
try {
|
||||
// Criar uma data a partir do parâmetro recebido
|
||||
const parsedDate = new Date(data as string);
|
||||
|
||||
if (!isNaN(parsedDate.getTime())) {
|
||||
// Se a data for válida, criar o filtro para a semana
|
||||
const weekStart = startOfWeek(parsedDate, { locale: ptBR });
|
||||
const weekEnd = endOfWeek(parsedDate, { locale: ptBR });
|
||||
|
||||
console.log("Período de busca:", {
|
||||
weekStart: weekStart.toISOString(),
|
||||
weekEnd: weekEnd.toISOString()
|
||||
});
|
||||
|
||||
where = {
|
||||
data: {
|
||||
gte: weekStart,
|
||||
lte: weekEnd,
|
||||
},
|
||||
};
|
||||
} else {
|
||||
console.log("Data inválida fornecida, buscando todos os agendamentos");
|
||||
}
|
||||
: {};
|
||||
} catch (error) {
|
||||
console.error("Erro ao processar data:", error);
|
||||
// Continuar sem filtro em caso de erro
|
||||
}
|
||||
}
|
||||
|
||||
console.log("Filtro final:", where);
|
||||
|
||||
const agendamentos = await prisma.agendamentoAtendimento.findMany({
|
||||
where,
|
||||
include: {
|
||||
cliente: true,
|
||||
cliente: {
|
||||
select: {
|
||||
id: true,
|
||||
nome: true,
|
||||
},
|
||||
},
|
||||
usuario: {
|
||||
select: {
|
||||
id: true,
|
||||
@@ -1265,6 +1293,8 @@ app.get("/api/agendamentos", async (req, res) => {
|
||||
data: "asc",
|
||||
},
|
||||
});
|
||||
|
||||
console.log(`Encontrados ${agendamentos.length} agendamentos`);
|
||||
res.json(agendamentos);
|
||||
} catch (error) {
|
||||
console.error("Erro ao buscar agendamentos:", error);
|
||||
|
||||
Reference in new issue
Block a user