xpeditis2.0/apps/backend/src/infrastructure/carriers/hapag-lloyd/hapag-lloyd.connector.ts
David 4b00ee2601
Some checks failed
CI/CD Pipeline - Xpeditis PreProd / Frontend - Docker Build & Push (push) Blocked by required conditions
CI/CD Pipeline - Xpeditis PreProd / Deploy to PreProd Server (push) Blocked by required conditions
CI/CD Pipeline - Xpeditis PreProd / Run Smoke Tests (push) Blocked by required conditions
CI/CD Pipeline - Xpeditis PreProd / Backend - Build & Test (push) Failing after 5m53s
CI/CD Pipeline - Xpeditis PreProd / Backend - Docker Build & Push (push) Has been skipped
CI/CD Pipeline - Xpeditis PreProd / Frontend - Build & Test (push) Has been cancelled
fix: replace relative domain imports with TypeScript path aliases
- Replace all ../../domain/ imports with @domain/ across 67 files
- Configure NestJS to use tsconfig.build.json with rootDir
- Add tsc-alias to resolve path aliases after build
- This fixes 'Cannot find module' TypeScript compilation errors

Fixed files:
- 30 files in application layer
- 37 files in infrastructure layer
2025-11-16 19:20:58 +01:00

101 lines
2.9 KiB
TypeScript

/**
* Hapag-Lloyd Connector
*
* Implements CarrierConnectorPort for Hapag-Lloyd Quick Quotes API
*/
import { Injectable, Logger } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import {
CarrierConnectorPort,
CarrierRateSearchInput,
CarrierAvailabilityInput,
} from '@domain/ports/out/carrier-connector.port';
import { RateQuote } from '@domain/entities/rate-quote.entity';
import { BaseCarrierConnector, CarrierConfig } from '../base-carrier.connector';
import { HapagLloydRequestMapper } from './hapag-lloyd.mapper';
@Injectable()
export class HapagLloydConnectorAdapter
extends BaseCarrierConnector
implements CarrierConnectorPort
{
private readonly apiUrl: string;
private readonly apiKey: string;
constructor(
private readonly configService: ConfigService,
private readonly requestMapper: HapagLloydRequestMapper
) {
const config: CarrierConfig = {
name: 'Hapag-Lloyd',
code: 'HLCU',
baseUrl: configService.get<string>('HAPAG_API_URL', 'https://api.hapag-lloyd.com/v1'),
timeout: 5000,
maxRetries: 3,
circuitBreakerThreshold: 50,
circuitBreakerTimeout: 30000,
};
super(config);
this.apiUrl = config.baseUrl;
this.apiKey = this.configService.get<string>('HAPAG_API_KEY', '');
}
async searchRates(input: CarrierRateSearchInput): Promise<RateQuote[]> {
this.logger.log(`Searching Hapag-Lloyd rates: ${input.origin} -> ${input.destination}`);
try {
const hapagRequest = this.requestMapper.toHapagRequest(input);
const response = await this.makeRequest({
url: `${this.apiUrl}/quick-quotes`,
method: 'POST',
data: hapagRequest,
headers: {
'API-Key': this.apiKey,
'Content-Type': 'application/json',
},
});
const rateQuotes = this.requestMapper.fromHapagResponse(response.data, input);
this.logger.log(`Found ${rateQuotes.length} Hapag-Lloyd rates`);
return rateQuotes;
} catch (error: any) {
this.logger.error(`Hapag-Lloyd API error: ${error?.message || 'Unknown error'}`);
if (error?.response?.status === 503) {
this.logger.warn('Hapag-Lloyd service temporarily unavailable');
}
return [];
}
}
async checkAvailability(input: CarrierAvailabilityInput): Promise<number> {
try {
const response = await this.makeRequest({
url: `${this.apiUrl}/availability`,
method: 'GET',
params: {
origin: input.origin,
destination: input.destination,
departure_date: input.departureDate,
equipment_type: input.containerType,
quantity: input.quantity,
},
headers: {
'API-Key': this.apiKey,
},
});
return (response.data as any).available_capacity || 0;
} catch (error: any) {
this.logger.error(
`Hapag-Lloyd availability check error: ${error?.message || 'Unknown error'}`
);
return 0;
}
}
}