Newer
Older
import { Body, Controller, Get, Post, UseFilters } from "@nestjs/common";
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,
},
});
}
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
@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) {
return this.pmClient.sendPayload<GetProofRequestDto>({
pattern: "proofs",
payload: {
source: "/credentials/proof/:proof_record_id",
data,
@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({
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
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,
},
});
}
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
@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,
},
});
}