- Add event persistence: confirmed events are now saved to MongoDB - Refactor Mongoose models to use virtuals for id field with IdVirtual interface - Update repositories to use toJSON() with consistent type casting - Add more test responses for chat (doctor, birthday, gym, etc.) - Show event description in ProposedEventCard - Change mongo-express port to 8083 - Update CLAUDE.md with Mongoose model pattern documentation
51 lines
1.7 KiB
TypeScript
51 lines
1.7 KiB
TypeScript
import { Response } from 'express';
|
|
import { SendMessageDTO, CreateEventDTO } from '@caldav/shared';
|
|
import { ChatService } from '../services';
|
|
import { AuthenticatedRequest } from '../middleware';
|
|
|
|
export class ChatController {
|
|
constructor(private chatService: ChatService) {}
|
|
|
|
async sendMessage(req: AuthenticatedRequest, res: Response): Promise<void> {
|
|
try {
|
|
const userId = req.user!.userId;
|
|
const data: SendMessageDTO = req.body;
|
|
const response = await this.chatService.processMessage(userId, data);
|
|
res.json(response);
|
|
} catch (error) {
|
|
res.status(500).json({ error: 'Failed to process message' });
|
|
}
|
|
}
|
|
|
|
async confirmEvent(req: AuthenticatedRequest, res: Response): Promise<void> {
|
|
try {
|
|
const userId = req.user!.userId;
|
|
const { conversationId, messageId } = req.params;
|
|
const event: CreateEventDTO = req.body;
|
|
const response = await this.chatService.confirmEvent(userId, conversationId, messageId, event);
|
|
res.json(response);
|
|
} catch (error) {
|
|
res.status(500).json({ error: 'Failed to confirm event' });
|
|
}
|
|
}
|
|
|
|
async rejectEvent(req: AuthenticatedRequest, res: Response): Promise<void> {
|
|
try {
|
|
const userId = req.user!.userId;
|
|
const { conversationId, messageId } = req.params;
|
|
const response = await this.chatService.rejectEvent(userId, conversationId, messageId);
|
|
res.json(response);
|
|
} catch (error) {
|
|
res.status(500).json({ error: 'Failed to reject event' });
|
|
}
|
|
}
|
|
|
|
async getConversations(req: AuthenticatedRequest, res: Response): Promise<void> {
|
|
throw new Error('Not implemented');
|
|
}
|
|
|
|
async getConversation(req: AuthenticatedRequest, res: Response): Promise<void> {
|
|
throw new Error('Not implemented');
|
|
}
|
|
}
|