recovery incidents

This commit is contained in:
azeeee05
2026-08-03 14:26:19 +05:30
parent a8c8b11ba5
commit 86f435500a
8 changed files with 239 additions and 19 deletions
+20 -19
View File
@@ -1,15 +1,16 @@
# AeroResolve Backend # AeroResolve Backend
test12345
test1
NestJS REST API for AeroResolve. NestJS REST API for AeroResolve.
## Current Modules ## Current Modules
| Module | Status | Description | | Module | Status | Description |
|--------|--------|-------------| | ------------- | ----------- | ---------------------------------------- |
| `health` | Implemented | Health check | | `health` | Implemented | Health check |
| `database` | Implemented | PostgreSQL / TypeORM setup | | `database` | Implemented | PostgreSQL / TypeORM setup |
| `master-data` | Implemented | CRUD and seed data for lookup categories | | `master-data` | Implemented | CRUD and seed data for lookup categories |
| `cohort` | Implemented | Cohort CRUD, pagination, status update | | `cohort` | Implemented | Cohort CRUD, pagination, status update |
## Prerequisites ## Prerequisites
@@ -80,20 +81,20 @@ http://localhost:3001/docs
## Endpoints ## Endpoints
| Method | Path | | Method | Path |
|--------|------| | -------- | -------------------------------- |
| `GET` | `/api/health` | | `GET` | `/api/health` |
| `GET` | `/api/master-data/:category` | | `GET` | `/api/master-data/:category` |
| `POST` | `/api/master-data/:category` | | `POST` | `/api/master-data/:category` |
| `GET` | `/api/master-data/:category/:id` | | `GET` | `/api/master-data/:category/:id` |
| `PUT` | `/api/master-data/:category/:id` | | `PUT` | `/api/master-data/:category/:id` |
| `DELETE` | `/api/master-data/:category/:id` | | `DELETE` | `/api/master-data/:category/:id` |
| `GET` | `/api/cohorts?page=1&limit=10` | | `GET` | `/api/cohorts?page=1&limit=10` |
| `POST` | `/api/cohorts` | | `POST` | `/api/cohorts` |
| `GET` | `/api/cohorts/:id` | | `GET` | `/api/cohorts/:id` |
| `PUT` | `/api/cohorts/:id` | | `PUT` | `/api/cohorts/:id` |
| `PATCH` | `/api/cohorts/:id/status` | | `PATCH` | `/api/cohorts/:id/status` |
| `DELETE` | `/api/cohorts/:id` | | `DELETE` | `/api/cohorts/:id` |
## Seed Master Data ## Seed Master Data
+2
View File
@@ -7,6 +7,7 @@ import { CohortModule } from './modules/cohort/cohort.module';
import { TenantModule } from './modules/tenant/tenant.module'; import { TenantModule } from './modules/tenant/tenant.module';
import { TenantMiddleware } from './common/tenant/tenant.middleware'; import { TenantMiddleware } from './common/tenant/tenant.middleware';
import { PolicyEngineModule } from './modules/policy-engine/policy-engine.module'; import { PolicyEngineModule } from './modules/policy-engine/policy-engine.module';
import { RecoveryIncidentModule } from './modules/recovery-incident/recovery-incident.module';
const env = process.env.NODE_ENV; const env = process.env.NODE_ENV;
const envFilePath = env ? [`.env.${env}`, '.env.local', '.env'] : ['.env.local', '.env']; const envFilePath = env ? [`.env.${env}`, '.env.local', '.env'] : ['.env.local', '.env'];
@@ -23,6 +24,7 @@ const envFilePath = env ? [`.env.${env}`, '.env.local', '.env'] : ['.env.local',
MasterDataModule, MasterDataModule,
CohortModule, CohortModule,
PolicyEngineModule, PolicyEngineModule,
RecoveryIncidentModule,
], ],
}) })
export class AppModule implements NestModule { export class AppModule implements NestModule {
@@ -0,0 +1,51 @@
import { IsString, IsNotEmpty, IsOptional, IsDateString, IsArray, ValidateNested } from 'class-validator';
import { Type } from 'class-transformer';
class IncidentStatusDto {
@IsString()
@IsNotEmpty()
text: string;
@IsString()
@IsNotEmpty()
variant: string;
}
export class CreateRecoveryIncidentDto {
@IsString()
@IsNotEmpty()
recoveryId: string;
@IsDateString()
@IsNotEmpty()
date: string;
@IsString()
@IsOptional()
passengerName?: string;
@IsString()
@IsOptional()
pnr?: string;
@IsString()
@IsNotEmpty()
flightNumber: string;
@IsString()
@IsNotEmpty()
flightRoute: string;
@IsString()
@IsOptional()
category?: string;
@IsArray()
@ValidateNested({ each: true })
@Type(() => IncidentStatusDto)
statuses: IncidentStatusDto[];
@IsString()
@IsOptional()
value?: string;
}
@@ -0,0 +1,4 @@
import { PartialType } from '@nestjs/swagger';
import { CreateRecoveryIncidentDto } from './create-recovery-incident.dto';
export class UpdateRecoveryIncidentDto extends PartialType(CreateRecoveryIncidentDto) {}
@@ -0,0 +1,43 @@
import { Entity, Column, PrimaryGeneratedColumn, CreateDateColumn, UpdateDateColumn } from 'typeorm';
@Entity('recovery_incidents')
export class RecoveryIncident {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column({ type: 'varchar', length: 255 })
tenantId: string;
@Column({ type: 'varchar', length: 255 })
recoveryId: string;
@Column({ type: 'timestamp with time zone' })
date: Date;
@Column({ type: 'varchar', length: 255, nullable: true })
passengerName?: string;
@Column({ type: 'varchar', length: 10, nullable: true })
pnr?: string;
@Column({ type: 'varchar', length: 20 })
flightNumber: string;
@Column({ type: 'varchar', length: 50 })
flightRoute: string;
@Column({ type: 'varchar', length: 255, nullable: true })
category?: string;
@Column({ type: 'jsonb', default: [] })
statuses: any[];
@Column({ type: 'varchar', length: 255, nullable: true })
value: string;
@CreateDateColumn()
createdAt: Date;
@UpdateDateColumn()
updatedAt: Date;
}
@@ -0,0 +1,43 @@
import { Controller, Get, Post, Body, Patch, Param, Delete, HttpCode, HttpStatus } from '@nestjs/common';
import { RecoveryIncidentService } from './recovery-incident.service';
import { CreateRecoveryIncidentDto } from './dto/create-recovery-incident.dto';
import { UpdateRecoveryIncidentDto } from './dto/update-recovery-incident.dto';
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
@ApiTags('Recovery Incidents')
@Controller('recovery-incidents')
export class RecoveryIncidentController {
constructor(private readonly recoveryIncidentService: RecoveryIncidentService) {}
@Post()
@ApiOperation({ summary: 'Create a new recovery incident' })
@ApiResponse({ status: HttpStatus.CREATED, description: 'The recovery incident has been successfully created.' })
create(@Body() createDto: CreateRecoveryIncidentDto) {
return this.recoveryIncidentService.create(createDto);
}
@Get()
@ApiOperation({ summary: 'Get all recovery incidents for the current tenant' })
findAll() {
return this.recoveryIncidentService.findAll();
}
@Get(':id')
@ApiOperation({ summary: 'Get a recovery incident by ID' })
findOne(@Param('id') id: string) {
return this.recoveryIncidentService.findOne(id);
}
@Patch(':id')
@ApiOperation({ summary: 'Update a recovery incident' })
update(@Param('id') id: string, @Body() updateDto: UpdateRecoveryIncidentDto) {
return this.recoveryIncidentService.update(id, updateDto);
}
@Delete(':id')
@HttpCode(HttpStatus.NO_CONTENT)
@ApiOperation({ summary: 'Delete a recovery incident' })
remove(@Param('id') id: string) {
return this.recoveryIncidentService.remove(id);
}
}
@@ -0,0 +1,13 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { RecoveryIncidentService } from './recovery-incident.service';
import { RecoveryIncidentController } from './recovery-incident.controller';
import { RecoveryIncident } from './entities/recovery-incident.entity';
@Module({
imports: [TypeOrmModule.forFeature([RecoveryIncident])],
controllers: [RecoveryIncidentController],
providers: [RecoveryIncidentService],
exports: [RecoveryIncidentService],
})
export class RecoveryIncidentModule {}
@@ -0,0 +1,63 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { RecoveryIncident } from './entities/recovery-incident.entity';
import { CreateRecoveryIncidentDto } from './dto/create-recovery-incident.dto';
import { UpdateRecoveryIncidentDto } from './dto/update-recovery-incident.dto';
import { getTenantId } from '../../common/tenant/tenant.context';
@Injectable()
export class RecoveryIncidentService {
constructor(
@InjectRepository(RecoveryIncident)
private readonly recoveryIncidentRepo: Repository<RecoveryIncident>,
) {}
async create(createDto: CreateRecoveryIncidentDto): Promise<RecoveryIncident> {
const tenantId = getTenantId();
const incident = this.recoveryIncidentRepo.create({
...createDto,
date: new Date(createDto.date),
tenantId,
});
return this.recoveryIncidentRepo.save(incident);
}
async findAll(): Promise<RecoveryIncident[]> {
const tenantId = getTenantId();
return this.recoveryIncidentRepo.find({
where: { tenantId },
order: { createdAt: 'DESC' },
});
}
async findOne(id: string): Promise<RecoveryIncident> {
const tenantId = getTenantId();
const incident = await this.recoveryIncidentRepo.findOne({
where: { id, tenantId },
});
if (!incident) {
throw new NotFoundException(`RecoveryIncident with ID ${id} not found`);
}
return incident;
}
async update(id: string, updateDto: UpdateRecoveryIncidentDto): Promise<RecoveryIncident> {
const incident = await this.findOne(id);
const updateData: any = { ...updateDto };
if (updateDto.date) {
updateData.date = new Date(updateDto.date);
}
Object.assign(incident, updateData);
return this.recoveryIncidentRepo.save(incident);
}
async remove(id: string): Promise<void> {
const incident = await this.findOne(id);
await this.recoveryIncidentRepo.remove(incident);
}
}