mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-27 20:10:56 +00:00
- 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.
91 lines
3.4 KiB
TypeScript
91 lines
3.4 KiB
TypeScript
import { PaginatedResponse } from '@edr/types';
|
|
import { BadRequestException, Inject, Injectable, NotFoundException } from '@nestjs/common';
|
|
import { CreateApprovalRuleDto } from '../dto/create-approval-rule.dto';
|
|
import { ListApprovalRulesQueryDto } from '../dto/list-rule-engine-query.dto';
|
|
import { ReorderItemsDto } from '../dto/reorder-items.dto';
|
|
import { UpdateApprovalRuleDto } from '../dto/update-approval-rule.dto';
|
|
import { ApprovalRule } from '../entities/approval-rule.entity';
|
|
import {
|
|
APPROVAL_RULES_REPOSITORY,
|
|
IApprovalRulesRepository,
|
|
} from '../interfaces/approval-rules.repository.interface';
|
|
import { DisplayOrderService } from './display-order.service';
|
|
|
|
@Injectable()
|
|
export class ApprovalRulesService {
|
|
constructor(
|
|
@Inject(APPROVAL_RULES_REPOSITORY)
|
|
private readonly repository: IApprovalRulesRepository,
|
|
private readonly displayOrder: DisplayOrderService,
|
|
) {}
|
|
|
|
/** List approval rules — standard paginated envelope with server-side search. */
|
|
async findAll(query: ListApprovalRulesQueryDto): Promise<PaginatedResponse<ApprovalRule>> {
|
|
return this.repository.findPaged(query);
|
|
}
|
|
|
|
/** Get approval chain for a cargo type flag. */
|
|
async findChain(requiresDirectorApproval: boolean): Promise<ApprovalRule[]> {
|
|
return this.repository.findChainForCargo(requiresDirectorApproval);
|
|
}
|
|
|
|
/** Get an approval rule by ID. */
|
|
async findById(id: string): Promise<ApprovalRule> {
|
|
const entity = await this.repository.findById(id);
|
|
if (!entity) throw new NotFoundException(`Approval rule ${id} not found`);
|
|
return entity;
|
|
}
|
|
|
|
/** Create an approval rule step. */
|
|
async create(dto: CreateApprovalRuleDto): Promise<ApprovalRule> {
|
|
if (dto.stepOrder !== undefined && dto.insertAfterId) {
|
|
throw new BadRequestException('Cannot set both stepOrder and insertAfterId');
|
|
}
|
|
|
|
const scopeWhere = { requiresDirectorApproval: dto.requiresDirectorApproval };
|
|
const stepOrder = await this.displayOrder.resolveCreateOrder(ApprovalRule, 'stepOrder', {
|
|
explicitOrder: dto.stepOrder,
|
|
insertAfterId: dto.insertAfterId,
|
|
scopeWhere,
|
|
});
|
|
|
|
return this.repository.create({
|
|
requiresDirectorApproval: dto.requiresDirectorApproval,
|
|
stepOrder,
|
|
requiredRole: dto.requiredRole,
|
|
actionLabel: dto.actionLabel,
|
|
blocksRole: dto.blocksRole,
|
|
});
|
|
}
|
|
|
|
/** Update an approval rule. */
|
|
async update(id: string, dto: UpdateApprovalRuleDto): Promise<ApprovalRule> {
|
|
await this.findById(id);
|
|
const updated = await this.repository.update(id, dto);
|
|
if (!updated) throw new NotFoundException(`Approval rule ${id} not found`);
|
|
return updated;
|
|
}
|
|
|
|
/** Soft-delete an approval rule. */
|
|
async remove(id: string): Promise<void> {
|
|
await this.findById(id);
|
|
await this.repository.softDelete(id);
|
|
}
|
|
|
|
async reorder(dto: ReorderItemsDto): Promise<void> {
|
|
if (dto.requiresDirectorApproval === undefined) {
|
|
throw new BadRequestException('requiresDirectorApproval is required for approval rule reorder');
|
|
}
|
|
await this.displayOrder.reorderByIds(ApprovalRule, 'stepOrder', dto.ids, {
|
|
requiresDirectorApproval: dto.requiresDirectorApproval,
|
|
});
|
|
}
|
|
|
|
async moveOrder(id: string, direction: 'up' | 'down'): Promise<void> {
|
|
const rule = await this.findById(id);
|
|
await this.displayOrder.moveOne(ApprovalRule, 'stepOrder', id, direction, {
|
|
requiresDirectorApproval: rule.requiresDirectorApproval,
|
|
});
|
|
}
|
|
}
|