import { Controller, Get, Headers, HttpException, Logger } from '@nestjs/common'; import { PlatformGraphqlService } from '../platform/platform-graphql.service'; import { WorklistService } from './worklist.service'; @Controller('api/worklist') export class WorklistController { private readonly logger = new Logger(WorklistController.name); constructor( private readonly worklist: WorklistService, private readonly platform: PlatformGraphqlService, ) {} @Get() async getWorklist(@Headers('authorization') authHeader: string) { if (!authHeader) { throw new HttpException('Authorization required', 401); } const agentName = await this.resolveAgentName(authHeader); this.logger.log(`Fetching worklist for agent: ${agentName}`); return this.worklist.getWorklist(agentName, authHeader); } private async resolveAgentName(authHeader: string): Promise { try { const data = await this.platform.queryWithAuth( `{ currentUser { workspaceMember { name { firstName lastName } } } }`, undefined, authHeader, ); const name = data.currentUser?.workspaceMember?.name; const full = `${name?.firstName ?? ''} ${name?.lastName ?? ''}`.trim(); if (full) return full; } catch (err) { this.logger.warn(`Failed to resolve agent name: ${err}`); } throw new HttpException('Could not determine agent identity', 400); } }