forked from Yara724/api
155 lines
5.5 KiB
TypeScript
155 lines
5.5 KiB
TypeScript
import {
|
||
Body,
|
||
Controller,
|
||
Get,
|
||
Param,
|
||
Post,
|
||
UseGuards,
|
||
} from "@nestjs/common";
|
||
import {
|
||
ApiBearerAuth,
|
||
ApiBody,
|
||
ApiOperation,
|
||
ApiParam,
|
||
ApiResponse,
|
||
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 { RequestManagementService } from "./request-management.service";
|
||
import { RunCallCenterInquiryV6Dto } from "./dto/run-call-center-inquiry-v6.dto";
|
||
|
||
/**
|
||
* V6 call-center blame API.
|
||
*
|
||
* A call-center agent takes the guilty party's details over the phone
|
||
* (plate, national code, birthday), runs the insurance inquiry, then sends
|
||
* the blame link via SMS. The user (guilty party) opens the link and
|
||
* completes the form through the standard v2 user flow — except the
|
||
* initial-form / inquiry step is skipped (`skipInitialFormStep=true`) because
|
||
* the agent already did it.
|
||
*
|
||
* For THIRD_PARTY files: only the guilty party's data is collected here.
|
||
* The damaged party sees their own portion of the page and fills their info
|
||
* as normal after the blame link is opened.
|
||
*/
|
||
@ApiTags("call-center-blame (v6)")
|
||
@Controller("v6/call-center-blame")
|
||
@ApiBearerAuth()
|
||
@UseGuards(LocalActorAuthGuard, RolesGuard)
|
||
@Roles(RoleEnum.CALL_CENTER)
|
||
export class CallCenterBlameV6Controller {
|
||
constructor(
|
||
private readonly requestManagementService: RequestManagementService,
|
||
) {}
|
||
|
||
@Get("my-files")
|
||
@ApiOperation({ summary: "[V6] List blame files created by this call-center agent" })
|
||
@ApiResponse({ status: 200, description: "List of blame files started by this agent" })
|
||
getMyFiles(@CurrentUser() agent: any) {
|
||
return this.requestManagementService.getMyCallCenterFilesV6(agent);
|
||
}
|
||
|
||
@Post("create")
|
||
@ApiOperation({
|
||
summary: "[V6] Create a call-center–initiated blame file",
|
||
description:
|
||
"Creates a LINK blame file. The call-center agent collects the guilty " +
|
||
"party's plate + national-code over the phone, calls run-inquiry to store " +
|
||
"the results, then calls send-link to SMS the blame URL to the user. " +
|
||
"The user opens the link and fills the form via the normal v2 flow; the " +
|
||
"initial-form/inquiry step is automatically skipped because the agent " +
|
||
"already ran it.",
|
||
})
|
||
@ApiBody({
|
||
schema: {
|
||
type: "object",
|
||
required: ["type"],
|
||
properties: {
|
||
type: {
|
||
type: "string",
|
||
enum: ["THIRD_PARTY", "CAR_BODY"],
|
||
example: "THIRD_PARTY",
|
||
},
|
||
},
|
||
},
|
||
})
|
||
createFile(
|
||
@CurrentUser() agent: any,
|
||
@Body("type") type: "THIRD_PARTY" | "CAR_BODY",
|
||
) {
|
||
return this.requestManagementService.createCallCenterInitiatedBlameV6(agent, { type });
|
||
}
|
||
|
||
@Post("run-inquiry/:requestId")
|
||
@ApiOperation({
|
||
summary: "[V6] Run plate + insurance inquiry for the guilty party",
|
||
description:
|
||
"Call after `create`. The agent supplies the plate and national-code data " +
|
||
"collected from the caller. Plate + third-party block inquiry is executed " +
|
||
"and the results are stored on the blame document. " +
|
||
"For THIRD_PARTY files only the guilty party (first party) is inquired here; " +
|
||
"the damaged party's inquiry is handled later by the user via the link. " +
|
||
"Sheba (IBAN) is not collected here — the user adds it themselves.",
|
||
})
|
||
@ApiParam({ name: "requestId", description: "Blame request ID from `create`" })
|
||
@ApiBody({ type: RunCallCenterInquiryV6Dto })
|
||
runInquiry(
|
||
@CurrentUser() agent: any,
|
||
@Param("requestId") requestId: string,
|
||
@Body() dto: RunCallCenterInquiryV6Dto,
|
||
) {
|
||
return this.requestManagementService.runCallCenterInquiryV6(agent, requestId, dto);
|
||
}
|
||
|
||
@Post("send-link/:requestId")
|
||
@ApiOperation({
|
||
summary: "[V6] Send blame link to the guilty party via SMS",
|
||
description:
|
||
"Call after `run-inquiry`. Provide the guilty party's phone number; " +
|
||
"the service registers the user if needed, stores them as the first party, " +
|
||
"and sends the blame invite link via SMS. The user opens the link and " +
|
||
"completes the blame form via the standard v2 user flow (initial-form step skipped).",
|
||
})
|
||
@ApiParam({ name: "requestId", description: "Blame request ID" })
|
||
@ApiBody({
|
||
schema: {
|
||
type: "object",
|
||
required: ["phoneNumber"],
|
||
properties: {
|
||
phoneNumber: {
|
||
type: "string",
|
||
example: "09121234567",
|
||
description: "Mobile number of the guilty party",
|
||
},
|
||
},
|
||
},
|
||
})
|
||
sendLink(
|
||
@CurrentUser() agent: any,
|
||
@Param("requestId") requestId: string,
|
||
@Body("phoneNumber") phoneNumber: string,
|
||
) {
|
||
return this.requestManagementService.sendCallCenterLinkV6(agent, requestId, { phoneNumber });
|
||
}
|
||
|
||
@Get("blame/:requestId")
|
||
@ApiOperation({
|
||
summary: "[V6] Get a single blame file created by this agent",
|
||
description:
|
||
"Returns the current status, workflow step, and party data for one blame " +
|
||
"file started by this call-center agent. Useful for checking whether the " +
|
||
"user has opened the link and progressed through the form.",
|
||
})
|
||
@ApiParam({ name: "requestId", description: "Blame request ID" })
|
||
getBlame(
|
||
@CurrentUser() agent: any,
|
||
@Param("requestId") requestId: string,
|
||
) {
|
||
return this.requestManagementService.getCallCenterBlameDetailV6(agent, requestId);
|
||
}
|
||
}
|