Lint errors
Signed-off-by: Rodrigo Martins <rodrigo.sousa.577@gmail.com>
This commit is contained in:
1 parent
f993d9ebfc
commit
7a7e5a0ca1
3 files changed
+201
-17
No files matched your search
@@ -24,6 +24,10 @@ interface Agendamento {
|
|||||||
status: string;
|
status: string;
|
||||||
tipo?: string;
|
tipo?: string;
|
||||||
observacoes?: string;
|
observacoes?: string;
|
||||||
|
atendimentoInicial?: {
|
||||||
|
id: string;
|
||||||
|
[key: string]: any;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function AgendamentoCalendario() {
|
export function AgendamentoCalendario() {
|
||||||
@@ -40,9 +44,11 @@ export function AgendamentoCalendario() {
|
|||||||
|
|
||||||
const loadAgendamentos = async (date: Date) => {
|
const loadAgendamentos = async (date: Date) => {
|
||||||
try {
|
try {
|
||||||
const response = await api.get("/agendamentos", {
|
console.log("Buscando agendamentos para a data:", date.toISOString());
|
||||||
|
const response = await api.get("/atendimentos/agendamentos", {
|
||||||
params: { data: date.toISOString() },
|
params: { data: date.toISOString() },
|
||||||
});
|
});
|
||||||
|
console.log("Resposta da API de agendamentos:", response.data);
|
||||||
setAgendamentos(response.data);
|
setAgendamentos(response.data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Erro ao carregar agendamentos:", error);
|
console.error("Erro ao carregar agendamentos:", error);
|
||||||
@@ -112,7 +118,7 @@ export function AgendamentoCalendario() {
|
|||||||
const handleDeleteAgendamento = async (id: string) => {
|
const handleDeleteAgendamento = async (id: string) => {
|
||||||
if (window.confirm("Tem certeza que deseja excluir este agendamento?")) {
|
if (window.confirm("Tem certeza que deseja excluir este agendamento?")) {
|
||||||
try {
|
try {
|
||||||
await api.delete(`/agendamentos/${id}`);
|
await api.delete(`/atendimentos/agendamentos/${id}`);
|
||||||
await loadAgendamentos(selectedDate);
|
await loadAgendamentos(selectedDate);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Erro ao excluir agendamento:", error);
|
console.error("Erro ao excluir agendamento:", error);
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ export function AgendamentoForm({
|
|||||||
setIsSaving(true);
|
setIsSaving(true);
|
||||||
if (agendamento) {
|
if (agendamento) {
|
||||||
// Atualizar agendamento existente
|
// Atualizar agendamento existente
|
||||||
await api.put(`/agendamentos/${agendamento.id}`, {
|
await api.put(`/atendimentos/agendamentos/${agendamento.id}`, {
|
||||||
clienteId,
|
clienteId,
|
||||||
data: data.toISOString(),
|
data: data.toISOString(),
|
||||||
observacoes,
|
observacoes,
|
||||||
@@ -92,7 +92,7 @@ export function AgendamentoForm({
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Criar novo agendamento
|
// Criar novo agendamento
|
||||||
await api.post("/agendamentos", {
|
await api.post("/atendimentos/agendamentos", {
|
||||||
clienteId,
|
clienteId,
|
||||||
data: data.toISOString(),
|
data: data.toISOString(),
|
||||||
observacoes,
|
observacoes,
|
||||||
@@ -102,6 +102,7 @@ export function AgendamentoForm({
|
|||||||
onSave();
|
onSave();
|
||||||
onClose();
|
onClose();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error("Erro ao salvar agendamento:", error);
|
||||||
setError(
|
setError(
|
||||||
agendamento
|
agendamento
|
||||||
? "Erro ao atualizar agendamento"
|
? "Erro ao atualizar agendamento"
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { Router } from "express";
|
import { Router } from "express";
|
||||||
import multer from "multer";
|
import multer from "multer";
|
||||||
import { startOfDay, endOfDay, startOfWeek, endOfWeek, parseISO, addDays } from 'date-fns';
|
import { startOfWeek, endOfWeek, parseISO } from 'date-fns';
|
||||||
|
import { ptBR } from 'date-fns/locale';
|
||||||
|
|
||||||
import { authMiddleware } from "../../middleware/auth";
|
import { authMiddleware } from "../../middleware/auth";
|
||||||
import { NextCloudService } from "../../services/nextcloud";
|
import { NextCloudService } from "../../services/nextcloud";
|
||||||
@@ -11,26 +12,40 @@ const upload = multer({ storage: multer.memoryStorage() });
|
|||||||
|
|
||||||
router.use(authMiddleware);
|
router.use(authMiddleware);
|
||||||
|
|
||||||
// Nova rota para listar agendamentos
|
// Rota para listar agendamentos
|
||||||
router.get("/agendamentos", async (req, res) => {
|
router.get("/agendamentos", async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { data } = req.query;
|
const { data } = req.query;
|
||||||
let dateFilter: any = {};
|
console.log("Requisição de agendamentos recebida, data:", data);
|
||||||
|
|
||||||
|
let dateFilter = {};
|
||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
// Se uma data específica foi fornecida, retorna os agendamentos da semana
|
try {
|
||||||
const parsedDate = parseISO(data as string);
|
const parsedDate = parseISO(data as string);
|
||||||
const weekStart = startOfWeek(parsedDate);
|
console.log("Data parseada:", parsedDate);
|
||||||
const weekEnd = endOfWeek(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) {
|
||||||
|
console.error("Erro ao analisar data:", parseError);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("Filtro de data:", JSON.stringify(dateFilter));
|
||||||
|
|
||||||
const agendamentos = await prisma.agendamento.findMany({
|
const agendamentos = await prisma.agendamento.findMany({
|
||||||
where: dateFilter,
|
where: dateFilter,
|
||||||
include: {
|
include: {
|
||||||
@@ -46,6 +61,33 @@ 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);
|
res.json(agendamentos);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Erro ao listar agendamentos:", error);
|
console.error("Erro ao listar agendamentos:", error);
|
||||||
@@ -53,6 +95,141 @@ router.get("/agendamentos", async (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Rota para criar um novo agendamento
|
||||||
|
router.post("/agendamentos", async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { clienteId, data, observacoes, tipo } = req.body;
|
||||||
|
console.log("Criando agendamento:", { clienteId, data, observacoes, tipo });
|
||||||
|
|
||||||
|
if (!clienteId || !data) {
|
||||||
|
return res.status(400).json({ error: "Cliente e data são obrigatórios" });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verificar se o cliente existe
|
||||||
|
const cliente = await prisma.cliente.findUnique({
|
||||||
|
where: { id: clienteId }
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!cliente) {
|
||||||
|
return res.status(404).json({ error: "Cliente não encontrado" });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Criar o agendamento
|
||||||
|
const agendamento = await prisma.agendamento.create({
|
||||||
|
data: {
|
||||||
|
clienteId,
|
||||||
|
data: new Date(data),
|
||||||
|
observacoes,
|
||||||
|
tipo,
|
||||||
|
status: "AGENDADO"
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
cliente: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
nome: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log("Agendamento criado:", {
|
||||||
|
id: agendamento.id,
|
||||||
|
data: agendamento.data,
|
||||||
|
clienteNome: agendamento.cliente.nome
|
||||||
|
});
|
||||||
|
|
||||||
|
res.status(201).json(agendamento);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Erro ao criar agendamento:", error);
|
||||||
|
res.status(500).json({ error: "Erro ao criar agendamento" });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Rota para atualizar um agendamento
|
||||||
|
router.put("/agendamentos/:id", async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { id } = req.params;
|
||||||
|
const { clienteId, data, observacoes, tipo } = req.body;
|
||||||
|
console.log("Atualizando agendamento:", { id, clienteId, data, observacoes, tipo });
|
||||||
|
|
||||||
|
// Verificar se o agendamento existe
|
||||||
|
const existingAgendamento = await prisma.agendamento.findUnique({
|
||||||
|
where: { id }
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!existingAgendamento) {
|
||||||
|
return res.status(404).json({ error: "Agendamento não encontrado" });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Atualizar o agendamento
|
||||||
|
const agendamento = await prisma.agendamento.update({
|
||||||
|
where: { id },
|
||||||
|
data: {
|
||||||
|
clienteId,
|
||||||
|
data: data ? new Date(data) : undefined,
|
||||||
|
observacoes,
|
||||||
|
tipo
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
cliente: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
nome: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log("Agendamento atualizado:", {
|
||||||
|
id: agendamento.id,
|
||||||
|
data: agendamento.data,
|
||||||
|
clienteNome: agendamento.cliente.nome
|
||||||
|
});
|
||||||
|
|
||||||
|
res.json(agendamento);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Erro ao atualizar agendamento:", error);
|
||||||
|
res.status(500).json({ error: "Erro ao atualizar agendamento" });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Rota para excluir um agendamento
|
||||||
|
router.delete("/agendamentos/:id", async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { id } = req.params;
|
||||||
|
console.log("Excluindo agendamento:", id);
|
||||||
|
|
||||||
|
// Verificar se o agendamento existe
|
||||||
|
const agendamento = await prisma.agendamento.findUnique({
|
||||||
|
where: { id },
|
||||||
|
include: { cliente: true }
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!agendamento) {
|
||||||
|
console.error("Agendamento não encontrado:", id);
|
||||||
|
return res.status(404).json({ error: "Agendamento não encontrado" });
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("Agendamento encontrado:", {
|
||||||
|
id: agendamento.id,
|
||||||
|
data: agendamento.data,
|
||||||
|
clienteNome: agendamento.cliente?.nome
|
||||||
|
});
|
||||||
|
|
||||||
|
// Excluir o agendamento
|
||||||
|
await prisma.agendamento.delete({
|
||||||
|
where: { id }
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log("Agendamento excluído com sucesso");
|
||||||
|
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" });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Rota para atualizar atendimento com anexos
|
// Rota para atualizar atendimento com anexos
|
||||||
router.patch("/:id", async (req, res) => {
|
router.patch("/:id", async (req, res) => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in new issue
Block a user