diff --git a/indexers/api/src/app.module.ts b/indexers/api/src/app.module.ts index 905225b5..44d89b20 100644 --- a/indexers/api/src/app.module.ts +++ b/indexers/api/src/app.module.ts @@ -15,8 +15,6 @@ import { ApiDailyUsage } from './entities/users/api-daily-usage.entity'; import { ApiKey } from './entities/users/api-key.entity'; import { ApiMonthlyUsage } from './entities/users/api-monthly-usage.entity'; import { Profile } from './entities/users/profile.entity'; -import { BlocksService } from './services/blocks.service'; -import { ExtrinsicsService } from './services/extrinsics.service'; @Module({ imports: [ @@ -59,6 +57,6 @@ import { ExtrinsicsService } from './services/extrinsics.service'; ExtrinsicsController, AccountsController, ], - providers: [AppService, BlocksService, ExtrinsicsService, ApiKeyStrategy], + providers: [AppService, ApiKeyStrategy], }) export class AppModule {} diff --git a/indexers/api/src/app.service.ts b/indexers/api/src/app.service.ts index 927d7cca..1302edf1 100644 --- a/indexers/api/src/app.service.ts +++ b/indexers/api/src/app.service.ts @@ -3,6 +3,6 @@ import { Injectable } from '@nestjs/common'; @Injectable() export class AppService { getHello(): string { - return 'Hello World!'; + return 'Hello Autonomys World!'; } } diff --git a/indexers/api/src/config/typeorm.config.ts b/indexers/api/src/config/typeorm.config.ts deleted file mode 100644 index fff72695..00000000 --- a/indexers/api/src/config/typeorm.config.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { ConfigService } from '@nestjs/config'; -import { TypeOrmModuleOptions } from '@nestjs/typeorm'; - -export const getTypeOrmConfig = ( - configService: ConfigService, -): TypeOrmModuleOptions => ({ - type: 'postgres', - host: configService.get('DB_HOST'), - port: configService.get('DB_PORT'), - username: configService.get('DB_USER'), - password: configService.get('DB_PASSWORD'), - database: configService.get('DB_DATABASE'), - entities: [__dirname + '/../**/*.entity{.ts,.js}'], - synchronize: false, - schema: 'users', -}); diff --git a/indexers/api/src/controllers/accounts.controller.ts b/indexers/api/src/controllers/accounts.controller.ts index c799301c..d92cdbcc 100644 --- a/indexers/api/src/controllers/accounts.controller.ts +++ b/indexers/api/src/controllers/accounts.controller.ts @@ -21,6 +21,7 @@ export class AccountsController { @ApiResponse({ status: 200, description: 'Account details retrieved successfully', + type: Accounts, }) @ApiResponse({ status: 404, description: 'Account not found' }) async getAccountById(@Param('accountId') accountId: string) { @@ -28,9 +29,8 @@ export class AccountsController { where: { id: accountId }, }); - if (!account) { + if (!account) throw new NotFoundException(`Account with ID ${accountId} not found`); - } return account; } diff --git a/indexers/api/src/controllers/blocks.controller.ts b/indexers/api/src/controllers/blocks.controller.ts index bf3dac83..e5ffc4e5 100644 --- a/indexers/api/src/controllers/blocks.controller.ts +++ b/indexers/api/src/controllers/blocks.controller.ts @@ -1,12 +1,16 @@ import { Controller, Get, NotFoundException, Param } from '@nestjs/common'; import { ApiOperation, ApiParam, ApiResponse, ApiTags } from '@nestjs/swagger'; +import { InjectRepository } from '@nestjs/typeorm'; +import { Repository } from 'typeorm'; import { Blocks } from '../entities/consensus/blocks.entity'; -import { BlocksService } from '../services/blocks.service'; @ApiTags('Blocks') @Controller('blocks') export class BlocksController { - constructor(private readonly blocksService: BlocksService) {} + constructor( + @InjectRepository(Blocks) + private blocksRepository: Repository, + ) {} @Get('latest') @ApiOperation({ @@ -20,7 +24,10 @@ export class BlocksController { }) @ApiResponse({ status: 404, description: 'No blocks found' }) async getLatestBlock(): Promise { - return this.blocksService.findLatest(); + return this.blocksRepository + .createQueryBuilder('blocks') + .orderBy('blocks.height', 'DESC') + .getOne(); } @Get(':height') @@ -36,11 +43,12 @@ export class BlocksController { }) @ApiResponse({ status: 404, description: 'Block not found' }) async getBlockByHeight(@Param('height') height: string) { - const block = await this.blocksService.findByHeight(Number(height)); + const block = await this.blocksRepository.findOne({ + where: { height: Number(height) }, + }); - if (!block) { + if (!block) throw new NotFoundException(`Block with height ${height} not found`); - } return block; } diff --git a/indexers/api/src/controllers/extrinsics.controller.ts b/indexers/api/src/controllers/extrinsics.controller.ts index 09a97c02..2eed7c3b 100644 --- a/indexers/api/src/controllers/extrinsics.controller.ts +++ b/indexers/api/src/controllers/extrinsics.controller.ts @@ -1,20 +1,30 @@ -import { Controller, Get, Param, UseGuards } from '@nestjs/common'; +import { + Controller, + Get, + NotFoundException, + Param, + UseGuards, +} from '@nestjs/common'; import { ApiOperation, ApiResponse, ApiSecurity, ApiTags, } from '@nestjs/swagger'; +import { InjectRepository } from '@nestjs/typeorm'; +import { Repository } from 'typeorm'; import { ApiKeyGuard } from '../auth/api-key.guard'; import { Extrinsics } from '../entities/consensus/extrinsics.entity'; -import { ExtrinsicsService } from '../services/extrinsics.service'; @ApiTags('Extrinsics') @Controller('extrinsics') @UseGuards(ApiKeyGuard) @ApiSecurity('X-API-KEY') export class ExtrinsicsController { - constructor(private readonly extrinsicsService: ExtrinsicsService) {} + constructor( + @InjectRepository(Extrinsics) + private extrinsicsRepository: Repository, + ) {} @Get(':hash') @ApiOperation({ summary: 'Get extrinsic by hash' }) @@ -25,6 +35,13 @@ export class ExtrinsicsController { }) @ApiResponse({ status: 404, description: 'Extrinsic not found' }) async findByHash(@Param('hash') hash: string): Promise { - return this.extrinsicsService.findByHash(hash); + const extrinsic = await this.extrinsicsRepository.findOne({ + where: { hash }, + }); + + if (!extrinsic) + throw new NotFoundException(`Extrinsic with hash ${hash} not found`); + + return extrinsic; } } diff --git a/indexers/api/src/services/blocks.service.ts b/indexers/api/src/services/blocks.service.ts deleted file mode 100644 index e86f9880..00000000 --- a/indexers/api/src/services/blocks.service.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { Injectable } from '@nestjs/common'; -import { InjectRepository } from '@nestjs/typeorm'; -import { Repository } from 'typeorm'; -import { Blocks } from '../entities/consensus/blocks.entity'; - -@Injectable() -export class BlocksService { - constructor( - @InjectRepository(Blocks) - private blocksRepository: Repository, - ) {} - - async findLatest(): Promise { - return this.blocksRepository - .createQueryBuilder('blocks') - .orderBy('blocks.height', 'DESC') - .getOne(); - } - - async findByHeight(height: number): Promise { - return this.blocksRepository.findOne({ - where: { height }, - }); - } -} diff --git a/indexers/api/src/services/extrinsics.service.ts b/indexers/api/src/services/extrinsics.service.ts deleted file mode 100644 index a35f8e59..00000000 --- a/indexers/api/src/services/extrinsics.service.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { Injectable, NotFoundException } from '@nestjs/common'; -import { InjectRepository } from '@nestjs/typeorm'; -import { Repository } from 'typeorm'; -import { Extrinsics } from '../entities/consensus/extrinsics.entity'; - -@Injectable() -export class ExtrinsicsService { - constructor( - @InjectRepository(Extrinsics) - private readonly extrinsicsRepository: Repository, - ) {} - - async findByHash(hash: string): Promise { - const extrinsic = await this.extrinsicsRepository.findOne({ - where: { hash }, - }); - - if (!extrinsic) { - throw new NotFoundException(`Extrinsic with hash ${hash} not found`); - } - - return extrinsic; - } -}