xpeditis2.0/apps/backend/src/domain/services/port-search.service.ts
David 3fc1091d31
Some checks failed
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 5m59s
CI/CD Pipeline - Xpeditis PreProd / Backend - Docker Build & Push (push) Has been skipped
CI/CD Pipeline - Xpeditis PreProd / Frontend - Build & Test (push) Successful in 11m1s
CI/CD Pipeline - Xpeditis PreProd / Frontend - Docker Build & Push (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:31:37 +01:00

71 lines
1.8 KiB
TypeScript

/**
* PortSearchService
*
* Domain service for port search and autocomplete
*
* Business Rules:
* - Fuzzy search on port name, city, and code
* - Return top 10 results by default
* - Support country filtering
*/
import { Port } from '../entities/port.entity';
import {
GetPortsPort,
PortSearchInput,
PortSearchOutput,
GetPortInput,
} from '@domain/ports/in/get-ports.port';
import { PortRepository } from '@domain/ports/out/port.repository';
import { PortNotFoundException } from '../exceptions/port-not-found.exception';
export class PortSearchService implements GetPortsPort {
private static readonly DEFAULT_LIMIT = 10;
constructor(private readonly portRepository: PortRepository) {}
async search(input: PortSearchInput): Promise<PortSearchOutput> {
const limit = input.limit || PortSearchService.DEFAULT_LIMIT;
const query = input.query.trim();
if (query.length === 0) {
return {
ports: [],
totalMatches: 0,
};
}
// Search using repository fuzzy search
const ports = await this.portRepository.search(query, limit, input.countryFilter);
return {
ports,
totalMatches: ports.length,
};
}
async getByCode(input: GetPortInput): Promise<Port> {
const port = await this.portRepository.findByCode(input.portCode);
if (!port) {
throw new PortNotFoundException(input.portCode);
}
return port;
}
async getByCodes(portCodes: string[]): Promise<Port[]> {
const ports = await this.portRepository.findByCodes(portCodes);
// Check if all ports were found
const foundCodes = ports.map(p => p.code);
const missingCodes = portCodes.filter(code => !foundCodes.includes(code));
if (missingCodes.length > 0) {
throw new PortNotFoundException(missingCodes[0]);
}
return ports;
}
}