forked from Yara724/api
137 lines
4.5 KiB
TypeScript
137 lines
4.5 KiB
TypeScript
import { Body, Controller, Get, Param, Patch, Post, UploadedFile, UseGuards, UseInterceptors } from "@nestjs/common";
|
|
import { FileInterceptor } from "@nestjs/platform-express";
|
|
import { diskStorage } from "multer";
|
|
import { extname } from "path";
|
|
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 { Roles } from "src/decorators/roles.decorator";
|
|
import { CurrentUser } from "src/decorators/user.decorator";
|
|
import { RoleEnum } from "src/Types&Enums/role.enum";
|
|
import { DEFAULT_MEDIA_MAX_BYTES } from "src/client/client.service";
|
|
import { SelectOuterPartsV2Dto } from "./dto/select-outer-parts-v2.dto";
|
|
import { SelectOtherPartsV2Dto } from "./dto/select-other-parts-v2.dto";
|
|
import { UploadRequiredDocumentV2Dto } from "./dto/upload-document-v2.dto";
|
|
import { CapturePartV2Dto } from "./dto/capture-part-v2.dto";
|
|
import { ClaimRequestManagementService } from "./claim-request-management.service";
|
|
|
|
@ApiTags("registrar-claim (v1)")
|
|
@Controller("registrar-claim")
|
|
@ApiBearerAuth()
|
|
@UseGuards(LocalActorAuthGuard, RolesGuard)
|
|
@Roles(RoleEnum.REGISTRAR)
|
|
export class RegistrarClaimV1Controller {
|
|
constructor(private readonly claimRequestManagementService: ClaimRequestManagementService) {}
|
|
|
|
@Post("create-from-blame/:blameRequestId")
|
|
@ApiParam({ name: "blameRequestId" })
|
|
createFromBlame(@Param("blameRequestId") blameRequestId: string, @CurrentUser() registrar: any) {
|
|
return this.claimRequestManagementService.createClaimFromBlameForRegistrarV1(
|
|
blameRequestId,
|
|
registrar,
|
|
);
|
|
}
|
|
|
|
@Get("request/:claimRequestId")
|
|
getClaim(@Param("claimRequestId") claimRequestId: string, @CurrentUser() registrar: any) {
|
|
return this.claimRequestManagementService.getClaimDetailsV2(
|
|
claimRequestId,
|
|
registrar.sub,
|
|
registrar,
|
|
);
|
|
}
|
|
|
|
@Patch("select-outer-parts/:claimRequestId")
|
|
@ApiBody({ type: SelectOuterPartsV2Dto })
|
|
selectOuter(
|
|
@Param("claimRequestId") claimRequestId: string,
|
|
@Body() body: SelectOuterPartsV2Dto,
|
|
@CurrentUser() registrar: any,
|
|
) {
|
|
return this.claimRequestManagementService.selectOuterPartsV2(
|
|
claimRequestId,
|
|
body,
|
|
registrar.sub,
|
|
registrar,
|
|
);
|
|
}
|
|
|
|
@Patch("select-other-parts/:claimRequestId")
|
|
@ApiBody({ type: SelectOtherPartsV2Dto })
|
|
selectOther(
|
|
@Param("claimRequestId") claimRequestId: string,
|
|
@Body() body: SelectOtherPartsV2Dto,
|
|
@CurrentUser() registrar: any,
|
|
) {
|
|
return this.claimRequestManagementService.selectOtherPartsV2(
|
|
claimRequestId,
|
|
body,
|
|
registrar.sub,
|
|
registrar,
|
|
);
|
|
}
|
|
|
|
@Get("capture-requirements/:claimRequestId")
|
|
getCapture(@Param("claimRequestId") claimRequestId: string, @CurrentUser() registrar: any) {
|
|
return this.claimRequestManagementService.getCaptureRequirementsV2(
|
|
claimRequestId,
|
|
registrar.sub,
|
|
registrar,
|
|
);
|
|
}
|
|
|
|
@Post("upload-document/:claimRequestId")
|
|
@ApiConsumes("multipart/form-data")
|
|
@UseInterceptors(
|
|
FileInterceptor("file", {
|
|
limits: { fileSize: DEFAULT_MEDIA_MAX_BYTES },
|
|
storage: diskStorage({
|
|
destination: "./files/claim-documents",
|
|
filename: (req, file, cb) => cb(null, `${Date.now()}${extname(file.originalname)}`),
|
|
}),
|
|
}),
|
|
)
|
|
@ApiOperation({ summary: "Registrar uploads required claim document" })
|
|
uploadDoc(
|
|
@Param("claimRequestId") claimRequestId: string,
|
|
@Body() body: UploadRequiredDocumentV2Dto,
|
|
@UploadedFile() file: Express.Multer.File,
|
|
@CurrentUser() registrar: any,
|
|
) {
|
|
return this.claimRequestManagementService.uploadRequiredDocumentV2(
|
|
claimRequestId,
|
|
body,
|
|
file,
|
|
registrar.sub,
|
|
registrar,
|
|
);
|
|
}
|
|
|
|
@Post("capture-part/:claimRequestId")
|
|
@ApiConsumes("multipart/form-data")
|
|
@UseInterceptors(
|
|
FileInterceptor("file", {
|
|
limits: { fileSize: DEFAULT_MEDIA_MAX_BYTES },
|
|
storage: diskStorage({
|
|
destination: "./files/claim-captures",
|
|
filename: (req, file, cb) => cb(null, `${Date.now()}${extname(file.originalname)}`),
|
|
}),
|
|
}),
|
|
)
|
|
capturePart(
|
|
@Param("claimRequestId") claimRequestId: string,
|
|
@Body() body: CapturePartV2Dto,
|
|
@UploadedFile() file: Express.Multer.File,
|
|
@CurrentUser() registrar: any,
|
|
) {
|
|
return this.claimRequestManagementService.capturePartV2(
|
|
claimRequestId,
|
|
body,
|
|
file,
|
|
registrar.sub,
|
|
registrar,
|
|
);
|
|
}
|
|
}
|
|
|