forked from Yara724/api
168 lines
4.5 KiB
TypeScript
168 lines
4.5 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Body,
|
|
Param,
|
|
UseGuards,
|
|
Put,
|
|
Req,
|
|
Res,
|
|
Headers,
|
|
UseInterceptors,
|
|
Patch,
|
|
} from "@nestjs/common";
|
|
import {
|
|
ApiBearerAuth,
|
|
ApiBody,
|
|
ApiOkResponse,
|
|
ApiParam,
|
|
ApiProduces,
|
|
ApiTags,
|
|
ApiOperation,
|
|
ApiExcludeController,
|
|
} 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 { RoleEnum } from "src/Types&Enums/role.enum";
|
|
import {
|
|
ResendFirstPartyDto,
|
|
ResendSecondPartyDto,
|
|
SendAginIF,
|
|
SubmitReplyDto,
|
|
} from "./dto/reply.dto";
|
|
import { ExpertBlameService } from "./expert-blame.service";
|
|
|
|
@ApiExcludeController()
|
|
// @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)
|
|
// @ApiOperation({ deprecated: true })
|
|
@Get()
|
|
async findAll(@CurrentUser() actor, @ClientKey() client) {
|
|
return await this.expertBlameService.findAll(actor);
|
|
}
|
|
|
|
@Roles(RoleEnum.EXPERT)
|
|
// @ApiOperation({ deprecated: true })
|
|
@Get(":id")
|
|
async findOne(@Param("id") id: string, @CurrentUser() actor) {
|
|
return await this.expertBlameService.findOne(id, actor.sub);
|
|
}
|
|
|
|
@Roles(RoleEnum.EXPERT)
|
|
// @ApiOperation({ deprecated: true })
|
|
@Put("lock/:id")
|
|
async lockRequest(@Param("id") id: string, @CurrentUser() actor) {
|
|
return await this.expertBlameService.lockRequest(id, actor);
|
|
}
|
|
|
|
@Roles(RoleEnum.EXPERT)
|
|
// @ApiOperation({ deprecated: true })
|
|
@Get("request/accident-fields")
|
|
async getAccidentFields() {
|
|
return await this.expertBlameService.getAccidentField();
|
|
}
|
|
|
|
@Roles(RoleEnum.EXPERT)
|
|
// @ApiOperation({ deprecated: true })
|
|
@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)
|
|
// @ApiOperation({ deprecated: true })
|
|
@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)
|
|
// @ApiOperation({ deprecated: true })
|
|
@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)
|
|
// @ApiOperation({ deprecated: true })
|
|
@Get("stream/:requestId")
|
|
@ApiParam({ name: "requestId" })
|
|
async streamVideo(@Param("requestId") requestId: string) {
|
|
return this.expertBlameService.streamVideo(requestId);
|
|
}
|
|
|
|
// @ApiOperation({ deprecated: true })
|
|
@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" })
|
|
// @ApiOperation({ deprecated: true })
|
|
@Patch(":id/visit")
|
|
async inPersonVisit(@Param("id") requestId: string, @CurrentUser() actor) {
|
|
return await this.expertBlameService.inPersonVisit(requestId, actor);
|
|
}
|
|
}
|