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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import type {
EventAnonCredsSchemasGetAll,
EventAnonCredsSchemasGetById,
EventAnonCredsSchemasRegister,
} from '@ocm/shared';
import {
Body,
Controller,
Get,
HttpStatus,
NotFoundException,
Param,
Post,
Query,
UsePipes,
ValidationPipe,
Version,
} from '@nestjs/common';
import {
ApiBody,
ApiOperation,
ApiParam,
ApiQuery,
ApiResponse,
ApiTags,
} from '@nestjs/swagger';
import { Observable, of, switchMap } from 'rxjs';
import { GetByIdParams } from './dto/get-by-id.dto.js';
import { RegisterSchemaPayload } from './dto/register-schema.dto.js';
import { TenantIdParam } from './dto/tenant-id.dto.js';
import { SchemasService } from './schemas.service.js';
@Controller('schemas')
@UsePipes(new ValidationPipe({ transform: true, whitelist: true }))
@ApiTags('Schemas')
export class SchemasController {
public constructor(private readonly schemasService: SchemasService) {}
@Version('1')
@Get()
@ApiOperation({
summary: 'Fetch a list of schemas',
description: 'This call provides a list of schemas for a given tenant',
})
@ApiQuery({ name: 'tenantId', required: true })
@ApiResponse({
status: HttpStatus.OK,
description: 'Schemas fetched successfully',
content: {
// TBD
},
})
@ApiResponse({
status: HttpStatus.NOT_FOUND,
description: 'Tenant not found',
content: {
// TBD
},
})
@ApiResponse({
status: HttpStatus.INTERNAL_SERVER_ERROR,
description: 'Internal server error',
content: {
// TBD
},
})
public getAll(
@Query() { tenantId }: TenantIdParam,
): Observable<EventAnonCredsSchemasGetAll['data']> {
return this.schemasService.getAll({
tenantId,
});
}
@Version('1')
@Get(':schemaId')
@ApiOperation({
summary: 'Fetch a schema by id',
description:
'This call allows you to retrieve schema data for a given tenant by specifying the `schemaId`.',
})
@ApiParam({ name: 'schemaId', required: true })
@ApiQuery({ name: 'tenantId', required: true })
@ApiResponse({
status: HttpStatus.OK,
description: 'Schema fetched successfully',
content: {
// TBD
},
})
@ApiResponse({
status: HttpStatus.NOT_FOUND,
description: 'Tenant not found',
content: {
// TBD
},
})
@ApiResponse({
status: HttpStatus.NOT_FOUND,
description: 'Schema not found',
content: {
// TBD
},
})
@ApiResponse({
status: HttpStatus.INTERNAL_SERVER_ERROR,
description: 'Internal server error',
content: {
// TBD
},
})
public getById(
@Param() { schemaId }: GetByIdParams,
@Query() { tenantId }: TenantIdParam,
): Observable<EventAnonCredsSchemasGetById['data']> {
return this.schemasService
.getById({
tenantId,
schemaId,
})
.pipe(
switchMap((schema) => {
if (schema === null) {
throw new NotFoundException(`Schema with id ${schemaId} not found`);
}
return of(schema);
}),
);
}
@Version('1')
@Post()
@ApiOperation({
summary: 'Register a new schema',
description:
'This call provides the capability to create new schema on ledger by name, author, version, schema attributes and type. Later this schema can be used to issue new credential definition. This call returns an information about created schema.',
})
@ApiQuery({ name: 'tenantId', required: true })
@ApiBody({ type: RegisterSchemaPayload })
@ApiResponse({
status: HttpStatus.CREATED,
description: 'Schema registered successfully',
content: {
'application/json': {},
},
})
@ApiResponse({
status: HttpStatus.NOT_FOUND,
description: 'Tenant not found',
content: {
'application/json': {},
},
})
@ApiResponse({
status: HttpStatus.BAD_REQUEST,
description: 'All fields are required for schema registration',
content: {
'application/json': {},
},
})
@ApiResponse({
status: HttpStatus.CONFLICT,
description: 'Schema already exists',
content: {
'application/json': {},
},
})
@ApiResponse({
status: HttpStatus.INTERNAL_SERVER_ERROR,
description: 'Internal server error',
content: {
'application/json': {},
},
})
public register(
@Query() { tenantId }: TenantIdParam,
@Body() payload: RegisterSchemaPayload,
): Observable<EventAnonCredsSchemasRegister['data']> {
return this.schemasService.register({
...payload,
tenantId,
});
}
}