Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import {
BadRequestException,
Body,
Controller,
Get,
Param,
Post,
UseFilters,
} from "@nestjs/common";
import {
AcceptProofRequestDto,
GatewayAcceptedResponseDto,
GetSchemaRequestDto,
IssueProofRequestDto,
PROOF_ACCEPT,
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,
},
});
}
@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/:proof_record_id/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(@Param("proof_record_id") proofRecordId: string) {
const data = new AcceptProofRequestDto();
data.proofRecordId = proofRecordId;
return this.pmClient.sendPayload<AcceptProofRequestDto>({
pattern: "proofs",
payload: {
source: "/credentials/proofs/:id/accept",
data,
type: PROOF_ACCEPT,
},
});
}
}