Skip to content

Commit 549a4f8

Browse files
committed
transactions endpoint
Signed-off-by: simvalery <[email protected]>
1 parent 65bc0bc commit 549a4f8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1633
-839
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ runtime-data/
2323
.idea
2424

2525
logs/
26-
**/logs/
26+
**/logs/
27+
/.run/

api-gateway/src/api/service/contract.ts

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { ContractType, Permissions } from '@guardian/interfaces';
22
import { IAuthUser, PinoLogger } from '@guardian/common';
33
import { Body, Controller, Delete, Get, HttpCode, HttpStatus, Param, Post, Query, Req, Response } from '@nestjs/common';
4-
import { ApiInternalServerErrorResponse, ApiOkResponse, ApiCreatedResponse, ApiOperation, ApiExtraModels, ApiTags, ApiBody, ApiQuery, ApiParam, } from '@nestjs/swagger';
5-
import { ContractConfigDTO, ContractDTO, RetirePoolDTO, RetirePoolTokenDTO, RetireRequestDTO, RetireRequestTokenDTO, WiperRequestDTO, InternalServerErrorDTO, pageHeader } from '#middlewares';
6-
import { AuthUser, Auth } from '#auth';
7-
import { Guardians, UseCache, InternalException, EntityOwner, CacheService, getCacheKey } from '#helpers';
4+
import { ApiBody, ApiCreatedResponse, ApiExtraModels, ApiInternalServerErrorResponse, ApiOkResponse, ApiOperation, ApiParam, ApiQuery, ApiTags, } from '@nestjs/swagger';
5+
import { ContractConfigDTO, ContractDTO, InternalServerErrorDTO, pageHeader, RetirePoolDTO, RetirePoolTokenDTO, RetireRequestDTO, RetireRequestTokenDTO, TransactionDTO, WiperRequestDTO } from '#middlewares';
6+
import { Auth, AuthUser } from '#auth';
7+
import { CacheService, EntityOwner, getCacheKey, Guardians, InternalException, UseCache } from '#helpers';
88

99
/**
1010
* Contracts api
@@ -179,6 +179,52 @@ export class ContractsApi {
179179
}
180180
}
181181

182+
/**
183+
* Return all transactions for schema
184+
* @param user
185+
* @param contractId
186+
*/
187+
@Get('/:contractId/transactions')
188+
@Auth(
189+
Permissions.CONTRACTS_CONTRACT_READ,
190+
// UserRole.STANDARD_REGISTRY,
191+
// UserRole.AUDITOR ?,
192+
// UserRole.USER ?
193+
)
194+
@ApiOperation({
195+
summary: 'Return all transactions for contract.',
196+
description: 'Return all transactions for contract.',
197+
})
198+
@ApiParam({
199+
name: 'contractId',
200+
type: String,
201+
description: 'Contract identifier',
202+
required: true
203+
})
204+
@ApiOkResponse({
205+
description: 'Successful operation.',
206+
isArray: true,
207+
type: TransactionDTO
208+
})
209+
@ApiInternalServerErrorResponse({
210+
description: 'Internal server error.',
211+
type: InternalServerErrorDTO
212+
})
213+
@ApiExtraModels(TransactionDTO, InternalServerErrorDTO)
214+
@HttpCode(HttpStatus.OK)
215+
async getSchemaTransactions(
216+
@AuthUser() user: IAuthUser,
217+
@Param('contractId') contractId: string,
218+
): Promise<TransactionDTO[]> {
219+
try {
220+
const guardians = new Guardians();
221+
const owner = new EntityOwner(user);
222+
return await guardians.getTransactions(contractId, 'contract', owner);
223+
} catch (error) {
224+
await InternalException(error, this.logger);
225+
}
226+
}
227+
182228
/**
183229
* Get contract permissions
184230
*/

