forked from Yara724/api
Initial commit after migration to gitea
This commit is contained in:
156
src/expert-blame/expert-blame.controller.ts
Normal file
156
src/expert-blame/expert-blame.controller.ts
Normal file
@@ -0,0 +1,156 @@
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Body,
|
||||
Param,
|
||||
UseGuards,
|
||||
Put,
|
||||
Req,
|
||||
Res,
|
||||
Headers,
|
||||
UseInterceptors,
|
||||
Patch,
|
||||
} from "@nestjs/common";
|
||||
import {
|
||||
ApiBearerAuth,
|
||||
ApiBody,
|
||||
ApiOkResponse,
|
||||
ApiParam,
|
||||
ApiProduces,
|
||||
ApiTags,
|
||||
} from "@nestjs/swagger";
|
||||
import { Response, Request } from "express";
|
||||
import { LocalActorAuthGuard } from "src/auth/guards/actor-local.guard";
|
||||
import { RolesGuard } from "src/auth/guards/role.guard";
|
||||
import { ClientKey } from "src/decorators/clientKey.decorator";
|
||||
import { Roles } from "src/decorators/roles.decorator";
|
||||
import { CurrentUser } from "src/decorators/user.decorator";
|
||||
import { LoggingInterceptor } from "src/interceptor/logging.interceptors";
|
||||
import { RoleEnum } from "src/Types&Enums/role.enum";
|
||||
import {
|
||||
ResendFirstPartyDto,
|
||||
ResendSecondPartyDto,
|
||||
SendAginIF,
|
||||
SubmitReplyDto,
|
||||
} from "./dto/reply.dto";
|
||||
import { ExpertBlameService } from "./expert-blame.service";
|
||||
|
||||
@ApiTags("expert-blame-panel")
|
||||
@Controller("expert-blame")
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(LocalActorAuthGuard, RolesGuard)
|
||||
@Roles(RoleEnum.EXPERT)
|
||||
export class ExpertBlameController {
|
||||
constructor(private readonly expertBlameService: ExpertBlameService) {}
|
||||
|
||||
// TODO role guard for expert fix
|
||||
@Roles(RoleEnum.EXPERT)
|
||||
@Get()
|
||||
async findAll(@CurrentUser() actor, @ClientKey() client) {
|
||||
return await this.expertBlameService.findAll(actor);
|
||||
}
|
||||
|
||||
@Roles(RoleEnum.EXPERT)
|
||||
@Get(":id")
|
||||
async findOne(@Param("id") id: string, @CurrentUser() actor) {
|
||||
return await this.expertBlameService.findOne(id, actor.sub);
|
||||
}
|
||||
|
||||
@Roles(RoleEnum.EXPERT)
|
||||
@Put("lock/:id")
|
||||
async lockRequest(@Param("id") id: string, @CurrentUser() actor) {
|
||||
return await this.expertBlameService.lockRequest(id, actor);
|
||||
}
|
||||
|
||||
@Roles(RoleEnum.EXPERT)
|
||||
@Get("request/accident-fields")
|
||||
async getAccidentFields() {
|
||||
return await this.expertBlameService.getAccidentField();
|
||||
}
|
||||
|
||||
@Roles(RoleEnum.EXPERT)
|
||||
@Put("reply/submit/:id")
|
||||
@ApiBody({ type: SubmitReplyDto })
|
||||
@ApiParam({ name: "id" })
|
||||
async submitReply(
|
||||
@Param("id") id: string,
|
||||
@Body() body: SubmitReplyDto,
|
||||
@CurrentUser() actor,
|
||||
) {
|
||||
return await this.expertBlameService.replyRequest(id, body, actor.sub);
|
||||
}
|
||||
|
||||
private async handleResendRequest(
|
||||
id: string,
|
||||
body: SendAginIF,
|
||||
actorSub: string,
|
||||
req: Request,
|
||||
) {
|
||||
return await this.expertBlameService.sendAgainRequest(
|
||||
id,
|
||||
body,
|
||||
actorSub,
|
||||
req,
|
||||
);
|
||||
}
|
||||
|
||||
@Roles(RoleEnum.EXPERT)
|
||||
@Put("reply/resend/first/:id")
|
||||
@ApiBody({ type: ResendFirstPartyDto })
|
||||
@ApiParam({ name: "id" })
|
||||
async resendFirstParty(
|
||||
@Param("id") id: string,
|
||||
@Body() body: SendAginIF,
|
||||
@CurrentUser() actor,
|
||||
@Req() req: Request,
|
||||
) {
|
||||
return this.handleResendRequest(id, body, actor.sub, req);
|
||||
}
|
||||
@Roles(RoleEnum.EXPERT)
|
||||
@Put("reply/resend/second/:id")
|
||||
@Roles(RoleEnum.EXPERT)
|
||||
@ApiBody({ type: ResendSecondPartyDto })
|
||||
@ApiParam({ name: "id" })
|
||||
async resendSecondParty(
|
||||
@Param("id") id: string,
|
||||
@Body() body: SendAginIF,
|
||||
@CurrentUser() actor,
|
||||
@Req() req: Request,
|
||||
) {
|
||||
return this.handleResendRequest(id, body, actor.sub, req);
|
||||
}
|
||||
@Roles(RoleEnum.EXPERT)
|
||||
@Get("stream/:requestId")
|
||||
@ApiParam({ name: "requestId" })
|
||||
async streamVideo(@Param("requestId") requestId: string) {
|
||||
return this.expertBlameService.streamVideo(requestId);
|
||||
}
|
||||
|
||||
@UseInterceptors(LoggingInterceptor)
|
||||
@Get("voice/:requestId/:voiceId")
|
||||
@Roles(RoleEnum.EXPERT, RoleEnum.DAMAGE_EXPERT)
|
||||
@ApiParam({ name: "requestId" })
|
||||
@ApiParam({ name: "voiceId" })
|
||||
@ApiOkResponse({
|
||||
schema: {
|
||||
type: "string",
|
||||
format: "binary",
|
||||
},
|
||||
})
|
||||
@ApiProduces("mp3")
|
||||
async downloadVoice(
|
||||
@Param("voiceId") voiceId,
|
||||
@Param("requestId") requestId: string,
|
||||
@Res({ passthrough: true }) res: Response,
|
||||
@Req() req: Request,
|
||||
@Headers() headers,
|
||||
) {
|
||||
return await this.expertBlameService.streamVoice(requestId, voiceId);
|
||||
}
|
||||
|
||||
@ApiParam({ name: "id" })
|
||||
@Patch(":id/visit")
|
||||
async inPersonVisit(@Param("id") requestId: string, @CurrentUser() actor) {
|
||||
return await this.expertBlameService.inPersonVisit(requestId, actor);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user