"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const express_1 = require("express"); const DIContainer_1 = require("../../Application/Services/DIContainer"); const Logger_1 = require("../../Application/Services/Logger"); const ContactAggregate_1 = require("../../Domain/Contact/ContactAggregate"); const contactRouter = (0, express_1.Router)(); // Public endpoint - anyone can create a contact contactRouter.post('/', async (req, res) => { try { // Get user ID if authenticated (optional) const userId = req.user?.userId || null; const { name, email, type, txt } = req.body; // Validate required fields if (!name || !email || type === undefined || !txt) { return res.status(400).json({ error: 'Missing required fields: name, email, type, and txt are required' }); } // Validate type if (!Object.values(ContactAggregate_1.ContactType).includes(Number(type))) { return res.status(400).json({ error: 'Invalid contact type. Must be one of: 0 (Bug), 1 (Problem), 2 (Question), 3 (Sales), 4 (Other)' }); } (0, Logger_1.logRequest)('Create contact endpoint accessed', req, res, { name, email, type, userId }); const result = await DIContainer_1.container.createContactCommandHandler.execute({ name, email, userid: userId, type: Number(type), txt }); (0, Logger_1.logRequest)('Contact created successfully', req, res, { contactId: result.id, name, email, type }); res.status(201).json(result); } catch (error) { (0, Logger_1.logError)('Create contact endpoint error', error, req, res); if (error instanceof Error && error.message.includes('validation')) { return res.status(400).json({ error: 'Invalid input data', details: error.message }); } res.status(500).json({ error: 'Internal server error' }); } }); exports.default = contactRouter; //# sourceMappingURL=contactRouter.js.map