[PROP-CORE-004] feat: Register payment-terminals module with TypeORM setup

- Added TypeORM DataSource configuration
- Added payment-terminals entities
- Added PaymentTerminalsModule with bootstrap function
- Registered routes: /api/payment-terminals, /api/mercadopago, /api/clip
- Registered webhooks: /webhooks/mercadopago, /webhooks/clip
- Updated API info with available endpoints

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Adrian Flores Cortes 2026-01-25 03:14:01 -06:00
parent b5dbe9db5f
commit e19c4b15c5

View File

@ -19,12 +19,38 @@ import express from 'express';
import cors from 'cors';
import helmet from 'helmet';
import dotenv from 'dotenv';
import { DataSource } from 'typeorm';
// Payment Terminals Module
import { PaymentTerminalsModule } from './modules/payment-terminals';
import { TenantTerminalConfig } from './modules/payment-terminals/entities/tenant-terminal-config.entity';
import { TerminalPayment } from './modules/payment-terminals/entities/terminal-payment.entity';
import { TerminalWebhookEvent } from './modules/payment-terminals/entities/terminal-webhook-event.entity';
dotenv.config();
const app = express();
const PORT = process.env.PORT || 3000;
// Database configuration
const AppDataSource = new DataSource({
type: 'postgres',
host: process.env.DB_HOST || 'localhost',
port: parseInt(process.env.DB_PORT || '5432', 10),
username: process.env.DB_USER || 'erp_user',
password: process.env.DB_PASSWORD || 'erp_dev_2026',
database: process.env.DB_NAME || 'erp_vidrio_templado',
schema: process.env.DB_SCHEMA || 'public',
entities: [
// Payment Terminals
TenantTerminalConfig,
TerminalPayment,
TerminalWebhookEvent,
],
synchronize: process.env.NODE_ENV === 'development',
logging: process.env.NODE_ENV === 'development',
});
// Middleware
app.use(helmet());
app.use(cors());
@ -37,6 +63,7 @@ app.get('/health', (req, res) => {
service: 'erp-vidrio-templado-backend',
version: '0.1.0',
timestamp: new Date().toISOString(),
database: AppDataSource.isInitialized ? 'connected' : 'disconnected',
});
});
@ -55,16 +82,61 @@ app.get('/api', (req, res) => {
'VT-006: Templado',
'VT-007: Calidad',
'VT-008: Despacho',
'Payment Terminals (MercadoPago, Clip)',
],
endpoints: {
health: '/health',
paymentTerminals: '/api/payment-terminals',
mercadopago: '/api/mercadopago',
clip: '/api/clip',
},
status: 'scaffold - en desarrollo',
});
});
// Start server
if (require.main === module) {
app.listen(PORT, () => {
console.log(`ERP Vidrio Templado backend running on port ${PORT}`);
});
// Bootstrap function
async function bootstrap() {
try {
// Initialize database
await AppDataSource.initialize();
console.log('📦 Database connection established');
// Initialize Payment Terminals Module
const paymentTerminals = new PaymentTerminalsModule({ dataSource: AppDataSource });
app.use('/api', paymentTerminals.router);
app.use('/webhooks', paymentTerminals.webhookRouter);
console.log('💳 Payment Terminals module initialized');
// 404 handler
app.use((req, res) => {
res.status(404).json({ error: 'Not Found' });
});
// Error handler
app.use((err: Error, _req: express.Request, res: express.Response, _next: express.NextFunction) => {
console.error(err.stack);
res.status(500).json({
error: 'Internal Server Error',
message: process.env.NODE_ENV === 'development' ? err.message : undefined,
});
});
// Start server
app.listen(PORT, () => {
console.log(`🔷 ERP Vidrio Templado backend running on port ${PORT}`);
console.log(`📊 Environment: ${process.env.NODE_ENV || 'development'}`);
console.log(`🏥 Health check: http://localhost:${PORT}/health`);
console.log(`📚 API Root: http://localhost:${PORT}/api`);
});
} catch (error) {
console.error('Failed to start server:', error);
process.exit(1);
}
}
export default app;
// Start application
if (require.main === module) {
bootstrap();
}
export { app, AppDataSource };