forked from Yara724/api
156 lines
5.4 KiB
TypeScript
156 lines
5.4 KiB
TypeScript
import { extname } from "node:path";
|
|
import { Body, Controller, Get, Param, Post, UploadedFile, UseGuards, UseInterceptors } from "@nestjs/common";
|
|
import { FileInterceptor } from "@nestjs/platform-express";
|
|
import { diskStorage } from "multer";
|
|
import { ApiBearerAuth, ApiBody, ApiConsumes, ApiOperation, ApiParam, ApiTags } from "@nestjs/swagger";
|
|
import { LocalActorAuthGuard } from "src/auth/guards/actor-local.guard";
|
|
import { RolesGuard } from "src/auth/guards/role.guard";
|
|
import { CurrentUser } from "src/decorators/user.decorator";
|
|
import { Roles } from "src/decorators/roles.decorator";
|
|
import { RoleEnum } from "src/Types&Enums/role.enum";
|
|
import { RequestManagementService } from "./request-management.service";
|
|
import { CreateRegistrarInitiatedFileDto } from "./dto/registrar-initiated.dto";
|
|
import { SendPartyOtpsDto } from "./dto/send-party-otps.dto";
|
|
import { VerifyPartyOtpsDto } from "./dto/verify-party-otps.dto";
|
|
import { ExpertAccidentFieldsDto } from "./dto/expert-accident-fields.dto";
|
|
import { PartyRole } from "./entities/schema/partyRole.enum";
|
|
|
|
@ApiTags("registrar-initiated-blame (v1)")
|
|
@Controller("registrar-initiated-blame")
|
|
@ApiBearerAuth()
|
|
@UseGuards(LocalActorAuthGuard, RolesGuard)
|
|
@Roles(RoleEnum.REGISTRAR)
|
|
export class RegistrarInitiatedController {
|
|
constructor(private readonly requestManagementService: RequestManagementService) {}
|
|
|
|
@Post("create")
|
|
@ApiOperation({ summary: "Registrar creates IN_PERSON blame file" })
|
|
@ApiBody({ type: CreateRegistrarInitiatedFileDto })
|
|
create(@CurrentUser() registrar: any, @Body() dto: CreateRegistrarInitiatedFileDto) {
|
|
return this.requestManagementService.createRegistrarInitiatedBlame(registrar, dto);
|
|
}
|
|
|
|
@Get("my-files")
|
|
myFiles(@CurrentUser() registrar: any) {
|
|
return this.requestManagementService.getMyExpertInitiatedFilesV2(registrar);
|
|
}
|
|
|
|
@Get("blame/:requestId")
|
|
getBlame(@Param("requestId") requestId: string, @CurrentUser() registrar: any) {
|
|
return this.requestManagementService.getBlameRequestV2(requestId, registrar);
|
|
}
|
|
|
|
@Post("send-party-otps/:requestId")
|
|
@ApiParam({ name: "requestId" })
|
|
@ApiBody({ type: SendPartyOtpsDto })
|
|
sendPartyOtps(
|
|
@CurrentUser() registrar: any,
|
|
@Param("requestId") requestId: string,
|
|
@Body() dto: SendPartyOtpsDto,
|
|
) {
|
|
return this.requestManagementService.sendPartyOtpsV2(registrar, requestId, dto);
|
|
}
|
|
|
|
@Post("verify-party-otps/:requestId")
|
|
@ApiParam({ name: "requestId" })
|
|
@ApiBody({ type: VerifyPartyOtpsDto })
|
|
verifyPartyOtps(
|
|
@CurrentUser() registrar: any,
|
|
@Param("requestId") requestId: string,
|
|
@Body() dto: VerifyPartyOtpsDto,
|
|
) {
|
|
return this.requestManagementService.verifyPartyOtpsV2(registrar, requestId, dto);
|
|
}
|
|
|
|
@Post("complete-blame-data/:requestId")
|
|
completeBlameData(
|
|
@CurrentUser() registrar: any,
|
|
@Param("requestId") requestId: string,
|
|
@Body() body: any,
|
|
) {
|
|
return this.requestManagementService.expertCompleteBlameDataV2(registrar, requestId, body);
|
|
}
|
|
|
|
@Post("upload-video/:requestId")
|
|
@ApiConsumes("multipart/form-data")
|
|
@UseInterceptors(
|
|
FileInterceptor("file", {
|
|
limits: { fileSize: 20 * 1024 * 1024 },
|
|
storage: diskStorage({
|
|
destination: "./files/video",
|
|
filename: (req, file, cb) => cb(null, `registrar-${Date.now()}${extname(file.originalname)}`),
|
|
}),
|
|
}),
|
|
)
|
|
uploadVideo(
|
|
@CurrentUser() registrar: any,
|
|
@Param("requestId") requestId: string,
|
|
@UploadedFile() file?: Express.Multer.File,
|
|
) {
|
|
return this.requestManagementService.expertUploadVideoForBlameV2(registrar, requestId, file);
|
|
}
|
|
|
|
@Post("upload-voice/:requestId")
|
|
@ApiConsumes("multipart/form-data")
|
|
@UseInterceptors(
|
|
FileInterceptor("voice", {
|
|
limits: { fileSize: 10 * 1024 * 1024 },
|
|
storage: diskStorage({
|
|
destination: "./files/voice",
|
|
filename: (req, file, cb) => cb(null, `registrar-${Date.now()}${extname(file.originalname)}`),
|
|
}),
|
|
}),
|
|
)
|
|
uploadVoice(
|
|
@CurrentUser() registrar: any,
|
|
@Param("requestId") requestId: string,
|
|
@UploadedFile() voice?: Express.Multer.File,
|
|
) {
|
|
return this.requestManagementService.expertUploadVoiceForBlameV2(registrar, requestId, voice);
|
|
}
|
|
|
|
@Post("add-accident-fields/:requestId")
|
|
@ApiBody({ type: ExpertAccidentFieldsDto })
|
|
addAccidentFields(
|
|
@CurrentUser() registrar: any,
|
|
@Param("requestId") requestId: string,
|
|
@Body() fields: ExpertAccidentFieldsDto,
|
|
) {
|
|
return this.requestManagementService.expertAddAccidentFieldsForBlameV2(
|
|
registrar,
|
|
requestId,
|
|
fields,
|
|
);
|
|
}
|
|
|
|
@Post("upload-party-signature/:requestId")
|
|
@ApiConsumes("multipart/form-data")
|
|
@UseInterceptors(
|
|
FileInterceptor("sign", {
|
|
limits: { fileSize: 10 * 1024 * 1024 },
|
|
storage: diskStorage({
|
|
destination: "./files/signs",
|
|
filename: (req, file, cb) => cb(null, `registrar-party-${Date.now()}${extname(file.originalname)}`),
|
|
}),
|
|
}),
|
|
)
|
|
uploadPartySignature(
|
|
@CurrentUser() registrar: any,
|
|
@Param("requestId") requestId: string,
|
|
@Body() body: { partyRole?: string; isAccept?: boolean | string },
|
|
@UploadedFile() sign?: Express.Multer.File,
|
|
) {
|
|
const role =
|
|
body.partyRole === "SECOND" ? PartyRole.SECOND : PartyRole.FIRST;
|
|
const isAccept = !(body.isAccept === false || body.isAccept === "false");
|
|
return this.requestManagementService.expertUploadPartySignatureV2(
|
|
registrar,
|
|
requestId,
|
|
role,
|
|
isAccept,
|
|
sign!,
|
|
);
|
|
}
|
|
}
|
|
|