diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..ff6a192 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,21 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + + { + "name": "Lunch Kraken", + "type": "node", + "request": "launch", + "runtimeExecutable": "${workspaceFolder}/node_modules/@nestjs/cli/bin/nest.js", + "runtimeArgs": ["start", "--watch"], + "cwd": "${workspaceRoot}", + "console": "integratedTerminal", + "restart": true, + "autoAttachChildProcesses": true + } + ] + } + \ No newline at end of file diff --git a/src/app.module.ts b/src/app.module.ts index 3713021..cd39cbb 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -2,6 +2,7 @@ import { Module } from '@nestjs/common'; import { ConfigModule } from '@nestjs/config'; import AuthModule from './modules/auth/auth.module'; +import { ServicesConfigModule } from './modules/config/config.module'; import HealthModule from './modules/health/health.module'; import ServiceRegistryModule from './modules/service-registry/service-registry.module'; import { UserModule } from './modules/users/user.module'; @@ -17,6 +18,7 @@ import { SharedModule } from './shared/shared.module'; UserModule, HealthModule, ServiceRegistryModule, + ServicesConfigModule, ], controllers: [], providers: [], diff --git a/src/common/abstract.entity.ts b/src/common/abstract.entity.ts index 3fdb90a..f6d7643 100644 --- a/src/common/abstract.entity.ts +++ b/src/common/abstract.entity.ts @@ -1,5 +1,5 @@ /* eslint-disable max-classes-per-file */ -import { CreateDateColumn, ObjectId, ObjectIdColumn, UpdateDateColumn } from 'typeorm'; +import { CreateDateColumn, ObjectId, ObjectIdColumn, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm'; import type { Constructor } from '../types'; import type { AbstractDto } from './dto/abstract.dto'; @@ -13,7 +13,7 @@ import type { AbstractDto } from './dto/abstract.dto'; * otherwise just delete and use your own entity. */ export interface IAbstractEntity { - id: ObjectId; + _id: ObjectId; createdAt: Date; updatedAt: Date; @@ -23,8 +23,9 @@ export interface IAbstractEntity { export abstract class AbstractEntity implements IAbstractEntity { - @ObjectIdColumn() // MongoDB ObjectId - id: ObjectId; + @PrimaryGeneratedColumn() + @ObjectIdColumn() + _id: ObjectId; @CreateDateColumn({ type: 'timestamp', @@ -61,10 +62,10 @@ export abstract class AbstractEntity) { - const { id, createdAt, updatedAt } = item; + const { _id: id, createdAt, updatedAt } = item; if (id) { - this.id = id; + this._id = id; } this.createdAt = createdAt ? new Date(createdAt) : this.createdAt; diff --git a/src/common/dto/abstract.dto.ts b/src/common/dto/abstract.dto.ts index 30b0f0c..d6eaf56 100644 --- a/src/common/dto/abstract.dto.ts +++ b/src/common/dto/abstract.dto.ts @@ -14,7 +14,7 @@ export class AbstractDto { constructor(entity: AbstractEntity, options?: { excludeFields?: boolean }) { if (!options?.excludeFields) { - this.id = entity.id.toString(); + this.id = entity._id.toString(); this.createdAt = entity.createdAt; this.updatedAt = entity.updatedAt; } diff --git a/src/common/dto/page-options.dto.ts b/src/common/dto/page-options.dto.ts index a6a1c02..4c31659 100644 --- a/src/common/dto/page-options.dto.ts +++ b/src/common/dto/page-options.dto.ts @@ -1,12 +1,9 @@ -import { Order } from '../../constants'; -import { - EnumFieldOptional, - NumberFieldOptional, - StringFieldOptional, -} from '../../decorators'; +import { Order } from '../../../src/constant/constants'; +import { EnumFieldOptional, NumberFieldOptional, StringFieldOptional } from '../../decorators'; export class PageOptionsDto { @EnumFieldOptional(() => Order, { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment default: Order.ASC, }) readonly order: Order = Order.ASC; diff --git a/src/constant/constants.ts b/src/constant/constants.ts new file mode 100644 index 0000000..fbac893 --- /dev/null +++ b/src/constant/constants.ts @@ -0,0 +1,3 @@ +export enum Order { + ASC = 'ASC', +} diff --git a/src/main.ts b/src/main.ts index e19ef56..e2a59b4 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,3 +1,4 @@ +import { ReflectionService } from '@grpc/reflection'; import { ClassSerializerInterceptor, HttpStatus, UnprocessableEntityException, ValidationPipe } from '@nestjs/common'; import { NestFactory, Reflector } from '@nestjs/core'; import type { MicroserviceOptions } from '@nestjs/microservices'; @@ -6,7 +7,6 @@ import type { NestExpressApplication } from '@nestjs/platform-express'; import { ExpressAdapter } from '@nestjs/platform-express'; import compression from 'compression'; import morgan from 'morgan'; -import { ReflectionService } from '@grpc/reflection'; import { AppModule } from './app.module'; import { setupSwagger } from './setup-swagger'; diff --git a/src/modules/auth/auth.service.ts b/src/modules/auth/auth.service.ts index 2fe9d2f..58d2d7e 100644 --- a/src/modules/auth/auth.service.ts +++ b/src/modules/auth/auth.service.ts @@ -31,7 +31,7 @@ export default class AuthService { if (isPasswordOk) { return { - id: user.id.toString(), + id: user._id.toString(), email: user.email, }; } diff --git a/src/modules/auth/strategies/jwt.strategy.ts b/src/modules/auth/strategies/jwt.strategy.ts index 88db05c..865593a 100644 --- a/src/modules/auth/strategies/jwt.strategy.ts +++ b/src/modules/auth/strategies/jwt.strategy.ts @@ -18,7 +18,7 @@ export default class JwtStrategy extends PassportStrategy(Strategy) { validate(payload: UserEntity): IJwtStrategyValidate { return { - id: payload.id.toString(), + id: payload._id.toString(), email: payload.email, }; } diff --git a/src/modules/config/config.module.ts b/src/modules/config/config.module.ts new file mode 100644 index 0000000..3dfa34e --- /dev/null +++ b/src/modules/config/config.module.ts @@ -0,0 +1,16 @@ +import { Module } from '@nestjs/common'; +import { TypeOrmModule } from '@nestjs/typeorm'; + +import { ConfigRepository } from './config.repository'; +import { ConfigService } from './config.service'; +import { ServiceConfigController } from './controllers/config.controller'; +import { ConfigGrpcController } from './controllers/config-grpc.controller'; +import { ConfigEntity } from './entities/config.entity'; + +@Module({ + imports: [TypeOrmModule.forFeature([ConfigEntity])], + providers: [ConfigService, ConfigRepository], + controllers: [ServiceConfigController, ConfigGrpcController], + exports: [ConfigService], +}) +export class ServicesConfigModule {} diff --git a/src/modules/config/config.repository.ts b/src/modules/config/config.repository.ts new file mode 100644 index 0000000..23fe606 --- /dev/null +++ b/src/modules/config/config.repository.ts @@ -0,0 +1,30 @@ +import { Injectable } from '@nestjs/common'; +import { InjectRepository } from '@nestjs/typeorm'; +import type { DeepPartial, FindManyOptions, FindOneOptions } from 'typeorm'; +import { MongoRepository } from 'typeorm'; + +import { ConfigEntity } from './entities/config.entity'; + +@Injectable() +export class ConfigRepository { + constructor( + @InjectRepository(ConfigEntity) + private repository: MongoRepository, + ) {} + + async findAll(options?: FindManyOptions | undefined) { + return this.repository.find({ ...options }); + } + + async findOne(options?: FindOneOptions) { + return this.repository.findOne({ ...options }); + } + + async save(data: ConfigEntity) { + return this.repository.save(data); + } + + create(entityLike: DeepPartial) { + return this.repository.create(entityLike); + } +} diff --git a/src/modules/config/config.service.ts b/src/modules/config/config.service.ts new file mode 100644 index 0000000..3e7d881 --- /dev/null +++ b/src/modules/config/config.service.ts @@ -0,0 +1,30 @@ +import { Injectable } from '@nestjs/common'; + +import { ConfigRepository } from './config.repository'; +import type { UpdateConfigDto } from './dto/update-config.dto'; + +@Injectable() +export class ConfigService { + constructor(private readonly configRepo: ConfigRepository) {} + + async getConfig() { + return this.configRepo.findOne(); + } + + async update(props: UpdateConfigDto) { + let config = await this.getConfig(); + console.log('AAAAA'); + if (!config) { + config = this.configRepo.create(props); + } + + console.log('BBBBBBB'); + + + config.assign(props); + console.log('CCCCCC'); + + + return this.configRepo.save(config); + } +} diff --git a/src/modules/config/controllers/config-grpc.controller.ts b/src/modules/config/controllers/config-grpc.controller.ts new file mode 100644 index 0000000..79b9454 --- /dev/null +++ b/src/modules/config/controllers/config-grpc.controller.ts @@ -0,0 +1,17 @@ +import { Controller } from '@nestjs/common'; + +import type { getConfigResponse } from '../../../../src/modules/grpc/gen/ts/kraken'; +import { KrakenConfigServiceControllerMethods } from '../../../../src/modules/grpc/gen/ts/kraken'; +import { ConfigService } from '../config.service'; + +@Controller() +@KrakenConfigServiceControllerMethods() +export class ConfigGrpcController { + constructor(private readonly configService: ConfigService) {} + + async getConfig(): Promise { + const config = await this.configService.getConfig(); + + return config?.toDto() as getConfigResponse; + } +} diff --git a/src/modules/config/controllers/config.controller.ts b/src/modules/config/controllers/config.controller.ts new file mode 100644 index 0000000..9ac7038 --- /dev/null +++ b/src/modules/config/controllers/config.controller.ts @@ -0,0 +1,23 @@ +import { Body, Controller, Get, Patch } from '@nestjs/common'; +import { ApiTags } from '@nestjs/swagger'; + +import { ConfigService } from '../config.service'; +import { UpdateConfigDto } from '../dto/update-config.dto'; + +@Controller('service-config') +@ApiTags('Service config') +export class ServiceConfigController { + constructor(private readonly configService: ConfigService) {} + + @Patch() + async update(@Body() props: UpdateConfigDto) { + return this.configService.update(props); + } + + @Get() + async get() { + const config = await this.configService.getConfig(); + + return config?.toDto(); + } +} diff --git a/src/modules/config/dto/config.dto.ts b/src/modules/config/dto/config.dto.ts new file mode 100644 index 0000000..cdb6ad6 --- /dev/null +++ b/src/modules/config/dto/config.dto.ts @@ -0,0 +1,101 @@ +import { ApiProperty } from '@nestjs/swagger'; +import { IsArray, IsOptional, IsString } from 'class-validator'; + +import { AbstractDto } from '../../../common/dto/abstract.dto'; +import type { ConfigEntity } from '../entities/config.entity'; +import { Retention } from './retention.dto'; + +export class ConfigDto extends AbstractDto { + @ApiProperty() + @IsString() + name: string; + + @ApiProperty() + @IsString() + description: string; + + @ApiProperty() + @IsString() + pubkey: string; + + @ApiProperty() + @IsString() + contact: string; + + @ApiProperty() + @IsString() + software: string; + + @ApiProperty({ type: [Number] }) + @IsArray() + supportedNips: number[]; + + @ApiProperty() + @IsString() + version: string; + + @ApiProperty({ type: [String] }) + @IsArray() + relayCountries: string[]; + + @ApiProperty({ type: [String] }) + @IsArray() + languageTags: string[]; + + @ApiProperty({ type: [String] }) + @IsArray() + tags: string[]; + + @ApiProperty({ required: false }) + @IsOptional() + @IsString() + postingPolicy?: string; + + @ApiProperty({ required: false }) + @IsOptional() + @IsString() + paymentsUrl?: string; + + @ApiProperty({ required: false }) + @IsOptional() + @IsString() + icon?: string; + + @ApiProperty({ required: false }) + @IsOptional() + @IsString() + url?: string; + + @ApiProperty({ type: () => Retention, required: false }) + @IsOptional() + retention?: Retention; + + // @ApiProperty({ type: () => FeesClass, required: false }) + // @IsOptional() + // fees?: FeesClass; + + constructor(e: ConfigEntity) { + super(e); + + this.name = e.name; + this.description = e.description; + this.pubkey = e.pubkey; + this.contact = e.contact; + this.software = e.software; + this.supportedNips = e.supportedNips; + this.version = e.version; + this.relayCountries = e.relayCountries; + this.languageTags = e.languageTags; + this.tags = e.tags; + this.postingPolicy = e.postingPolicy; + this.paymentsUrl = e.paymentsUrl; + this.icon = e.icon; + this.url = e.url; + this.retention = { + count: e.retention?.count, + kinds: e.retention?.kinds, + time: e.retention?.time, + }; + // this.fees = e.fees; + } +} diff --git a/src/modules/config/dto/fees.dto.ts b/src/modules/config/dto/fees.dto.ts new file mode 100644 index 0000000..1145adf --- /dev/null +++ b/src/modules/config/dto/fees.dto.ts @@ -0,0 +1,29 @@ +export interface ISubscription { + amount: number; + + unit: string; + + period: number; +} + +export interface IPublication { + kinds: number[]; + + amount: number; + + unit: string; +} + +export interface IAdmission { + amount: number; + + unit: number; +} + +export interface IFees { + subscription: ISubscription[]; + + publication: IPublication[]; + + admission: IAdmission[]; +} diff --git a/src/modules/config/dto/retention.dto.ts b/src/modules/config/dto/retention.dto.ts new file mode 100644 index 0000000..b6221b4 --- /dev/null +++ b/src/modules/config/dto/retention.dto.ts @@ -0,0 +1,7 @@ +export class Retention { + time?: number; + + count?: number; + + kinds?: string; +} diff --git a/src/modules/config/dto/update-config.dto.ts b/src/modules/config/dto/update-config.dto.ts new file mode 100644 index 0000000..1792869 --- /dev/null +++ b/src/modules/config/dto/update-config.dto.ts @@ -0,0 +1,5 @@ +import { OmitType, PartialType } from '@nestjs/swagger'; + +import { ConfigDto } from './config.dto'; + +export class UpdateConfigDto extends PartialType(OmitType(ConfigDto, ['id', 'createdAt', 'updatedAt'] as const)) {} diff --git a/src/modules/config/entities/config.entity.ts b/src/modules/config/entities/config.entity.ts new file mode 100644 index 0000000..b7e0ca2 --- /dev/null +++ b/src/modules/config/entities/config.entity.ts @@ -0,0 +1,90 @@ +import { Column, Entity } from 'typeorm'; + +import { AbstractEntity } from '../../../../src/common/abstract.entity'; +import { ConfigDto } from '../dto/config.dto'; +import { Retention } from '../dto/retention.dto'; + +@Entity('config') +export class ConfigEntity extends AbstractEntity { + dtoClass = ConfigDto; + + @Column({ type: 'varchar' }) + name: string; + + @Column({ type: 'varchar' }) + description: string; + + @Column({ type: 'varchar' }) + pubkey: string; + + @Column({ type: 'varchar' }) + contact: string; + + @Column({ type: 'varchar' }) + software: string; + + @Column('simple-array') + supportedNips: number[]; + + @Column({ type: 'varchar' }) + version: string; + + @Column('simple-array') + relayCountries: string[]; + + @Column('simple-array') + languageTags: string[]; + + @Column('simple-array') + tags: string[]; + + @Column({ type: 'varchar', nullable: true }) + postingPolicy: string; + + @Column({ type: 'varchar', nullable: true }) + paymentsUrl: string; + + @Column({ type: 'varchar', nullable: true }) + icon: string; + + @Column({ type: 'varchar', nullable: true }) + url: string; + + @Column({ type: 'json', nullable: true }) + retention?: Retention; + + // @Column({ type: 'json', nullable: true }) + // fees: IFees; + + constructor(item?: Partial>) { + super(); + + if (!item) { + return; + } + + this.assign(item); + } + + // eslint-disable-next-line sonarjs/cognitive-complexity + assign(item: Partial>): void { + super.assign(item); + + this.name = item.name ?? this.name; + this.description = item.description ?? this.description; + this.pubkey = item.pubkey ?? this.pubkey; + this.contact = item.contact ?? this.contact; + this.software = item.software ?? this.software; + this.supportedNips = item.supportedNips ?? this.supportedNips; + this.version = item.version ?? this.version; + this.relayCountries = item.relayCountries ?? this.relayCountries; + this.languageTags = item.languageTags ?? this.languageTags; + this.tags = item.tags ?? this.tags; + this.postingPolicy = item.postingPolicy ?? this.postingPolicy; + this.paymentsUrl = item.paymentsUrl ?? this.paymentsUrl; + this.icon = item.icon ?? this.icon; + this.url = item.url ?? this.url; + // this.retention = item.retention ?? this.retention; + // this.fees = item.fees ?? this.fees; + } +} diff --git a/src/modules/grpc/gen/ts/kraken.ts b/src/modules/grpc/gen/ts/kraken.ts index b3d8c1b..f104b08 100644 --- a/src/modules/grpc/gen/ts/kraken.ts +++ b/src/modules/grpc/gen/ts/kraken.ts @@ -7,14 +7,17 @@ /* eslint-disable */ import { GrpcMethod, GrpcStreamMethod } from "@nestjs/microservices"; import { Observable } from "rxjs"; +import { Any } from "./google/protobuf/any"; export const protobufPackage = "kraken"; +/** Enum definitions */ export enum ServiceTypeEnum { RELAY = 0, UNRECOGNIZED = -1, } +/** Request and response messages */ export interface registerServiceRequest { url: string; heartbeatDurationInSec: number; @@ -26,31 +29,113 @@ export interface registerServiceResponse { message?: string | undefined; } +export interface EmptyRequest { +} + +/** Configuration messages */ +export interface getConfigResponse { + retention: Retention | undefined; + fees: Fees | undefined; + name: string; + description: string; + pubkey: string; + contact: string; + software: string; + supportedNips: number[]; + version: string; + relayCountries: string[]; + languageTags: string[]; + tags: string[]; + postingPolicy: string; + paymentsUrl: string; + icon: string; + url: string; +} + +/** Data structure messages */ +export interface Retention { + time: number; + count: number; + kinds: Any | undefined; +} + +export interface Subscription { + amount: number; + unit: string; + period: number; +} + +export interface Admission { + amount: number; + unit: string; +} + +export interface Publication { + kinds: number[]; + amount: number; + unit: string; +} + +export interface Fees { + subscription: Subscription[]; + publication: Publication[]; + admission: Admission[]; +} + export const KRAKEN_PACKAGE_NAME = "kraken"; -export interface KrakenServiceClient { +/** Service definition */ + +export interface KrakenServiceRegistryServiceClient { registerService(request: registerServiceRequest): Observable; } -export interface KrakenServiceController { +/** Service definition */ + +export interface KrakenServiceRegistryServiceController { registerService( request: registerServiceRequest, ): Promise | Observable | registerServiceResponse; } -export function KrakenServiceControllerMethods() { +export function KrakenServiceRegistryServiceControllerMethods() { return function (constructor: Function) { const grpcMethods: string[] = ["registerService"]; for (const method of grpcMethods) { const descriptor: any = Reflect.getOwnPropertyDescriptor(constructor.prototype, method); - GrpcMethod("KrakenService", method)(constructor.prototype[method], method, descriptor); + GrpcMethod("KrakenServiceRegistryService", method)(constructor.prototype[method], method, descriptor); + } + const grpcStreamMethods: string[] = []; + for (const method of grpcStreamMethods) { + const descriptor: any = Reflect.getOwnPropertyDescriptor(constructor.prototype, method); + GrpcStreamMethod("KrakenServiceRegistryService", method)(constructor.prototype[method], method, descriptor); + } + }; +} + +export const KRAKEN_SERVICE_REGISTRY_SERVICE_NAME = "KrakenServiceRegistryService"; + +export interface KrakenConfigServiceClient { + getConfig(request: EmptyRequest): Observable; +} + +export interface KrakenConfigServiceController { + getConfig(request: EmptyRequest): Promise | Observable | getConfigResponse; +} + +export function KrakenConfigServiceControllerMethods() { + return function (constructor: Function) { + const grpcMethods: string[] = ["getConfig"]; + for (const method of grpcMethods) { + const descriptor: any = Reflect.getOwnPropertyDescriptor(constructor.prototype, method); + GrpcMethod("KrakenConfigService", method)(constructor.prototype[method], method, descriptor); } const grpcStreamMethods: string[] = []; for (const method of grpcStreamMethods) { const descriptor: any = Reflect.getOwnPropertyDescriptor(constructor.prototype, method); - GrpcStreamMethod("KrakenService", method)(constructor.prototype[method], method, descriptor); + GrpcStreamMethod("KrakenConfigService", method)(constructor.prototype[method], method, descriptor); } }; } -export const KRAKEN_SERVICE_NAME = "KrakenService"; +export const KRAKEN_CONFIG_SERVICE_NAME = "KrakenConfigService"; diff --git a/src/modules/grpc/proto/kraken.proto b/src/modules/grpc/proto/kraken.proto index b1a3883..7f3fa3a 100644 --- a/src/modules/grpc/proto/kraken.proto +++ b/src/modules/grpc/proto/kraken.proto @@ -2,12 +2,20 @@ syntax = "proto3"; package kraken; -service KrakenService { +import "google/protobuf/any.proto"; + +// Service definition +service KrakenServiceRegistryService { rpc registerService (registerServiceRequest) returns (registerServiceResponse) {} } +service KrakenConfigService { + rpc getConfig (EmptyRequest) returns (getConfigResponse) {} +} + +// Request and response messages message registerServiceRequest { - string url = 1; + string url = 1; uint32 heartbeat_duration_in_sec = 2; ServiceTypeEnum type = 3; } @@ -17,6 +25,59 @@ message registerServiceResponse { optional string message = 2; } +message EmptyRequest {} + +// Configuration messages +message getConfigResponse { + Retention retention = 1; + Fees fees = 2; + string name = 3; + string description = 4; + string pubkey = 5; + string contact = 6; + string software = 7; + repeated int32 supported_nips = 8; + string version = 9; + repeated string relay_countries = 10; + repeated string language_tags = 11; + repeated string tags = 12; + string posting_policy = 13; + string payments_url = 14; + string icon = 15; + string url = 16; +} + +// Data structure messages +message Retention { + int32 time = 1; + int32 count = 2; + google.protobuf.Any kinds = 3; +} + +message Subscription { + int32 amount = 1; + string unit = 2; + int32 period = 3; +} + +message Admission { + int32 amount = 1; + string unit = 2; +} + +message Publication { + repeated int32 kinds = 1; + int32 amount = 2; + string unit = 3; +} + +message Fees { + repeated Subscription subscription = 1; + repeated Publication publication = 2; + repeated Admission admission = 3; +} + +// Enum definitions enum ServiceTypeEnum { RELAY = 0; -} \ No newline at end of file +} diff --git a/src/modules/service-registry/controllers/service-regsitry-grpc.controller.ts b/src/modules/service-registry/controllers/service-registry-grpc.controller.ts similarity index 61% rename from src/modules/service-registry/controllers/service-regsitry-grpc.controller.ts rename to src/modules/service-registry/controllers/service-registry-grpc.controller.ts index 5d454f0..9f066c8 100644 --- a/src/modules/service-registry/controllers/service-regsitry-grpc.controller.ts +++ b/src/modules/service-registry/controllers/service-registry-grpc.controller.ts @@ -1,17 +1,13 @@ import { Controller } from '@nestjs/common'; -import type { - KrakenServiceController, - registerServiceRequest, - registerServiceResponse, -} from '../../../../src/modules/grpc/gen/ts/kraken'; -import { KrakenServiceControllerMethods, ServiceTypeEnum } from '../../../../src/modules/grpc/gen/ts/kraken'; +import type { registerServiceRequest, registerServiceResponse } from '../../grpc/gen/ts/kraken'; +import { KrakenServiceRegistryServiceControllerMethods, ServiceTypeEnum } from '../../grpc/gen/ts/kraken'; import { ServiceType } from '../enums/service-types.enum'; -import ServiceRegistryService from '../service-registry.service'; +import ServiceRegistryService from '../services/service-registry.service'; -@KrakenServiceControllerMethods() +@KrakenServiceRegistryServiceControllerMethods() @Controller() -export default class ServiceRegistryGrpcController implements Partial { +export class ServiceRegistryGrpcController { constructor(private readonly serviceRegistryService: ServiceRegistryService) {} async registerService({ diff --git a/src/modules/service-registry/controllers/service-registry.controller.ts b/src/modules/service-registry/controllers/service-registry.controller.ts index 1297fd5..a208056 100644 --- a/src/modules/service-registry/controllers/service-registry.controller.ts +++ b/src/modules/service-registry/controllers/service-registry.controller.ts @@ -1,6 +1,6 @@ import { Controller, Get } from '@nestjs/common'; -import ServiceRegistryService from '../service-registry.service'; +import ServiceRegistryService from '../services/service-registry.service'; @Controller('service-registry') export default class ServiceRegistryController { diff --git a/src/modules/service-registry/service-registry.module.ts b/src/modules/service-registry/service-registry.module.ts index 77a03fb..ab20f95 100644 --- a/src/modules/service-registry/service-registry.module.ts +++ b/src/modules/service-registry/service-registry.module.ts @@ -2,15 +2,16 @@ import { Module } from '@nestjs/common'; import { TypeOrmModule } from '@nestjs/typeorm'; import ServiceRegistryController from './controllers/service-registry.controller'; -import ServiceRegistryGrpcController from './controllers/service-regsitry-grpc.controller'; +import { ServiceRegistryGrpcController } from './controllers/service-registry-grpc.controller'; import { ServiceRegistryEntity } from './entities/service-registry.entity'; import { ServiceRegistryRepository } from './service-registry.repository'; -import ServiceRegistryService from './service-registry.service'; -import ServiceRegistryHealthCheckService from './service-registry-health-check.service'; +import ServiceRegistryService from './services/service-registry.service'; +import ServiceRegistryHealthCheckService from './services/service-registry-health-check.service'; @Module({ imports: [TypeOrmModule.forFeature([ServiceRegistryEntity])], controllers: [ServiceRegistryController, ServiceRegistryGrpcController], providers: [ServiceRegistryService, ServiceRegistryRepository, ServiceRegistryHealthCheckService], + exports: [ServiceRegistryService], }) export default class ServiceRegistryModule {} diff --git a/src/modules/service-registry/service-registry-health-check.service.ts b/src/modules/service-registry/services/service-registry-health-check.service.ts similarity index 87% rename from src/modules/service-registry/service-registry-health-check.service.ts rename to src/modules/service-registry/services/service-registry-health-check.service.ts index 194168a..954903c 100644 --- a/src/modules/service-registry/service-registry-health-check.service.ts +++ b/src/modules/service-registry/services/service-registry-health-check.service.ts @@ -1,9 +1,9 @@ import type { OnModuleDestroy } from '@nestjs/common'; import { Injectable } from '@nestjs/common'; -import type { ServiceRegistryEntity } from './entities/service-registry.entity'; -import { ServiceStatus } from './enums/service-status.enum'; -import { ServiceRegistryRepository } from './service-registry.repository'; +import type { ServiceRegistryEntity } from '../entities/service-registry.entity'; +import { ServiceStatus } from '../enums/service-status.enum'; +import { ServiceRegistryRepository } from '../service-registry.repository'; import ServiceRegistryService from './service-registry.service'; @Injectable() @@ -46,7 +46,7 @@ export default class ServiceRegistryHealthCheckService implements OnModuleDestro void this.checkServiceHealth(service); }, service.heartbeatDurationInSec * 1000); - this.serviceIntervals.set(String(service.id), intervalId); + this.serviceIntervals.set(String(service._id), intervalId); } private async checkServiceHealth(service: ServiceRegistryEntity) { diff --git a/src/modules/service-registry/service-registry.service.ts b/src/modules/service-registry/services/service-registry.service.ts similarity index 73% rename from src/modules/service-registry/service-registry.service.ts rename to src/modules/service-registry/services/service-registry.service.ts index 262acc1..eeac243 100644 --- a/src/modules/service-registry/service-registry.service.ts +++ b/src/modules/service-registry/services/service-registry.service.ts @@ -2,9 +2,9 @@ import EventEmitter from 'node:events'; import { Injectable } from '@nestjs/common'; -import type RegisterServiceRegistry from './dtos/service-registry-register.dto'; -import { ServiceRegistryEntity } from './entities/service-registry.entity'; -import { ServiceRegistryRepository } from './service-registry.repository'; +import type RegisterServiceRegistry from '../dtos/service-registry-register.dto'; +import { ServiceRegistryEntity } from '../entities/service-registry.entity'; +import { ServiceRegistryRepository } from '../service-registry.repository'; @Injectable() // eslint-disable-next-line unicorn/prefer-event-target