Merge pull request #786 from Tria-plc/freight_feature/usermanagement

split export
This commit is contained in:
marshal
2026-07-18 12:20:48 +03:00
committed by GitHub
14 changed files with 1092 additions and 41 deletions

View File

@@ -74,9 +74,14 @@ export class CreateRateDto {
@Transform(({ value }) => Number(value))
rateValue!: number;
@ApiProperty({ enum: RATE_UNITS, description: 'Unit basis for the rate' })
@ApiPropertyOptional({
enum: RATE_UNITS,
description:
'Unit basis for the rate. Optional for shapes with a forced unit (overweight is always PER_TON — the admin form hides the field and omits it); required otherwise.',
})
@IsOptional()
@IsIn([...RATE_UNITS])
rateUnit!: string;
rateUnit?: string;
}
export class SubmitRateForApprovalDto {

View File

@@ -68,15 +68,21 @@ export class RatesService {
private resolveRateUnit(
appliesTo: Rate['appliesTo'],
trigger: Rate['trigger'],
requestedUnit: Rate['rateUnit'],
requestedUnit: Rate['rateUnit'] | undefined,
): Rate['rateUnit'] {
// Overweight is per-ton, full stop.
// Overweight is per-ton, full stop — the admin form hides the unit field
// for it and omits rateUnit from the payload entirely.
if (trigger === 'OVERWEIGHT') return 'PER_TON';
if (!isRateUnitAllowed({ appliesTo, trigger, unit: requestedUnit })) {
const allowed = allowedRateUnits({ appliesTo, trigger }).join(', ');
const allowed = allowedRateUnits({ appliesTo, trigger });
if (!requestedUnit) {
throw new BadRequestException(
`Rate unit "${requestedUnit}" is not valid for this rate. Allowed: ${allowed}.`,
`Pick a rate unit for this rate. Allowed: ${allowed.join(', ')}.`,
);
}
if (!isRateUnitAllowed({ appliesTo, trigger, unit: requestedUnit })) {
throw new BadRequestException(
`Rate unit "${requestedUnit}" is not valid for this rate. Allowed: ${allowed.join(', ')}.`,
);
}
return requestedUnit;
@@ -272,7 +278,11 @@ export class RatesService {
tradeDirection,
isBulk: this.resolvesToBulk(appliesTo, intercityKind),
});
const rateUnit = this.resolveRateUnit(appliesTo, trigger, dto.rateUnit as Rate['rateUnit']);
const rateUnit = this.resolveRateUnit(
appliesTo,
trigger,
dto.rateUnit as Rate['rateUnit'] | undefined,
);
await this.assertNoDuplicatePattern({
rateType,