forked from Yara724/api
140 lines
4.6 KiB
TypeScript
140 lines
4.6 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Get,
|
|
HttpException,
|
|
InternalServerErrorException,
|
|
Param,
|
|
Put,
|
|
UseGuards,
|
|
} from "@nestjs/common";
|
|
import { ApiBearerAuth, ApiBody, ApiOperation, ApiParam, ApiTags } from "@nestjs/swagger";
|
|
import { LocalActorAuthGuard } from "src/auth/guards/actor-local.guard";
|
|
import { RolesGuard } from "src/auth/guards/role.guard";
|
|
import { Roles } from "src/decorators/roles.decorator";
|
|
import { CurrentUser } from "src/decorators/user.decorator";
|
|
import { RoleEnum } from "src/Types&Enums/role.enum";
|
|
import { ExpertBlameService } from "./expert-blame.service";
|
|
import { SubmitReplyDto } from "./dto/reply.dto";
|
|
import { ResendRequestDto } from "./dto/resend.dto";
|
|
|
|
@ApiTags("expert-blame-panel (v2)")
|
|
@Controller("v2/expert-blame")
|
|
@ApiBearerAuth()
|
|
@UseGuards(LocalActorAuthGuard, RolesGuard)
|
|
@Roles(RoleEnum.EXPERT, RoleEnum.FIELD_EXPERT)
|
|
export class ExpertBlameV2Controller {
|
|
constructor(private readonly expertBlameService: ExpertBlameService) { }
|
|
|
|
@Get()
|
|
async findAll(@CurrentUser() actor: any) {
|
|
try {
|
|
return await this.expertBlameService.findAllV2(actor);
|
|
} catch (error) {
|
|
if (error instanceof HttpException) throw error;
|
|
throw new InternalServerErrorException(
|
|
error instanceof Error ? error.message : "Failed to list blame cases",
|
|
);
|
|
}
|
|
}
|
|
|
|
@Get("report/status-counts")
|
|
@ApiOperation({
|
|
summary: "Count blame cases by grouped status bucket (tenant)",
|
|
description:
|
|
"IN_PROGRESS groups OPEN and WAITING_FOR_SECOND_PARTY. WAITING_FOR_EXPERT, WAITING_FOR_DOCUMENT_RESEND, WAITING_FOR_SIGNATURES, and terminal statuses are counted separately. Expert-initiated files count only for the initiating expert.",
|
|
})
|
|
async getStatusReportBucketsV2(@CurrentUser() actor: any) {
|
|
try {
|
|
return await this.expertBlameService.getStatusReportBucketsV2(actor);
|
|
} catch (error) {
|
|
if (error instanceof HttpException) throw error;
|
|
throw new InternalServerErrorException(
|
|
error instanceof Error ? error.message : "Failed to load blame status report",
|
|
);
|
|
}
|
|
}
|
|
|
|
@Get(":id")
|
|
@ApiParam({ name: "id", description: "Blame case request id" })
|
|
async findOne(@Param("id") id: string, @CurrentUser() actor: any) {
|
|
try {
|
|
return await this.expertBlameService.findOneV2(id, actor);
|
|
} catch (error) {
|
|
if (error instanceof HttpException) throw error;
|
|
throw new InternalServerErrorException(
|
|
error instanceof Error ? error.message : "Failed to get blame case details",
|
|
);
|
|
}
|
|
}
|
|
|
|
@Put("lock/:id")
|
|
@ApiParam({ name: "id", description: "Blame case request id" })
|
|
async lockRequest(@Param("id") id: string, @CurrentUser() actor: any) {
|
|
try {
|
|
return await this.expertBlameService.lockRequestV2(id, actor);
|
|
} catch (error) {
|
|
if (error instanceof HttpException) throw error;
|
|
throw new InternalServerErrorException(
|
|
error instanceof Error ? error.message : "Failed to lock blame case",
|
|
);
|
|
}
|
|
}
|
|
|
|
@Put("reply/resend/:id")
|
|
@ApiParam({ name: "id", description: "Blame case request id" })
|
|
@ApiBody({ type: ResendRequestDto })
|
|
async resendRequest(
|
|
@Param("id") id: string,
|
|
@Body() body: ResendRequestDto,
|
|
@CurrentUser() actor: any,
|
|
) {
|
|
try {
|
|
return await this.expertBlameService.resendRequestV2(id, body, actor);
|
|
} catch (error) {
|
|
if (error instanceof HttpException) throw error;
|
|
throw new InternalServerErrorException(
|
|
error instanceof Error
|
|
? error.message
|
|
: "Failed to request document resend",
|
|
);
|
|
}
|
|
}
|
|
|
|
@Put("reply/submit/:id")
|
|
@ApiParam({ name: "id", description: "Blame case request id" })
|
|
@ApiBody({ type: SubmitReplyDto })
|
|
async submitReply(
|
|
@Param("id") id: string,
|
|
@Body() body: SubmitReplyDto,
|
|
@CurrentUser() actor: any,
|
|
) {
|
|
try {
|
|
return await this.expertBlameService.replyRequestV2(id, body, actor);
|
|
} catch (error) {
|
|
if (error instanceof HttpException) throw error;
|
|
throw new InternalServerErrorException(
|
|
error instanceof Error ? error.message : "Failed to submit expert reply",
|
|
);
|
|
}
|
|
}
|
|
|
|
@Put("reply/inPerson/:id")
|
|
@ApiParam({ name: "id", description: "Blame case request id" })
|
|
@ApiBody({ type: SubmitReplyDto })
|
|
async submitInPerson(
|
|
@Param("id") id: string,
|
|
@Body() body: SubmitReplyDto,
|
|
@CurrentUser() actor: any,
|
|
) {
|
|
try {
|
|
return await this.expertBlameService.submitInPerson(id, actor.sub);
|
|
} catch (error) {
|
|
if (error instanceof HttpException) throw error;
|
|
throw new InternalServerErrorException(
|
|
error instanceof Error ? error.message : "Failed to submit expert reply for in person",
|
|
);
|
|
}
|
|
}
|
|
}
|