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
|
// Rotas de Agendamento
|
||||||
app.get("/api/agendamentos", async (req, res) => {
|
app.get("/api/atendimentos/agendamentos", async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { data } = req.query;
|
const { data } = req.query;
|
||||||
const where = data
|
console.log("Requisição de agendamentos recebida, data:", data);
|
||||||
? {
|
|
||||||
data: {
|
let where = {};
|
||||||
gte: new Date(data as string),
|
|
||||||
lt: new Date(
|
if (data) {
|
||||||
new Date(data as string).setDate(
|
try {
|
||||||
new Date(data as string).getDate() + 1,
|
// 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({
|
const agendamentos = await prisma.agendamentoAtendimento.findMany({
|
||||||
where,
|
where,
|
||||||
include: {
|
include: {
|
||||||
cliente: true,
|
cliente: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
nome: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
usuario: {
|
usuario: {
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
@@ -1265,6 +1293,8 @@ app.get("/api/agendamentos", async (req, res) => {
|
|||||||
data: "asc",
|
data: "asc",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log(`Encontrados ${agendamentos.length} agendamentos`);
|
||||||
res.json(agendamentos);
|
res.json(agendamentos);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Erro ao buscar agendamentos:", error);
|
console.error("Erro ao buscar agendamentos:", error);
|
||||||
|
|||||||
Reference in new issue
Block a user