recovery incidents
This commit is contained in:
@@ -1,15 +1,16 @@
|
||||
# AeroResolve Backend
|
||||
test12345
|
||||
|
||||
test1
|
||||
NestJS REST API for AeroResolve.
|
||||
|
||||
## Current Modules
|
||||
|
||||
| Module | Status | Description |
|
||||
|--------|--------|-------------|
|
||||
| `health` | Implemented | Health check |
|
||||
| `database` | Implemented | PostgreSQL / TypeORM setup |
|
||||
| Module | Status | Description |
|
||||
| ------------- | ----------- | ---------------------------------------- |
|
||||
| `health` | Implemented | Health check |
|
||||
| `database` | Implemented | PostgreSQL / TypeORM setup |
|
||||
| `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
|
||||
|
||||
@@ -80,20 +81,20 @@ http://localhost:3001/docs
|
||||
|
||||
## Endpoints
|
||||
|
||||
| Method | Path |
|
||||
|--------|------|
|
||||
| `GET` | `/api/health` |
|
||||
| `GET` | `/api/master-data/:category` |
|
||||
| `POST` | `/api/master-data/:category` |
|
||||
| `GET` | `/api/master-data/:category/:id` |
|
||||
| `PUT` | `/api/master-data/:category/:id` |
|
||||
| Method | Path |
|
||||
| -------- | -------------------------------- |
|
||||
| `GET` | `/api/health` |
|
||||
| `GET` | `/api/master-data/:category` |
|
||||
| `POST` | `/api/master-data/:category` |
|
||||
| `GET` | `/api/master-data/:category/:id` |
|
||||
| `PUT` | `/api/master-data/:category/:id` |
|
||||
| `DELETE` | `/api/master-data/:category/:id` |
|
||||
| `GET` | `/api/cohorts?page=1&limit=10` |
|
||||
| `POST` | `/api/cohorts` |
|
||||
| `GET` | `/api/cohorts/:id` |
|
||||
| `PUT` | `/api/cohorts/:id` |
|
||||
| `PATCH` | `/api/cohorts/:id/status` |
|
||||
| `DELETE` | `/api/cohorts/:id` |
|
||||
| `GET` | `/api/cohorts?page=1&limit=10` |
|
||||
| `POST` | `/api/cohorts` |
|
||||
| `GET` | `/api/cohorts/:id` |
|
||||
| `PUT` | `/api/cohorts/:id` |
|
||||
| `PATCH` | `/api/cohorts/:id/status` |
|
||||
| `DELETE` | `/api/cohorts/:id` |
|
||||
|
||||
## Seed Master Data
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import { CohortModule } from './modules/cohort/cohort.module';
|
||||
import { TenantModule } from './modules/tenant/tenant.module';
|
||||
import { TenantMiddleware } from './common/tenant/tenant.middleware';
|
||||
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 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,
|
||||
CohortModule,
|
||||
PolicyEngineModule,
|
||||
RecoveryIncidentModule,
|
||||
],
|
||||
})
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user