Files
edr-platform/apps/edr-freight-api/src/modules/rule-engine/services/shipping-lines.service.ts
Marshal 4b7f6d2548 enhance contract and booking services with server-side search and validation improvements
- Added  parameter to  and  for server-side free-text search on contract reference, company name, and booking details.
- Introduced new validation errors in  for container clashes and space issues when creating bookings.
- Implemented paginated dropdown settings retrieval in .
- Updated  to fetch active yards using a new method that handles pagination.
- Enhanced  with a  method to fetch all records by walking through pages.
- Refactored  to support filtering and pagination in schedule listings.
- Improved  to return a paginated list of facilities.
- Updated UI components in  and  to utilize debounced search inputs for better performance.
- Added alerts in  to inform users about booking constraints related to splits and capacity.
- Enhanced  to display notifications for split bookings and capacity usage.
2026-07-12 10:51:31 +00:00

64 lines
2.3 KiB
TypeScript

import { PaginatedResponse } from '@edr/types';
import { ConflictException, Inject, Injectable, NotFoundException } from '@nestjs/common';
import { CreateShippingLineDto } from '../dto/create-shipping-line.dto';
import { ListRuleEngineQueryDto } from '../dto/list-rule-engine-query.dto';
import { UpdateShippingLineDto } from '../dto/update-shipping-line.dto';
import { ShippingLine } from '../entities/shipping-line.entity';
import {
IShippingLinesRepository,
SHIPPING_LINES_REPOSITORY,
} from '../interfaces/shipping-lines.repository.interface';
@Injectable()
export class ShippingLinesService {
constructor(
@Inject(SHIPPING_LINES_REPOSITORY)
private readonly repository: IShippingLinesRepository,
) {}
/** List shipping lines — standard paginated envelope with server-side search. */
async findAll(query: ListRuleEngineQueryDto): Promise<PaginatedResponse<ShippingLine>> {
return this.repository.findPaged(query);
}
/** Get a shipping line by ID. */
async findById(id: string): Promise<ShippingLine> {
const entity = await this.repository.findById(id);
if (!entity) throw new NotFoundException(`Shipping line ${id} not found`);
return entity;
}
/** Create a shipping line. */
async create(dto: CreateShippingLineDto): Promise<ShippingLine> {
const existing = await this.repository.findByCode(dto.code);
if (existing) throw new ConflictException(`Shipping line with code "${dto.code}" already exists`);
return this.repository.create({
code: dto.code,
label: dto.label,
mappedToCode: dto.mappedToCode,
showExtraFeeNotice: dto.showExtraFeeNotice ?? false,
isActive: dto.isActive ?? true,
});
}
/** Update a shipping line. */
async update(id: string, dto: UpdateShippingLineDto): Promise<ShippingLine> {
await this.findById(id);
if (dto.code) {
const conflict = await this.repository.findByCode(dto.code);
if (conflict && conflict.id !== id) {
throw new ConflictException(`Shipping line with code "${dto.code}" already exists`);
}
}
const updated = await this.repository.update(id, dto);
if (!updated) throw new NotFoundException(`Shipping line ${id} not found`);
return updated;
}
/** Soft-delete a shipping line. */
async remove(id: string): Promise<void> {
await this.findById(id);
await this.repository.softDelete(id);
}
}