Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ZigBalthazar committed Nov 20, 2024
1 parent 1f66bb4 commit 1960d5c
Show file tree
Hide file tree
Showing 26 changed files with 560 additions and 45 deletions.
21 changes: 21 additions & 0 deletions .vscode/launch.json
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
}
]
}

2 changes: 2 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -17,6 +18,7 @@ import { SharedModule } from './shared/shared.module';
UserModule,
HealthModule,
ServiceRegistryModule,
ServicesConfigModule,
],
controllers: [],
providers: [],
Expand Down
13 changes: 7 additions & 6 deletions src/common/abstract.entity.ts
Original file line number Diff line number Diff line change
@@ -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';

Check failure on line 2 in src/common/abstract.entity.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/common/abstract.entity.ts#L2

Unable to resolve path to module 'typeorm' (import/no-unresolved)

import type { Constructor } from '../types';
import type { AbstractDto } from './dto/abstract.dto';
Expand All @@ -13,7 +13,7 @@ import type { AbstractDto } from './dto/abstract.dto';
* otherwise just delete and use your own entity.
*/
export interface IAbstractEntity<DTO extends AbstractDto, O = never> {
id: ObjectId;
_id: ObjectId;
createdAt: Date;
updatedAt: Date;

Expand All @@ -23,8 +23,9 @@ export interface IAbstractEntity<DTO extends AbstractDto, O = never> {
export abstract class AbstractEntity<DTO extends AbstractDto = AbstractDto, O = never>
implements IAbstractEntity<DTO, O>
{
@ObjectIdColumn() // MongoDB ObjectId
id: ObjectId;
@PrimaryGeneratedColumn()

Check failure on line 26 in src/common/abstract.entity.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/common/abstract.entity.ts#L26

Unsafe call of an `any` typed value (@typescript-eslint/no-unsafe-call)
@ObjectIdColumn()

Check failure on line 27 in src/common/abstract.entity.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/common/abstract.entity.ts#L27

Unsafe call of an `any` typed value (@typescript-eslint/no-unsafe-call)
_id: ObjectId;

@CreateDateColumn({

Check failure on line 30 in src/common/abstract.entity.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/common/abstract.entity.ts#L30

Unsafe call of an `any` typed value (@typescript-eslint/no-unsafe-call)
type: 'timestamp',
Expand Down Expand Up @@ -61,10 +62,10 @@ export abstract class AbstractEntity<DTO extends AbstractDto = AbstractDto, O =
}

assign(item: Partial<AbstractEntity>) {
const { id, createdAt, updatedAt } = item;
const { _id: id, createdAt, updatedAt } = item;

Check failure on line 65 in src/common/abstract.entity.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/common/abstract.entity.ts#L65

Unsafe array destructuring of a tuple element with an `any` value (@typescript-eslint/no-unsafe-assignment)

if (id) {
this.id = id;
this._id = id;

Check failure on line 68 in src/common/abstract.entity.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/common/abstract.entity.ts#L68

Unsafe assignment of an `any` value (@typescript-eslint/no-unsafe-assignment)
}

this.createdAt = createdAt ? new Date(createdAt) : this.createdAt;
Expand Down
2 changes: 1 addition & 1 deletion src/common/dto/abstract.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Check failure on line 17 in src/common/dto/abstract.dto.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/common/dto/abstract.dto.ts#L17

Unsafe assignment of an `any` value (@typescript-eslint/no-unsafe-assignment)

Check failure on line 17 in src/common/dto/abstract.dto.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/common/dto/abstract.dto.ts#L17

Unsafe call of an `any` typed value (@typescript-eslint/no-unsafe-call)

Check failure on line 17 in src/common/dto/abstract.dto.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/common/dto/abstract.dto.ts#L17

Unsafe member access .toString on an `any` value (@typescript-eslint/no-unsafe-member-access)
this.createdAt = entity.createdAt;
this.updatedAt = entity.updatedAt;
}
Expand Down
9 changes: 3 additions & 6 deletions src/common/dto/page-options.dto.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/constant/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export enum Order {
ASC = 'ASC',
}
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/modules/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default class AuthService {

if (isPasswordOk) {
return {
id: user.id.toString(),
id: user._id.toString(),

Check failure on line 34 in src/modules/auth/auth.service.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/modules/auth/auth.service.ts#L34

Unsafe assignment of an `any` value (@typescript-eslint/no-unsafe-assignment)

Check failure on line 34 in src/modules/auth/auth.service.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/modules/auth/auth.service.ts#L34

Unsafe call of an `any` typed value (@typescript-eslint/no-unsafe-call)

Check failure on line 34 in src/modules/auth/auth.service.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/modules/auth/auth.service.ts#L34

Unsafe member access ._id on an `any` value (@typescript-eslint/no-unsafe-member-access)
email: user.email,

Check failure on line 35 in src/modules/auth/auth.service.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/modules/auth/auth.service.ts#L35

Unsafe assignment of an `any` value (@typescript-eslint/no-unsafe-assignment)

Check failure on line 35 in src/modules/auth/auth.service.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/modules/auth/auth.service.ts#L35

Unsafe member access .email on an `any` value (@typescript-eslint/no-unsafe-member-access)
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/modules/auth/strategies/jwt.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class JwtStrategy extends PassportStrategy(Strategy) {

validate(payload: UserEntity): IJwtStrategyValidate {
return {
id: payload.id.toString(),
id: payload._id.toString(),

Check failure on line 21 in src/modules/auth/strategies/jwt.strategy.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/modules/auth/strategies/jwt.strategy.ts#L21

Unsafe assignment of an `any` value (@typescript-eslint/no-unsafe-assignment)

Check failure on line 21 in src/modules/auth/strategies/jwt.strategy.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/modules/auth/strategies/jwt.strategy.ts#L21

Unsafe call of an `any` typed value (@typescript-eslint/no-unsafe-call)

Check failure on line 21 in src/modules/auth/strategies/jwt.strategy.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/modules/auth/strategies/jwt.strategy.ts#L21

Unsafe member access .toString on an `any` value (@typescript-eslint/no-unsafe-member-access)
email: payload.email,
};
}
Expand Down
16 changes: 16 additions & 0 deletions src/modules/config/config.module.ts
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 {}
30 changes: 30 additions & 0 deletions src/modules/config/config.repository.ts
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';

Check failure on line 4 in src/modules/config/config.repository.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/modules/config/config.repository.ts#L4

Unable to resolve path to module 'typeorm' (import/no-unresolved)

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

View workflow job for this annotation

GitHub Actions / ESLint

src/modules/config/config.repository.ts#L15

Async method 'findAll' has no 'await' expression (@typescript-eslint/require-await)

Check failure on line 15 in src/modules/config/config.repository.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/modules/config/config.repository.ts#L15

'any' overrides all other types in this union type (@typescript-eslint/no-redundant-type-constituents)
return this.repository.find({ ...options });

Check failure on line 16 in src/modules/config/config.repository.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/modules/config/config.repository.ts#L16

Unsafe return of an `any` typed value (@typescript-eslint/no-unsafe-return)

Check failure on line 16 in src/modules/config/config.repository.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/modules/config/config.repository.ts#L16

Unsafe call of an `any` typed value (@typescript-eslint/no-unsafe-call)

Check failure on line 16 in src/modules/config/config.repository.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/modules/config/config.repository.ts#L16

Unsafe member access .find on an `any` value (@typescript-eslint/no-unsafe-member-access)
}

async findOne(options?: FindOneOptions<ConfigEntity>) {

Check failure on line 19 in src/modules/config/config.repository.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/modules/config/config.repository.ts#L19

Async method 'findOne' has no 'await' expression (@typescript-eslint/require-await)
return this.repository.findOne({ ...options });

Check failure on line 20 in src/modules/config/config.repository.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/modules/config/config.repository.ts#L20

Unsafe return of an `any` typed value (@typescript-eslint/no-unsafe-return)

Check failure on line 20 in src/modules/config/config.repository.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/modules/config/config.repository.ts#L20

Unsafe call of an `any` typed value (@typescript-eslint/no-unsafe-call)

Check failure on line 20 in src/modules/config/config.repository.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/modules/config/config.repository.ts#L20

Unsafe member access .findOne on an `any` value (@typescript-eslint/no-unsafe-member-access)
}

async save(data: ConfigEntity) {

Check failure on line 23 in src/modules/config/config.repository.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/modules/config/config.repository.ts#L23

Async method 'save' has no 'await' expression (@typescript-eslint/require-await)
return this.repository.save(data);

Check failure on line 24 in src/modules/config/config.repository.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/modules/config/config.repository.ts#L24

Unsafe return of an `any` typed value (@typescript-eslint/no-unsafe-return)

Check failure on line 24 in src/modules/config/config.repository.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/modules/config/config.repository.ts#L24

Unsafe call of an `any` typed value (@typescript-eslint/no-unsafe-call)

Check failure on line 24 in src/modules/config/config.repository.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/modules/config/config.repository.ts#L24

Unsafe member access .save on an `any` value (@typescript-eslint/no-unsafe-member-access)
}

create(entityLike: DeepPartial<ConfigEntity>) {
return this.repository.create(entityLike);

Check failure on line 28 in src/modules/config/config.repository.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/modules/config/config.repository.ts#L28

Unsafe return of an `any` typed value (@typescript-eslint/no-unsafe-return)

Check failure on line 28 in src/modules/config/config.repository.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/modules/config/config.repository.ts#L28

Unsafe call of an `any` typed value (@typescript-eslint/no-unsafe-call)

Check failure on line 28 in src/modules/config/config.repository.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/modules/config/config.repository.ts#L28

Unsafe member access .create on an `any` value (@typescript-eslint/no-unsafe-member-access)
}
}
30 changes: 30 additions & 0 deletions src/modules/config/config.service.ts
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();

Check failure on line 15 in src/modules/config/config.service.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/modules/config/config.service.ts#L15

Unsafe assignment of an `any` value (@typescript-eslint/no-unsafe-assignment)
console.log('AAAAA');

Check failure on line 16 in src/modules/config/config.service.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/modules/config/config.service.ts#L16

Unexpected console statement (no-console)
if (!config) {

Check failure on line 17 in src/modules/config/config.service.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/modules/config/config.service.ts#L17

Expected blank line before this statement (padding-line-between-statements)
config = this.configRepo.create(props);

Check failure on line 18 in src/modules/config/config.service.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/modules/config/config.service.ts#L18

Unsafe assignment of an `any` value (@typescript-eslint/no-unsafe-assignment)
}

console.log('BBBBBBB');

Check failure on line 21 in src/modules/config/config.service.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/modules/config/config.service.ts#L21

Unexpected console statement (no-console)


Check failure on line 23 in src/modules/config/config.service.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/modules/config/config.service.ts#L23

Delete `⏎` (prettier/prettier)

Check failure on line 23 in src/modules/config/config.service.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/modules/config/config.service.ts#L23

More than 1 blank line not allowed (no-multiple-empty-lines)
config.assign(props);

Check failure on line 24 in src/modules/config/config.service.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/modules/config/config.service.ts#L24

Unsafe call of an `any` typed value (@typescript-eslint/no-unsafe-call)

Check failure on line 24 in src/modules/config/config.service.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/modules/config/config.service.ts#L24

Unsafe member access .assign on an `any` value (@typescript-eslint/no-unsafe-member-access)
console.log('CCCCCC');


return this.configRepo.save(config);
}
}
17 changes: 17 additions & 0 deletions src/modules/config/controllers/config-grpc.controller.ts
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;
}
}
23 changes: 23 additions & 0 deletions src/modules/config/controllers/config.controller.ts
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();
}
}
101 changes: 101 additions & 0 deletions src/modules/config/dto/config.dto.ts
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;
}
}
29 changes: 29 additions & 0 deletions src/modules/config/dto/fees.dto.ts
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[];
}
Loading

0 comments on commit 1960d5c

Please sign in to comment.