IAM related required updates

This commit is contained in:
Stephanos A
2026-06-24 19:53:05 +03:00
parent d94e0e9d35
commit 58967e6e3d
19 changed files with 240 additions and 142 deletions

View File

@@ -1,19 +1,21 @@
import { Body, Controller, Get, Param, Post, Query, UseGuards } from '@nestjs/common';
import { Body, Controller, Get, Param, Post, Query, Request, UseGuards } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
import { AgentsService } from './agents.service';
import { CreateAgentBookingDto, OpenShiftDto, CloseShiftDto } from './agents.dto';
// IAM auth: validate the IAM session token via @tria-plc/api-common's DB-backed JwtGuard.
import { JwtGuard as IamJwtGuard } from '@tria-plc/api-common/modules/auth/services/jwt.guard';
@ApiTags('Agents')
@Controller('agents')
// TODO(iam-authz): restrict per route via @UseGuards(PermissionGuard([...])) once the IAM
// role→permission mapping (EIamPermissionKey) is confirmed. For now: authenticated IAM users only.
@UseGuards(IamJwtGuard)
@ApiBearerAuth('IAM-auth')
export class AgentsController {
constructor(private service: AgentsService) {}
@Get('me')
@ApiOperation({ summary: 'Get agent profile for logged-in IAM user' })
getMe(@Request() req: any) {
return this.service.getMe(req.user?.id ?? req.user?.sub);
}
@Post('bookings')
@ApiOperation({ summary: 'Create agent booking with cash payment' })
createBooking(@Body() dto: CreateAgentBookingDto) {

View File

@@ -133,4 +133,10 @@ export class AgentsService {
take: 20
});
}
async getMe(iamUserId: string) {
const agent = await this.prisma.agent.findUnique({ where: { iamUserId } });
if (!agent) throw new NotFoundException('No agent profile found for this user');
return agent;
}
}