All files / services/scheduler-service/src index.js

90.9% Statements 30/33
100% Branches 4/4
100% Functions 0/0
90.9% Lines 30/33

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 341x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x 1x 1x     1x 1x 1x  
const express = require('express');
const mongoose = require('mongoose');
const config = require('./config');
const scheduleRoutes = require('./routes/index');
const { runWorker } = require('./temporal/worker');
 
const app = express();
 
app.use(express.json());
 
app.get('/health', (req, res) => {
  res.json({ success: true, message: 'Scheduler Service running', version: '1.0.0' });
});
 
app.use('/:organizationId', scheduleRoutes);
app.use('/', scheduleRoutes);
 
mongoose.connect(config.mongodbUri)
  .then(() => {
    console.log('[Scheduler] Connected to MongoDB');
    app.listen(config.port, '0.0.0.0', () => {
      console.log(`[Scheduler] API running on port ${config.port}`);
    });
    runWorker().catch(err => {
      console.error('[Scheduler] Worker error:', err);
    });
  })
  .catch((err) => {
    console.error('[Scheduler] MongoDB connection error:', err.message);
    process.exit(1);
  });
 
module.exports = app;