Skip to content
Snippets Groups Projects
proof.controller.ts 8.45 KiB
Newer Older
  • Learn to ignore specific revisions
  • import { Body, Controller, Get, Post, UseFilters } from "@nestjs/common";
    
    import {
      AcceptProofRequestDto,
    
      DeclineProofRequestDto,
    
      GatewayAcceptedResponseDto,
    
    Boyan Tsolov's avatar
    Boyan Tsolov committed
      GetProofRequestDto,
    
      GetSchemaRequestDto,
      IssueProofRequestDto,
      PROOF_ACCEPT,
    
    Boyan Tsolov's avatar
    Boyan Tsolov committed
      PROOF_GET,
    
      PROOF_ISSUE,
      PROOF_LIST,
    } from "@ocm-engine/dtos";
    import { AllExceptionsHandler } from "../exception.handler";
    import { ProofManagerClient } from "@ocm-engine/clients";
    import {
      ApiBadRequestResponse,
      ApiInternalServerErrorResponse,
      ApiOperation,
      ApiResponse,
    } from "@nestjs/swagger";
    
    @UseFilters(AllExceptionsHandler)
    @Controller("v1")
    export class ProofController {
      constructor(private readonly pmClient: ProofManagerClient) {}
    
      @Get("/credentials/proof")
      @ApiResponse({
        status: 200,
        description:
          "Request is accepted for execution, the response id will match the event id received from the web socket",
        type: GatewayAcceptedResponseDto,
      })
    
      @ApiInternalServerErrorResponse({
    
        description:
          "Error in sending data to proof manager. This error shows that proof manager could not convert request to event or proof manager could not send the event to the broker.",
    
        content: {
          "application/json": {
            schema: {
              type: "object",
              properties: {
                statusCode: {
                  type: "number",
                  example: 500,
                },
    
                message: {
                  type: "string",
                  example: "connect ECONNREFUSED 0.0.0.0.0:1919",
                },
              },
            },
          },
        },
    
      })
      @ApiOperation({
        summary: "List received unaccepted proofs",
        description:
          "Method list all received unaccepted proofs. Status - request-receive. The id of the response will be matched when you receive event from the websocket",
        tags: ["Credentials Proof"],
      })
      proofs() {
        return this.pmClient.sendPayload<GetSchemaRequestDto>({
          pattern: "proofs",
          payload: {
            source: "/credential/proofs",
            data: null,
            type: PROOF_LIST,
          },
        });
      }
    
    
    Boyan Tsolov's avatar
    Boyan Tsolov committed
    
      @Get("/credentials/proof/:proof_record_id")
      @ApiResponse({
        status: 200,
        description:
          "Request is accepted for execution, the response id will match the event id received from the web socket",
        type: GatewayAcceptedResponseDto,
      })
      @ApiInternalServerErrorResponse({
        description:
          "Error in sending data to proof manager. This error shows that proof manager could not convert request to event or proof manager could not send the event to the broker.",
        content: {
          "application/json": {
            schema: {
              type: "object",
              properties: {
                statusCode: {
                  type: "number",
                  example: 500,
                },
    
                message: {
                  type: "string",
                  example: "connect ECONNREFUSED 0.0.0.0.0:1919",
                },
              },
            },
          },
        },
      })
      @ApiOperation({
        summary: "Get a single proof record by providing proof record id.",
        description:
          "Method get proof by id. Status - request-receive. The id of the response will be matched when you receive event from the websocket",
        tags: ["Credentials Proof Get Id"],
      })
      getProofById(@Param("proof_record_id") proofRecordId: string) {
    
    Boyan Tsolov's avatar
    Boyan Tsolov committed
        const data = new GetProofRequestDto();
    
    Boyan Tsolov's avatar
    Boyan Tsolov committed
        data.proofRecordId = proofRecordId;
    
    
    Boyan Tsolov's avatar
    Boyan Tsolov committed
        return this.pmClient.sendPayload<GetProofRequestDto>({
    
    Boyan Tsolov's avatar
    Boyan Tsolov committed
          pattern: "proofs",
          payload: {
            source: "/credentials/proof/:proof_record_id",
            data,
    
    Boyan Tsolov's avatar
    Boyan Tsolov committed
            type: PROOF_GET,
    
      @Post("/credentials/proof/issue")
      @ApiResponse({
        status: 201,
        description:
          "Request is accepted for execution, the response id will match the event id received from the web socket",
        type: GatewayAcceptedResponseDto,
      })
      @ApiBadRequestResponse({
    
        description: "Validation error",
        content: {
          "application/json": {
            schema: {
              type: "object",
              properties: {
                statusCode: {
                  type: "number",
                  example: 400,
                },
    
                message: {
                  type: "array",
                  example: [
                    "attributes must contain at least 1 elements",
                    "attributes must be an array",
                  ],
                },
                error: {
                  type: "string",
                  example: "Bad Request",
                },
              },
            },
          },
        },
    
      })
      @ApiInternalServerErrorResponse({
    
        description:
          "Error in sending data to proof manager. This error shows that proof manager could not convert request to event or proof manager could not send the event to the broker.",
        content: {
          "application/json": {
            schema: {
              type: "object",
              properties: {
                statusCode: {
                  type: "number",
                  example: 500,
                },
    
                message: {
                  type: "string",
                  example: "connect ECONNREFUSED 0.0.0.0.0:1919",
                },
              },
            },
          },
        },
    
      })
      @ApiOperation({
        summary: "Issue proof for credential",
        description:
          "Method will issue proof. If connection id is not passed, the proof will be OOB. The id of the response will be matched when you receive event from the websocket",
        tags: ["Credentials Proof"],
      })
      issueProof(@Body() issueProofDto: IssueProofRequestDto) {
        return this.pmClient.sendPayload<IssueProofRequestDto>({
          pattern: "proofs",
          payload: {
            source: "/credentials/proof/issue",
            data: issueProofDto,
            type: PROOF_ISSUE,
          },
        });
      }
    
    
      @Post(`/credentials/proof/accept`)
    
      @ApiResponse({
        status: 201,
        description:
          "Request is accepted for execution, the response id will match the event id received from the web socket",
        type: GatewayAcceptedResponseDto,
      })
    
      @ApiInternalServerErrorResponse({
    
        description:
          "Error in sending data to proof manager. This error shows that proof manager could not convert request to event or proof manager could not send the event to the broker.",
    
        content: {
          "application/json": {
            schema: {
              type: "object",
              properties: {
                statusCode: {
                  type: "number",
                  example: 500,
                },
    
                message: {
                  type: "string",
                  example: "connect ECONNREFUSED 0.0.0.0.0:1919",
                },
              },
            },
          },
        },
    
      })
      @ApiOperation({
        summary: "Accept credential proof",
        description:
          "Method accept credential proof. The id of the response will be matched when you receive event from the websocket",
        tags: ["Credentials Proof"],
      })
    
      acceptProof(@Body() acceptProofRequestDto: AcceptProofRequestDto) {
    
        return this.pmClient.sendPayload<AcceptProofRequestDto>({
          pattern: "proofs",
          payload: {
    
            source: "/credentials/proofs/accept",
            data: acceptProofRequestDto,
    
            type: PROOF_ACCEPT,
          },
        });
      }
    
    
    
      @Post("/credentials/proof/:proof_record_id/decline")
      @ApiResponse({
        status: 200,
        description:
          "Request is accepted for execution, the response id will match the event id received from the web socket",
        type: GatewayAcceptedResponseDto,
      })
      @ApiInternalServerErrorResponse({
        description:
          "Error in sending data to proof manager. This error shows that proof manager could not convert request to event or proof manager could not send the event to the broker.",
        content: {
          "application/json": {
            schema: {
              type: "object",
              properties: {
                statusCode: {
                  type: "number",
                  example: 500,
                },
    
                message: {
                  type: "string",
                  example: "connect ECONNREFUSED 0.0.0.0.0:1919",
                },
              },
            },
          },
        },
      })
      @ApiOperation({
        summary: "Decline a proof request.",
        description:
          "Method to decline a proof request by id. Status - request-receive. The id of the response will be matched when you receive event from the websocket",
        tags: ["Credentials Proof Decline Request Id"],
      })
      declineProofRequest(@Param("proof_record_id") proofRecordId: string) {
        const data = new DeclineProofRequestDto();
        data.proofRecordId = proofRecordId;
    
        return this.pmClient.sendPayload<DeclineProofRequestDto>({
          pattern: "proofs",
          payload: {
            source: "/credentials/proof/:proof_record_id/decline",
            data,
            type: PROOF_DECLINE,
          },
        });
      }