mirror of
https://dev.azure.com/globalhealthx/EMR/_git/helix-engage-server
synced 2026-04-11 18:08:16 +00:00
lint and format
This commit is contained in:
@@ -1,61 +1,72 @@
|
||||
import { Controller, Get, Patch, Headers, Param, Body, HttpException, Logger } from '@nestjs/common';
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Patch,
|
||||
Headers,
|
||||
Param,
|
||||
Body,
|
||||
HttpException,
|
||||
Logger,
|
||||
} from '@nestjs/common';
|
||||
import { PlatformGraphqlService } from '../platform/platform-graphql.service';
|
||||
import { WorklistService } from './worklist.service';
|
||||
import { MissedQueueService } from './missed-queue.service';
|
||||
|
||||
@Controller('api/worklist')
|
||||
export class WorklistController {
|
||||
private readonly logger = new Logger(WorklistController.name);
|
||||
private readonly logger = new Logger(WorklistController.name);
|
||||
|
||||
constructor(
|
||||
private readonly worklist: WorklistService,
|
||||
private readonly missedQueue: MissedQueueService,
|
||||
private readonly platform: PlatformGraphqlService,
|
||||
) {}
|
||||
constructor(
|
||||
private readonly worklist: WorklistService,
|
||||
private readonly missedQueue: MissedQueueService,
|
||||
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);
|
||||
@Get()
|
||||
async getWorklist(@Headers('authorization') authHeader: string) {
|
||||
if (!authHeader) {
|
||||
throw new HttpException('Authorization required', 401);
|
||||
}
|
||||
|
||||
@Get('missed-queue')
|
||||
async getMissedQueue(@Headers('authorization') authHeader: string) {
|
||||
if (!authHeader) throw new HttpException('Authorization header required', 401);
|
||||
const agentName = await this.resolveAgentName(authHeader);
|
||||
return this.missedQueue.getMissedQueue(agentName, authHeader);
|
||||
}
|
||||
const agentName = await this.resolveAgentName(authHeader);
|
||||
this.logger.log(`Fetching worklist for agent: ${agentName}`);
|
||||
|
||||
@Patch('missed-queue/:id/status')
|
||||
async updateMissedCallStatus(
|
||||
@Param('id') id: string,
|
||||
@Headers('authorization') authHeader: string,
|
||||
@Body() body: { status: string },
|
||||
) {
|
||||
if (!authHeader) throw new HttpException('Authorization header required', 401);
|
||||
if (!body.status) throw new HttpException('status is required', 400);
|
||||
return this.missedQueue.updateStatus(id, body.status, authHeader);
|
||||
}
|
||||
return this.worklist.getWorklist(agentName, authHeader);
|
||||
}
|
||||
|
||||
private async resolveAgentName(authHeader: string): Promise<string> {
|
||||
try {
|
||||
const data = await this.platform.queryWithAuth<any>(
|
||||
`{ 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);
|
||||
@Get('missed-queue')
|
||||
async getMissedQueue(@Headers('authorization') authHeader: string) {
|
||||
if (!authHeader)
|
||||
throw new HttpException('Authorization header required', 401);
|
||||
const agentName = await this.resolveAgentName(authHeader);
|
||||
return this.missedQueue.getMissedQueue(agentName, authHeader);
|
||||
}
|
||||
|
||||
@Patch('missed-queue/:id/status')
|
||||
async updateMissedCallStatus(
|
||||
@Param('id') id: string,
|
||||
@Headers('authorization') authHeader: string,
|
||||
@Body() body: { status: string },
|
||||
) {
|
||||
if (!authHeader)
|
||||
throw new HttpException('Authorization header required', 401);
|
||||
if (!body.status) throw new HttpException('status is required', 400);
|
||||
return this.missedQueue.updateStatus(id, body.status, authHeader);
|
||||
}
|
||||
|
||||
private async resolveAgentName(authHeader: string): Promise<string> {
|
||||
try {
|
||||
const data = await this.platform.queryWithAuth<any>(
|
||||
`{ 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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user