api-gateway/src/api/service/policy.ts

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { IAuthUser, PinoLogger, RunFunctionAsync } from '@guardian/common';
33
import { DocumentType, Permissions, PolicyHelper, TaskAction, UserRole } from '@guardian/interfaces';
44
import { Body, Controller, Delete, Get, HttpCode, HttpException, HttpStatus, Param, Post, Put, Query, Req, Response, UseInterceptors, Version } from '@nestjs/common';
55
import { ApiAcceptedResponse, ApiBody, ApiConsumes, ApiExtraModels, ApiInternalServerErrorResponse, ApiOkResponse, ApiOperation, ApiParam, ApiQuery, ApiServiceUnavailableResponse, ApiTags } from '@nestjs/swagger';
6-
import { BlockDTO, Examples, ExportMessageDTO, ImportMessageDTO, InternalServerErrorDTO, MigrationConfigDTO, pageHeader, PoliciesValidationDTO, PolicyCategoryDTO, PolicyDTO, PolicyPreviewDTO, PolicyTestDTO, PolicyValidationDTO, RunningDetailsDTO, ServiceUnavailableErrorDTO, TaskDTO } from '#middlewares';
7-
import { AnyFilesInterceptor, CacheService, EntityOwner, getCacheKey, InternalException, ONLY_SR, PolicyEngine, ProjectService, ServiceError, TaskManager, UploadedFiles, UseCache } from '#helpers';
6+
import { BlockDTO, Examples, ExportMessageDTO, ImportMessageDTO, InternalServerErrorDTO, MigrationConfigDTO, pageHeader, PoliciesValidationDTO, PolicyCategoryDTO, PolicyDTO, PolicyPreviewDTO, PolicyTestDTO, PolicyValidationDTO, RunningDetailsDTO, ServiceUnavailableErrorDTO, TaskDTO, TransactionDTO } from '#middlewares';
7+
import { AnyFilesInterceptor, CacheService, EntityOwner, getCacheKey, Guardians, InternalException, ONLY_SR, PolicyEngine, ProjectService, ServiceError, TaskManager, UploadedFiles, UseCache } from '#helpers';
88
import { CACHE, POLICY_REQUIRED_PROPS, PREFIXES } from '#constants';
99

1010
async function getOldResult(user: IAuthUser): Promise<PolicyDTO[]> {
@@ -398,6 +398,52 @@ export class PolicyApi {
398398
return task;
399399
}
400400

401+
/**
402+
* Return all transactions for schema
403+
* @param user
404+
* @param policyId
405+
*/
406+
@Get('/:policyId/transactions')
407+
@Auth(
408+
Permissions.POLICIES_POLICY_REVIEW,
409+
// UserRole.STANDARD_REGISTRY,
410+
// UserRole.AUDITOR ?,
411+
// UserRole.USER ?
412+
)
413+
@ApiOperation({
414+
summary: 'Return all transactions for policy.',
415+
description: 'Return all transactions for policy.',
416+
})
417+
@ApiParam({
418+
name: 'policyId',
419+
type: String,
420+
description: 'Policy identifier',
421+
required: true
422+
})
423+
@ApiOkResponse({
424+
description: 'Successful operation.',
425+
isArray: true,
426+
type: TransactionDTO
427+
})
428+
@ApiInternalServerErrorResponse({
429+
description: 'Internal server error.',
430+
type: InternalServerErrorDTO
431+
})
432+
@ApiExtraModels(TransactionDTO, InternalServerErrorDTO)
433+
@HttpCode(HttpStatus.OK)
434+
async getSchemaTransactions(
435+
@AuthUser() user: IAuthUser,
436+
@Param('policyId') policyId: string,
437+
): Promise<TransactionDTO[]> {
438+
try {
439+
const guardians = new Guardians();
440+
const owner = new EntityOwner(user);
441+
return await guardians.getTransactions(policyId, 'policy', owner);
442+
} catch (error) {
443+
await InternalException(error, this.logger);
444+
}
445+
}
446+
401447
/**
402448
* Delete policy
403449
*/

api-gateway/src/api/service/schema.ts

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ApiBody, ApiExtraModels, ApiInternalServerErrorResponse, ApiOkResponse,
44
import { Body, Controller, Delete, Get, HttpCode, HttpException, HttpStatus, Param, Post, Put, Query, Req, Response, Version } from '@nestjs/common';
55
import { Auth, AuthUser } from '#auth';
66
import { Client, ClientProxy, Transport } from '@nestjs/microservices';
7-
import { Examples, ExportSchemaDTO, InternalServerErrorDTO, MessageSchemaDTO, pageHeader, SchemaDTO, SystemSchemaDTO, TaskDTO, VersionSchemaDTO } from '#middlewares';
7+
import { Examples, ExportSchemaDTO, InternalServerErrorDTO, MessageSchemaDTO, pageHeader, SchemaDTO, SystemSchemaDTO, TaskDTO, TransactionDTO, VersionSchemaDTO } from '#middlewares';
88
import { CACHE, PREFIXES, SCHEMA_REQUIRED_PROPS } from '#constants';
99
import { CacheService, EntityOwner, getCacheKey, Guardians, InternalException, ONLY_SR, SchemaUtils, ServiceError, TaskManager, UseCache } from '#helpers';
1010
import process from 'process';
@@ -66,6 +66,52 @@ export class SingleSchemaApi {
6666
}
6767
}
6868

