-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
] | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export enum Order { | ||
ASC = 'ASC', | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ConfigEntity>, | ||
) {} | ||
|
||
async findAll(options?: FindManyOptions<ConfigEntity> | undefined) { | ||
Check failure on line 15 in src/modules/config/config.repository.ts GitHub Actions / ESLintsrc/modules/config/config.repository.ts#L15
|
||
return this.repository.find({ ...options }); | ||
Check failure on line 16 in src/modules/config/config.repository.ts GitHub Actions / ESLintsrc/modules/config/config.repository.ts#L16
Check failure on line 16 in src/modules/config/config.repository.ts GitHub Actions / ESLintsrc/modules/config/config.repository.ts#L16
|
||
} | ||
|
||
async findOne(options?: FindOneOptions<ConfigEntity>) { | ||
return this.repository.findOne({ ...options }); | ||
Check failure on line 20 in src/modules/config/config.repository.ts GitHub Actions / ESLintsrc/modules/config/config.repository.ts#L20
Check failure on line 20 in src/modules/config/config.repository.ts GitHub Actions / ESLintsrc/modules/config/config.repository.ts#L20
|
||
} | ||
|
||
async save(data: ConfigEntity) { | ||
return this.repository.save(data); | ||
Check failure on line 24 in src/modules/config/config.repository.ts GitHub Actions / ESLintsrc/modules/config/config.repository.ts#L24
Check failure on line 24 in src/modules/config/config.repository.ts GitHub Actions / ESLintsrc/modules/config/config.repository.ts#L24
|
||
} | ||
|
||
create(entityLike: DeepPartial<ConfigEntity>) { | ||
return this.repository.create(entityLike); | ||
Check failure on line 28 in src/modules/config/config.repository.ts GitHub Actions / ESLintsrc/modules/config/config.repository.ts#L28
Check failure on line 28 in src/modules/config/config.repository.ts GitHub Actions / ESLintsrc/modules/config/config.repository.ts#L28
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
|
||
|
||
Check failure on line 23 in src/modules/config/config.service.ts GitHub Actions / ESLintsrc/modules/config/config.service.ts#L23
|
||
config.assign(props); | ||
Check failure on line 24 in src/modules/config/config.service.ts GitHub Actions / ESLintsrc/modules/config/config.service.ts#L24
|
||
console.log('CCCCCC'); | ||
|
||
|
||
return this.configRepo.save(config); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<getConfigResponse> { | ||
const config = await this.configService.getConfig(); | ||
|
||
return config?.toDto() as getConfigResponse; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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[]; | ||
} |