fix rate edit

This commit is contained in:
Marshal
2026-07-17 10:15:26 +00:00
parent 18311f22f7
commit 801872c106
20 changed files with 1227 additions and 112 deletions

View File

@@ -0,0 +1,58 @@
import { Body, Controller, Get, Param, ParseUUIDPipe, Post, Query } from '@nestjs/common';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
import { CurrentUser } from '@edr/api-common';
import type { TCurrentUser } from '@tria-plc/api-common/modules/auth/types/current-user.type';
import { isSuperAdmin } from '../../../common/freight-permission.util';
import { RuleEngineApprove, RuleEngineManage, RuleEngineView } from '../../../common/rule-engine-guards';
import { DecideRateChangeDto, SubmitRateChangeDto } from '../dto/rate-change-request.dto';
import { RateChangeStatus } from '../entities/rate-change-request.entity';
import { RateChangeRequestsService } from '../services/rate-change-requests.service';
/**
* Edits to LIVE rates. Staff with `manage` propose (submit); only holders of
* `approve` decide. Until a change is approved the live rate keeps its current
* value, so pricing never moves on an unapproved edit.
*/
@ApiTags('rate-change-requests')
@Controller('rate-change-requests')
@ApiBearerAuth()
export class RateChangeRequestsController {
constructor(private readonly service: RateChangeRequestsService) {}
@Post()
@RuleEngineManage('rates')
@ApiOperation({ summary: 'Propose a change to a LIVE rate' })
submit(@Body() dto: SubmitRateChangeDto, @CurrentUser() user: TCurrentUser) {
return this.service.submit(dto, user?.id);
}
@Get()
@RuleEngineView('rates')
@ApiOperation({ summary: 'List rate change requests, optionally by status' })
list(@Query('status') status?: RateChangeStatus) {
return this.service.list(status);
}
@Post(':id/approve')
@RuleEngineApprove('rates')
@ApiOperation({ summary: 'Approve a rate change and put it into effect' })
approve(
@Param('id', ParseUUIDPipe) id: string,
@Body() dto: DecideRateChangeDto,
@CurrentUser() user: TCurrentUser,
) {
return this.service.approve(id, user?.id, dto.decisionNote, isSuperAdmin(user));
}
@Post(':id/reject')
@RuleEngineApprove('rates')
@ApiOperation({ summary: 'Reject a rate change — the rate keeps its current value' })
reject(
@Param('id', ParseUUIDPipe) id: string,
@Body() dto: DecideRateChangeDto,
@CurrentUser() user: TCurrentUser,
) {
return this.service.reject(id, user?.id, dto.decisionNote);
}
}