Base code

This commit is contained in:
azeeee05
2026-07-06 13:16:46 +05:30
commit 3b4d2ae43e
19 changed files with 10823 additions and 0 deletions
+4
View File
@@ -0,0 +1,4 @@
PORT=3001
DATABASE_URL=postgresql://username:password@localhost:5432/dbname
REDIS_URL=redis://localhost:6379
KAFKA_BROKERS=localhost:9092
+41
View File
@@ -0,0 +1,41 @@
# compiled output
/dist
/node_modules
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*
# OS
.DS_Store
# Tests
/coverage
/.nyc_output
# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace
# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
# Environment variables
.env
.env.test
.env.production
.env.local
+4
View File
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "all"
}
+30
View File
@@ -0,0 +1,30 @@
# Aero Resolve - Backend
This is the backend REST API powered by NestJS.
## 🚀 Getting Started
### Prerequisites
- Node.js (v18+)
### Installation
1. Navigate to the backend directory (if you aren't already here):
```bash
cd backend
```
2. Install the dependencies using npm:
```bash
npm install
```
### Development
Start the local development server in watch mode:
```bash
npm run dev
```
### Build for Production
To compile the NestJS application:
```bash
npm run build
```
+35
View File
@@ -0,0 +1,35 @@
// @ts-check
import eslint from '@eslint/js';
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
import globals from 'globals';
import tseslint from 'typescript-eslint';
export default tseslint.config(
{
ignores: ['eslint.config.mjs'],
},
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
eslintPluginPrettierRecommended,
{
languageOptions: {
globals: {
...globals.node,
...globals.jest,
},
sourceType: 'commonjs',
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
},
{
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-floating-promises': 'warn',
'@typescript-eslint/no-unsafe-argument': 'warn',
"prettier/prettier": ["error", { endOfLine: "auto" }],
},
},
);
+8
View File
@@ -0,0 +1,8 @@
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"deleteOutDir": true
}
}
+10344
View File
File diff suppressed because it is too large Load Diff
+76
View File
@@ -0,0 +1,76 @@
{
"name": "@aeroresolve/backend",
"version": "0.0.1",
"description": "AeroResolve NestJS API",
"author": "",
"private": true,
"license": "UNLICENSED",
"scripts": {
"build": "nest build",
"dev": "nest start --watch",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"@nestjs/common": "^11.0.1",
"@nestjs/config": "^4.0.2",
"@nestjs/core": "^11.0.1",
"@nestjs/platform-express": "^11.0.1",
"@nestjs/swagger": "^11.2.0",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.2",
"reflect-metadata": "^0.2.2",
"rxjs": "^7.8.1"
},
"devDependencies": {
"@eslint/eslintrc": "^3.2.0",
"@eslint/js": "^9.18.0",
"@nestjs/cli": "^11.0.0",
"@nestjs/schematics": "^11.0.0",
"@nestjs/testing": "^11.0.1",
"@types/express": "^5.0.0",
"@types/jest": "^30.0.0",
"@types/node": "^24.0.0",
"@types/supertest": "^7.0.0",
"eslint": "^9.18.0",
"eslint-config-prettier": "^10.0.1",
"eslint-plugin-prettier": "^5.2.2",
"globals": "^17.0.0",
"jest": "^30.0.0",
"prettier": "^3.4.2",
"source-map-support": "^0.5.21",
"supertest": "^7.0.0",
"ts-jest": "^29.2.5",
"ts-loader": "^9.5.2",
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.7.3",
"typescript-eslint": "^8.20.0"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}
+13
View File
@@ -0,0 +1,13 @@
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { HealthModule } from './modules/health/health.module';
import { DisruptionModule } from './modules/disruption/disruption.module';
@Module({
imports: [
ConfigModule.forRoot({ isGlobal: true }),
HealthModule,
DisruptionModule,
],
})
export class AppModule {}
+34
View File
@@ -0,0 +1,34 @@
import { NestFactory } from '@nestjs/core';
import { ValidationPipe } from '@nestjs/common';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.enableCors({
origin: ['http://localhost:5174'],
credentials: true,
});
app.useGlobalPipes(
new ValidationPipe({
whitelist: true,
transform: true,
}),
);
const swaggerConfig = new DocumentBuilder()
.setTitle('AeroResolve API')
.setDescription('Passenger recovery and compensation intelligence platform')
.setVersion('0.1.0')
.build();
const document = SwaggerModule.createDocument(app, swaggerConfig);
SwaggerModule.setup('docs', app, document);
const port = process.env.PORT ?? 3001;
await app.listen(port);
}
bootstrap();
@@ -0,0 +1,72 @@
const DEMO_DISRUPTION_ID = 'disruption-ek542';
const baseDisruption: any = {
id: DEMO_DISRUPTION_ID,
tenantId: 'tenant-demo',
flightNumber: 'EK542',
route: { origin: 'DXB', destination: 'CDG' },
scheduledDeparture: '2026-07-02T08:00:00.000Z',
estimatedDeparture: '2026-07-02T12:00:00.000Z',
delayMinutes: 240,
type: 'DELAY',
status: 'AWAITING_APPROVAL',
reason: 'Technical Issue',
aircraftType: 'A380-800',
airlineResponsible: true,
createdAt: '2026-07-02T06:15:00.000Z',
updatedAt: '2026-07-02T06:20:00.000Z',
};
const impactSummary: any = {
totalPassengers: 150,
compensationEligible: 92,
connectionsAtRisk: 25,
estimatedExposure: 36800,
currency: 'EUR',
jurisdiction: 'EU261',
};
const passengerSegments: any[] = [
{ label: 'Premium / Business', count: 18, percentage: 12 },
{ label: 'Frequent Flyers', count: 35, percentage: 23 },
{ label: 'Families', count: 20, percentage: 13 },
{ label: 'Connecting Pax', count: 25, percentage: 17 },
{ label: 'Economy', count: 52, percentage: 35 },
];
const recoveryPlan: any = {
id: 'recovery-ek542',
disruptionId: DEMO_DISRUPTION_ID,
status: 'PENDING_APPROVAL',
actions: [
{ type: 'HOTEL', description: 'Hotel allocation', quantity: 70, estimatedCost: 14000 },
{ type: 'MEAL_VOUCHER', description: 'Meal vouchers', quantity: 150, estimatedCost: 4500 },
{ type: 'REBOOKING', description: 'Next available rebooking', quantity: 25, estimatedCost: 0 },
{ type: 'LOUNGE', description: 'Lounge access', quantity: 18, estimatedCost: 1800 },
{ type: 'GROUND_TRANSPORT', description: 'Ground transport', quantity: 20, estimatedCost: 2200 },
],
estimatedRecoveryCost: 22500,
estimatedExposure: 36800,
potentialSavings: 14300,
currency: 'EUR',
};
export const demoDisruptionDetail: any = {
disruption: baseDisruption,
impact: impactSummary,
segments: passengerSegments,
recoveryPlan,
};
export function cloneDetail(
overrides: Partial<any> = {},
): any {
return {
disruption: { ...demoDisruptionDetail.disruption, ...overrides.disruption },
impact: { ...demoDisruptionDetail.impact, ...overrides.impact },
segments: overrides.segments ?? demoDisruptionDetail.segments,
recoveryPlan: overrides.recoveryPlan
? { ...demoDisruptionDetail.recoveryPlan!, ...overrides.recoveryPlan }
: demoDisruptionDetail.recoveryPlan,
};
}
@@ -0,0 +1,33 @@
import { Controller, Get, Param, Post } from '@nestjs/common';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
import { DisruptionService } from './disruption.service';
@ApiTags('disruptions')
@Controller('disruptions')
export class DisruptionController {
constructor(private readonly disruptionService: DisruptionService) {}
@Get()
@ApiOperation({ summary: 'List active disruptions' })
findAll(): any[] {
return this.disruptionService.findAll();
}
@Get(':id')
@ApiOperation({ summary: 'Get disruption detail with impact and recovery plan' })
findOne(@Param('id') id: string): any {
return this.disruptionService.findOne(id);
}
@Post(':id/approve')
@ApiOperation({ summary: 'Approve recovery plan' })
approve(@Param('id') id: string): any {
return this.disruptionService.approve(id);
}
@Post(':id/reject')
@ApiOperation({ summary: 'Reject recovery plan' })
reject(@Param('id') id: string): any {
return this.disruptionService.reject(id);
}
}
@@ -0,0 +1,10 @@
import { Module } from '@nestjs/common';
import { DisruptionController } from './disruption.controller';
import { DisruptionService } from './disruption.service';
@Module({
controllers: [DisruptionController],
providers: [DisruptionService],
exports: [DisruptionService],
})
export class DisruptionModule {}
@@ -0,0 +1,55 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { cloneDetail, demoDisruptionDetail } from './data/demo-disruption';
@Injectable()
export class DisruptionService {
private readonly store = new Map<string, any>([
[demoDisruptionDetail.disruption.id, cloneDetail()],
]);
findAll(): any[] {
return Array.from(this.store.values()).map((item) => item.disruption);
}
findOne(id: string): any {
const detail = this.store.get(id);
if (!detail) {
throw new NotFoundException(`Disruption ${id} not found`);
}
return cloneDetail(detail);
}
approve(id: string): any {
const current = this.findOne(id);
const updated = cloneDetail({
disruption: {
...current.disruption,
status: 'COMPLETED',
updatedAt: new Date().toISOString(),
},
recoveryPlan: {
...current.recoveryPlan!,
status: 'COMPLETED',
},
});
this.store.set(id, updated);
return cloneDetail(updated);
}
reject(id: string): any {
const current = this.findOne(id);
const updated = cloneDetail({
disruption: {
...current.disruption,
status: 'REJECTED',
updatedAt: new Date().toISOString(),
},
recoveryPlan: {
...current.recoveryPlan!,
status: 'REJECTED',
},
});
this.store.set(id, updated);
return cloneDetail(updated);
}
}
+14
View File
@@ -0,0 +1,14 @@
import { Controller, Get } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { HealthService } from './health.service';
@ApiTags('health')
@Controller('health')
export class HealthController {
constructor(private readonly healthService: HealthService) {}
@Get()
getHealth(): any {
return this.healthService.getHealth();
}
}
+9
View File
@@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { HealthController } from './health.controller';
import { HealthService } from './health.service';
@Module({
controllers: [HealthController],
providers: [HealthService],
})
export class HealthModule {}
+12
View File
@@ -0,0 +1,12 @@
import { Injectable } from '@nestjs/common';
@Injectable()
export class HealthService {
getHealth(): any {
return {
status: 'ok',
service: 'aeroresol-api',
timestamp: new Date().toISOString(),
};
}
}
+4
View File
@@ -0,0 +1,4 @@
{
"extends": "./tsconfig.json",
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
}
+25
View File
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"module": "nodenext",
"moduleResolution": "nodenext",
"resolvePackageJsonExports": true,
"esModuleInterop": true,
"isolatedModules": true,
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "ES2023",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true,
"skipLibCheck": true,
"strictNullChecks": true,
"forceConsistentCasingInFileNames": true,
"noImplicitAny": true,
"strictBindCallApply": true,
"noFallthroughCasesInSwitch": true
}
}