- Add messages table schema with soft delete support - Add message service, controller and routes - Update CORS to allow local network IPs - Update server to listen on 0.0.0.0 - Fix cookie sameSite for local network development Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
46 lines
1.3 KiB
JavaScript
46 lines
1.3 KiB
JavaScript
import express from 'express';
|
|
import * as messageController from '../controllers/message.controller.js';
|
|
import { authenticate } from '../middlewares/auth/authMiddleware.js';
|
|
import { validateBody, validateParams } from '../middlewares/security/validateInput.js';
|
|
import { z } from 'zod';
|
|
|
|
const router = express.Router();
|
|
|
|
// All message routes require authentication
|
|
router.use(authenticate);
|
|
|
|
// Get all conversations
|
|
router.get('/conversations', messageController.getConversations);
|
|
|
|
// Get all CRM users available for chat
|
|
router.get('/users', messageController.getChatUsers);
|
|
|
|
// Get unread message count
|
|
router.get('/unread-count', messageController.getUnreadCount);
|
|
|
|
// Get messages with specific user
|
|
router.get(
|
|
'/conversation/:userId',
|
|
validateParams(z.object({ userId: z.string().uuid() })),
|
|
messageController.getConversation
|
|
);
|
|
|
|
// Send a message
|
|
router.post(
|
|
'/send',
|
|
validateBody(z.object({
|
|
receiverId: z.string().uuid('Neplatný formát user ID'),
|
|
content: z.string().min(1, 'Správa nemôže byť prázdna').max(5000, 'Správa je príliš dlhá'),
|
|
})),
|
|
messageController.sendMessage
|
|
);
|
|
|
|
// Delete conversation
|
|
router.delete(
|
|
'/conversation/:userId',
|
|
validateParams(z.object({ userId: z.string().uuid() })),
|
|
messageController.deleteConversation
|
|
);
|
|
|
|
export default router;
|