69+
/**
70+
* Return all transactions for schema
71+
* @param user
72+
* @param schemaId
73+
*/
74+
@Get('/:schemaId/transactions')
75+
@Auth(
76+
Permissions.SCHEMAS_SCHEMA_READ,
77+
// UserRole.STANDARD_REGISTRY,
78+
// UserRole.AUDITOR ?,
79+
// UserRole.USER ?
80+
)
81+
@ApiOperation({
82+
summary: 'Return all transactions for schema.',
83+
description: 'Return all transactions for schema.',
84+
})
85+
@ApiParam({
86+
name: 'schemaId',
87+
type: String,
88+
description: 'Schema identifier',
89+
required: true
90+
})
91+
@ApiOkResponse({
92+
description: 'Successful operation.',
93+
isArray: true,
94+
type: TransactionDTO
95+
})
96+
@ApiInternalServerErrorResponse({
97+
description: 'Internal server error.',
98+
type: InternalServerErrorDTO
99+
})
100+
@ApiExtraModels(TransactionDTO, InternalServerErrorDTO)
101+
@HttpCode(HttpStatus.OK)
102+
async getSchemaTransactions(
103+
@AuthUser() user: IAuthUser,
104+
@Param('schemaId') schemaId: string,
105+
): Promise<TransactionDTO[]> {
106+
try {
107+
const guardians = new Guardians();
108+
const owner = new EntityOwner(user);
109+
return await guardians.getTransactions(schemaId, 'schema', owner);
110+
} catch (error) {
111+
await InternalException(error, this.logger);
112+
}
113+
}
114+
69115
/**
70116
* Returns all parent schemas.
71117
*/

api-gateway/src/api/service/tokens.ts

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { Guardians, PolicyEngine, TaskManager, ServiceError, InternalException, ONLY_SR, parseInteger, EntityOwner, getCacheKey, CacheService } from '#helpers';
1+
import { CacheService, EntityOwner, getCacheKey, Guardians, InternalException, ONLY_SR, parseInteger, PolicyEngine, ServiceError, TaskManager } from '#helpers';
22
import { IOwner, IToken, Permissions, TaskAction, UserPermissions } from '@guardian/interfaces';
33
import { IAuthUser, PinoLogger, RunFunctionAsync } from '@guardian/common';
44
import { Body, Controller, Delete, Get, HttpCode, HttpException, HttpStatus, Param, Post, Put, Query, Req, Response, Version } from '@nestjs/common';
5-
import { AuthUser, Auth } from '#auth';
6-
import { ApiInternalServerErrorResponse, ApiOkResponse, ApiOperation, ApiExtraModels, ApiTags, ApiParam, ApiBody, ApiQuery } from '@nestjs/swagger';
7-
import { Examples, InternalServerErrorDTO, TaskDTO, TokenDTO, TokenInfoDTO, pageHeader } from '#middlewares';
5+
import { Auth, AuthUser } from '#auth';
6+
import { ApiBody, ApiExtraModels, ApiInternalServerErrorResponse, ApiOkResponse, ApiOperation, ApiParam, ApiQuery, ApiTags } from '@nestjs/swagger';
7+
import { Examples, InternalServerErrorDTO, pageHeader, TaskDTO, TokenDTO, TokenInfoDTO, TransactionDTO } from '#middlewares';
88
import { TOKEN_REQUIRED_PROPS } from '#constants';
99

