first commit
This commit is contained in:
commit
c9fb67e751
423 files changed
+53287
No files matched your search
@@ -0,0 +1,113 @@
|
||||
import { Router } from 'express';
|
||||
import { prisma } from '../prismaClient';
|
||||
import { authMiddleware } from '../../middleware/auth';
|
||||
import multer from 'multer';
|
||||
import { NextCloudService } from '../../services/nextcloud';
|
||||
|
||||
const router = Router();
|
||||
const upload = multer({ storage: multer.memoryStorage() });
|
||||
|
||||
router.use(authMiddleware);
|
||||
|
||||
// ...existing routes...
|
||||
|
||||
// Rota para atualizar atendimento com anexos
|
||||
router.patch('/:id', async (req, res) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const { anexos, ...data } = req.body;
|
||||
|
||||
console.log('Atualizando atendimento:', id, { anexos, data }); // Debug log
|
||||
|
||||
const atendimento = await prisma.atendimento.update({
|
||||
where: { id },
|
||||
data: {
|
||||
...data,
|
||||
...(anexos && {
|
||||
anexos: {
|
||||
createMany: {
|
||||
data: anexos.map((anexo: any) => ({
|
||||
nome: anexo.nome,
|
||||
url: anexo.url,
|
||||
tipo: anexo.tipo,
|
||||
tamanho: anexo.tamanho
|
||||
}))
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
include: {
|
||||
anexos: true,
|
||||
cliente: true
|
||||
}
|
||||
});
|
||||
|
||||
console.log('Atendimento atualizado:', atendimento); // Debug log
|
||||
res.json(atendimento);
|
||||
} catch (error) {
|
||||
console.error('Erro ao atualizar atendimento:', error);
|
||||
res.status(500).json({ error: 'Erro ao atualizar atendimento' });
|
||||
}
|
||||
});
|
||||
|
||||
// Nova rota para upload de arquivo via proxy
|
||||
router.post('/upload', upload.single('file'), async (req, res) => {
|
||||
try {
|
||||
if (!req.file || !req.body.clienteNome) {
|
||||
return res.status(400).json({ error: 'Arquivo e nome do cliente são obrigatórios' });
|
||||
}
|
||||
|
||||
// Enviar para o NextCloud usando a estrutura de pastas correta
|
||||
const buffer = req.file.buffer;
|
||||
Object.defineProperty(buffer, 'name', {
|
||||
value: req.file.originalname,
|
||||
writable: true,
|
||||
enumerable: true
|
||||
});
|
||||
|
||||
const filePath = await NextCloudService.uploadFile(
|
||||
buffer,
|
||||
req.body.clienteNome,
|
||||
'atendimento',
|
||||
req.body.protocolo
|
||||
);
|
||||
|
||||
res.json({ url: filePath });
|
||||
} catch (error) {
|
||||
console.error('Erro no upload:', error);
|
||||
res.status(500).json({ error: 'Erro no upload do arquivo' });
|
||||
}
|
||||
});
|
||||
|
||||
router.get('/:id', async (req, res) => {
|
||||
try {
|
||||
const atendimento = await prisma.atendimento.findUnique({
|
||||
where: {
|
||||
id: req.params.id
|
||||
},
|
||||
include: {
|
||||
cliente: true,
|
||||
processo: true,
|
||||
usuario: {
|
||||
select: {
|
||||
id: true,
|
||||
nome: true,
|
||||
oab: true,
|
||||
oabUF: true
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (!atendimento) {
|
||||
return res.status(404).json({ error: 'Atendimento não encontrado' });
|
||||
}
|
||||
|
||||
res.json(atendimento);
|
||||
} catch (error) {
|
||||
console.error('Erro ao buscar atendimento:', error);
|
||||
res.status(500).json({ error: 'Erro ao buscar atendimento' });
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
Reference in new issue
Block a user