Files
cmdb-insight/backend/src/routes/referenceData.ts
Bert Hausmans 1fa424efb9 Add authentication, user management, and database migration features
- Implement OAuth 2.0 and PAT authentication methods
- Add user management, roles, and profile functionality
- Add database migrations and admin user scripts
- Update services for authentication and user settings
- Add protected routes and permission hooks
- Update documentation for authentication and database access
2026-01-15 03:20:50 +01:00

225 lines
7.0 KiB
TypeScript

import { Router, Request, Response } from 'express';
import { dataService } from '../services/dataService.js';
import { logger } from '../services/logger.js';
import { requireAuth } from '../middleware/authorization.js';
const router = Router();
// All routes require authentication
router.use(requireAuth);
// Get all reference data
router.get('/', async (req: Request, res: Response) => {
try {
const [
dynamicsFactors,
complexityFactors,
numberOfUsers,
governanceModels,
organisations,
hostingTypes,
applicationFunctions,
applicationSubteams,
applicationTeams,
applicationTypes,
businessImportance,
businessImpactAnalyses,
applicationManagementHosting,
applicationManagementTAM,
subteamToTeamMapping,
] = await Promise.all([
dataService.getDynamicsFactors(),
dataService.getComplexityFactors(),
dataService.getNumberOfUsers(),
dataService.getGovernanceModels(),
dataService.getOrganisations(),
dataService.getHostingTypes(),
dataService.getApplicationFunctions(),
dataService.getApplicationSubteams(),
dataService.getApplicationTeams(),
dataService.getApplicationTypes(),
dataService.getBusinessImportance(),
dataService.getBusinessImpactAnalyses(),
dataService.getApplicationManagementHosting(),
dataService.getApplicationManagementTAM(),
dataService.getSubteamToTeamMapping(),
]);
res.json({
dynamicsFactors,
complexityFactors,
numberOfUsers,
governanceModels,
organisations,
hostingTypes,
applicationFunctions,
applicationSubteams,
applicationTeams,
applicationTypes,
businessImportance,
businessImpactAnalyses,
applicationManagementHosting,
applicationManagementTAM,
subteamToTeamMapping,
});
} catch (error) {
logger.error('Failed to get reference data', error);
res.status(500).json({ error: 'Failed to get reference data' });
}
});
// Get dynamics factors
router.get('/dynamics-factors', async (req: Request, res: Response) => {
try {
const factors = await dataService.getDynamicsFactors();
res.json(factors);
} catch (error) {
logger.error('Failed to get dynamics factors', error);
res.status(500).json({ error: 'Failed to get dynamics factors' });
}
});
// Get complexity factors
router.get('/complexity-factors', async (req: Request, res: Response) => {
try {
const factors = await dataService.getComplexityFactors();
res.json(factors);
} catch (error) {
logger.error('Failed to get complexity factors', error);
res.status(500).json({ error: 'Failed to get complexity factors' });
}
});
// Get number of users options
router.get('/number-of-users', async (req: Request, res: Response) => {
try {
const options = await dataService.getNumberOfUsers();
res.json(options);
} catch (error) {
logger.error('Failed to get number of users', error);
res.status(500).json({ error: 'Failed to get number of users' });
}
});
// Get governance models
router.get('/governance-models', async (req: Request, res: Response) => {
try {
const models = await dataService.getGovernanceModels();
res.json(models);
} catch (error) {
logger.error('Failed to get governance models', error);
res.status(500).json({ error: 'Failed to get governance models' });
}
});
// Get organisations
router.get('/organisations', async (req: Request, res: Response) => {
try {
const orgs = await dataService.getOrganisations();
res.json(orgs);
} catch (error) {
logger.error('Failed to get organisations', error);
res.status(500).json({ error: 'Failed to get organisations' });
}
});
// Get hosting types
router.get('/hosting-types', async (req: Request, res: Response) => {
try {
const types = await dataService.getHostingTypes();
res.json(types);
} catch (error) {
logger.error('Failed to get hosting types', error);
res.status(500).json({ error: 'Failed to get hosting types' });
}
});
// Get application functions (from Jira Assets)
router.get('/application-functions', async (req: Request, res: Response) => {
try {
const functions = await dataService.getApplicationFunctions();
res.json(functions);
} catch (error) {
logger.error('Failed to get application functions', error);
res.status(500).json({ error: 'Failed to get application functions' });
}
});
// Get application subteams (from Jira Assets)
router.get('/application-subteams', async (req: Request, res: Response) => {
try {
const subteams = await dataService.getApplicationSubteams();
res.json(subteams);
} catch (error) {
logger.error('Failed to get application subteams', error);
res.status(500).json({ error: 'Failed to get application subteams' });
}
});
// Get application teams (from Jira Assets)
router.get('/application-teams', async (req: Request, res: Response) => {
try {
const teams = await dataService.getApplicationTeams();
res.json(teams);
} catch (error) {
logger.error('Failed to get application teams', error);
res.status(500).json({ error: 'Failed to get application teams' });
}
});
// Get application types (from Jira Assets)
router.get('/application-types', async (req: Request, res: Response) => {
try {
const types = await dataService.getApplicationTypes();
res.json(types);
} catch (error) {
logger.error('Failed to get application types', error);
res.status(500).json({ error: 'Failed to get application types' });
}
});
router.get('/business-importance', async (req: Request, res: Response) => {
try {
const importance = await dataService.getBusinessImportance();
res.json(importance);
} catch (error) {
logger.error('Failed to get business importance', error);
res.status(500).json({ error: 'Failed to get business importance' });
}
});
// Get business impact analyses
router.get('/business-impact-analyses', async (req: Request, res: Response) => {
try {
const analyses = await dataService.getBusinessImpactAnalyses();
res.json(analyses);
} catch (error) {
logger.error('Failed to get business impact analyses', error);
res.status(500).json({ error: 'Failed to get business impact analyses' });
}
});
// Get application management hosting
router.get('/application-management-hosting', async (req: Request, res: Response) => {
try {
const hosting = await dataService.getApplicationManagementHosting();
res.json(hosting);
} catch (error) {
logger.error('Failed to get application management hosting', error);
res.status(500).json({ error: 'Failed to get application management hosting' });
}
});
// Get application management TAM
router.get('/application-management-tam', async (req: Request, res: Response) => {
try {
const tam = await dataService.getApplicationManagementTAM();
res.json(tam);
} catch (error) {
logger.error('Failed to get application management TAM', error);
res.status(500).json({ error: 'Failed to get application management TAM' });
}
});
export default router;