1010
/**
@@ -306,6 +306,52 @@ export class TokensApi {
306306
}
307307
}
308308

309+
/**
310+
* Return all transactions for token
311+
* @param user
312+
* @param tokenId
313+
*/
314+
@Get('/:tokenId/transactions')
315+
@Auth(
316+
Permissions.POLICIES_POLICY_REVIEW,
317+
// UserRole.STANDARD_REGISTRY,
318+
// UserRole.AUDITOR ?,
319+
// UserRole.USER ?
320+
)
321+
@ApiOperation({
322+
summary: 'Return all transactions for policy.',
323+
description: 'Return all transactions for policy.',
324+
})
325+
@ApiParam({
326+
name: 'tokenId',
327+
type: String,
328+
description: 'Policy identifier',
329+
required: true
330+
})
331+
@ApiOkResponse({
332+
description: 'Successful operation.',
333+
isArray: true,
334+
type: TransactionDTO
335+
})
336+
@ApiInternalServerErrorResponse({
337+
description: 'Internal server error.',
338+
type: InternalServerErrorDTO
339+
})
340+
@ApiExtraModels(TransactionDTO, InternalServerErrorDTO)
341+
@HttpCode(HttpStatus.OK)
342+
async getSchemaTransactions(
343+
@AuthUser() user: IAuthUser,
344+
@Param('tokenId') tokenId: string,
345+
): Promise<TransactionDTO[]> {
346+
try {
347+
const guardians = new Guardians();
348+
const owner = new EntityOwner(user);
349+
return await guardians.getTransactions(tokenId, 'token', owner);
350+
} catch (error) {
351+
await InternalException(error, this.logger);
352+
}
353+
}
354+
309355
/**
310356
* Creates a new token
311357
*/

api-gateway/src/helpers/guardians.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,9 @@ import {
2727
SchemaNode,
2828
SuggestionsOrderPriority
2929
} from '@guardian/interfaces';
30-
import { IAuthUser, NatsService } from '@guardian/common';
30+
import { IAuthUser, IMetadataItem, NatsService } from '@guardian/common';
3131
import { NewTask } from './task-manager.js';
32-
import {
33-
ModuleDTO,
34-
TagDTO,
35-
ThemeDTO,
36-
TokenDTO,
37-
ToolDTO,
38-
StatisticDefinitionDTO,
39-
StatisticAssessmentDTO,
40-
StatisticAssessmentRelationshipsDTO,
41-
StatisticDefinitionRelationshipsDTO,
42-
SchemaRuleDTO,
43-
SchemaRuleRelationshipsDTO,
44-
SchemaRuleDataDTO
45-
} from '#middlewares';
32+
import { ModuleDTO, SchemaRuleDataDTO, SchemaRuleDTO, SchemaRuleRelationshipsDTO, StatisticAssessmentDTO, StatisticAssessmentRelationshipsDTO, StatisticDefinitionDTO, StatisticDefinitionRelationshipsDTO, TagDTO, ThemeDTO, TokenDTO, ToolDTO } from '#middlewares';
4633

4734
/**
4835
* Filters type
@@ -620,6 +607,17 @@ export class Guardians extends NatsService {
620607
return await this.sendMessage(MessageAPI.GET_SCHEMA_PARENTS, { id, owner });
621608
}
622609

610+
/**
611+
* Get schema transactions
612+
* @param id Schema identifier
613+
* @param type
614+
* @param owner
615+
* @returns Schemas
616+
*/
617+
public async getTransactions(id: string, type: string, owner: IOwner): Promise<IMetadataItem[]> {
618+
return await this.sendMessage(MessageAPI.GET_TRANSACTIONS, {id, owner, type});
619+
}
620+
623621
/**
624622
* Get schema tree
625623
* @param id Id

api-gateway/src/middlewares/validation/schemas/schemas.dto.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,21 @@ import { IsIn, IsNotEmpty, IsObject, IsOptional, IsString } from 'class-validato
33
import { SchemaCategory, SchemaEntity, SchemaStatus, UserRole } from '@guardian/interfaces';
44
import { Examples } from '../examples.js';
55

6+
export class TransactionDTO{
7+
@ApiProperty({
8+
type: 'string',
9+
})
10+
@IsString()
11+
type: string;
12+
13+
// @ApiProperty({
14+
// type: 'object',
15+
// })
16+
// @IsOptional()
17+
// @IsString()
18+
[key: string]: any;
19+
}
20+
621
export class SchemaDTO {
722
@ApiProperty({
823
type: 'string',
@@ -228,4 +243,4 @@ export class MessageSchemaDTO {
228243
@IsString()
229244
@IsNotEmpty()
230245
messageId: string;
231-
}
246+
}

0 commit comments

Comments
 (0)