Skip to content

Commit

Permalink
fix: some issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ZigBalthazar committed Dec 20, 2024
1 parent 6eb190f commit 7b342d3
Show file tree
Hide file tree
Showing 19 changed files with 145 additions and 123 deletions.
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ ENABLE_DOCUMENTATION=true


#== MONGO
MONGO_URI="mongodb://..."
MONGO_DB_URL="mongodb://..."
MONGO_DB_NAME=IMMORTAL
MONGO_DB_USERNAME=IMMORTAL
MONGO_DB_PASSWORD=IMMORTAL
MONGO_DB_CONNECTION_TIMEOUT_IN_MS=500

#== JWT
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export interface IJwtStrategyValidate {
id: string;
email: string;
}
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 @@ -17,8 +17,8 @@ export default class JwtStrategy extends PassportStrategy(Strategy) {
}

validate(payload: UserEntity): IJwtStrategyValidate {
console.log(payload)

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

View workflow job for this annotation

GitHub Actions / ESLint

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

Unexpected console statement (no-console)

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

View workflow job for this annotation

GitHub Actions / ESLint

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

Insert `;` (prettier/prettier)

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

View workflow job for this annotation

GitHub Actions / ESLint

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

Missing semicolon (@typescript-eslint/semi)
return {

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

Expected blank line before this statement (padding-line-between-statements)
id: payload._id.toString(),
email: payload.email,
};
}
Expand Down
14 changes: 9 additions & 5 deletions src/modules/config/config.service.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import { Injectable } from '@nestjs/common';
import { Injectable, NotFoundException } from '@nestjs/common';

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

View workflow job for this annotation

GitHub Actions / ESLint

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

Run autofix to sort these imports! (simple-import-sort/imports)

import { Nip11Repository } from './repositories/nip11.repository';
import type { UpdateNip11Dto } from './dto/update-config.dto';
import { EventEmitter } from 'node:stream';

@Injectable()
export class ConfigService extends EventEmitter {

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

View workflow job for this annotation

GitHub Actions / ESLint

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

Prefer `EventTarget` over `EventEmitter` (unicorn/prefer-event-target)
constructor(
private readonly nip11Repo: Nip11Repository,
) {
constructor(private readonly nip11Repo: Nip11Repository) {
super();
}

async getNip11() {
return this.nip11Repo.findOne();
const entity = await this.nip11Repo.findOne();

if (!entity) {
throw new NotFoundException('NIP-11 not found.');
}

return entity;
}

async updateNip11(props: UpdateNip11Dto) {
Expand Down
9 changes: 7 additions & 2 deletions src/modules/config/controllers/config.controller.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import { Body, Controller, Get, Patch } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { Body, Controller, Get, Patch, UseGuards } from '@nestjs/common';

Check failure on line 1 in src/modules/config/controllers/config.controller.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/modules/config/controllers/config.controller.ts#L1

Run autofix to sort these imports! (simple-import-sort/imports)
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';

import { ConfigService } from '../config.service';
import { UpdateNip11Dto } from '../dto/update-config.dto';
import JwtAuthGuard from '../../../../src/modules/auth/guards/jwt-auth.guard';

@Controller('config')
@ApiTags('config')
export class ServiceConfigController {
constructor(private readonly configService: ConfigService) {}

@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@Patch()
async update(@Body() props: UpdateNip11Dto) {
return this.configService.updateNip11(props);
}

@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@Get()
async get() {
const config = await this.configService.getNip11();
Expand Down
28 changes: 14 additions & 14 deletions src/modules/config/dto/limitation.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,57 +6,57 @@ import { AbstractDto } from '../../../common/dto/abstract.dto';
export class LimitationDto {
@ApiProperty()
@IsInt()
maxMessageLength?: number;
max_message_length?: number;

@ApiProperty()
@IsInt()
maxSubscriptions?: number;
max_subscriptions?: number;

@ApiProperty()
@IsInt()
maxFilters?: number;
max_filters?: number;

@ApiProperty()
@IsInt()
maxSubidLength?: number;
max_subid_length?: number;

@ApiProperty()
@IsInt()
minPowDifficulty?: number;
min_pow_difficulty?: number;

@ApiProperty()
@IsBoolean()
authRequired?: boolean;
auth_required?: boolean;

@ApiProperty()
@IsBoolean()
paymentRequired?: boolean;
payment_required?: boolean;

@ApiProperty()
@IsBoolean()
restrictedWrites?: boolean;
restricted_writes?: boolean;

@ApiProperty()
@IsInt()
maxEventTags?: number;
max_event_tags?: number;

@ApiProperty()
@IsInt()
maxContentLength?: number;
max_content_length?: number;

@ApiProperty()
@IsInt()
createdAtLowerLimit?: number;
created_at_lower_limit?: number;

@ApiProperty()
@IsInt()
createdAtUpperLimit?: number;
created_at_upper_limit?: number;

@ApiProperty()
@IsInt()
maxQueryLimit?: number;
max_limit?: number;

@ApiProperty()
@IsInt()
defaultQueryLimit?: number;
default_query_limit?: number;
}
53 changes: 29 additions & 24 deletions src/modules/config/dto/nip11.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export class Nip11DTO extends AbstractDto {
@IsString()
description: string;

@ApiProperty()
@IsString()
banner: string;

@ApiProperty()
@IsString()
pubkey: string;
Expand All @@ -30,19 +34,19 @@ export class Nip11DTO extends AbstractDto {

@ApiProperty({ type: [Number] })
@IsArray()
supportedNips: number[];
supported_nips: number[];

@ApiProperty()
@IsString()
version: string;

@ApiProperty({ type: [String] })
@IsArray()
relayCountries: string[];
relay_countries: string[];

@ApiProperty({ type: [String] })
@IsArray()
languageTags: string[];
language_tags: string[];

@ApiProperty({ type: [String] })
@IsArray()
Expand All @@ -51,12 +55,12 @@ export class Nip11DTO extends AbstractDto {
@ApiProperty({ required: false })
@IsOptional()
@IsString()
postingPolicy?: string;
posting_policy?: string;

@ApiProperty({ required: false })
@IsOptional()
@IsString()
paymentsUrl?: string;
payments_url?: string;

@ApiProperty({ required: false })
@IsOptional()
Expand Down Expand Up @@ -87,14 +91,15 @@ export class Nip11DTO extends AbstractDto {
this.description = e.description;
this.pubkey = e.pubkey;
this.contact = e.contact;
this.banner = e.banner;
this.software = e.software;
this.supportedNips = e.supportedNips;
this.supported_nips = e.supported_nips;
this.version = e.version;
this.relayCountries = e.relayCountries;
this.languageTags = e.languageTags;
this.relay_countries = e.relay_countries;
this.language_tags = e.language_tags;
this.tags = e.tags;
this.postingPolicy = e.postingPolicy;
this.paymentsUrl = e.paymentsUrl;
this.posting_policy = e.posting_policy;
this.payments_url = e.payments_url;
this.icon = e.icon;
this.url = e.url;
this.retention = {
Expand All @@ -120,20 +125,20 @@ export class Nip11DTO extends AbstractDto {
};

this.limitations = {
authRequired: e.limitations?.authRequired,
maxMessageLength: e.limitations?.maxMessageLength,
maxSubidLength: e.limitations?.maxSubidLength,
maxFilters: e.limitations?.maxFilters,
maxSubscriptions: e.limitations?.maxSubscriptions,
minPowDifficulty: e.limitations?.minPowDifficulty,
paymentRequired: e.limitations?.paymentRequired,
restrictedWrites: e.limitations?.restrictedWrites,
maxEventTags: e.limitations?.maxEventTags,
maxContentLength: e.limitations?.maxContentLength,
createdAtLowerLimit: e.limitations?.createdAtLowerLimit,
createdAtUpperLimit: e.limitations?.createdAtUpperLimit,
defaultQueryLimit: e.limitations?.maxQueryLimit,
maxQueryLimit: e.limitations?.maxQueryLimit,
auth_required: e.limitations?.auth_required,
max_message_length: e.limitations?.max_message_length,
max_subid_length: e.limitations?.max_subid_length,
max_filters: e.limitations?.max_filters,
max_subscriptions: e.limitations?.max_subscriptions,
min_pow_difficulty: e.limitations?.min_pow_difficulty,
payment_required: e.limitations?.payment_required,
restricted_writes: e.limitations?.restricted_writes,
max_event_tags: e.limitations?.max_event_tags,
max_content_length: e.limitations?.max_content_length,
created_at_lower_limit: e.limitations?.created_at_lower_limit,
created_at_upper_limit: e.limitations?.created_at_upper_limit,
default_query_limit: e.limitations?.max_limit,
max_limit: e.limitations?.max_limit,
};
}
}
28 changes: 14 additions & 14 deletions src/modules/config/entities/limitaion.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,44 @@ import { Column } from 'typeorm';

export class LimitationEntity {
@Column({ type: 'int' })
maxMessageLength?: number;
max_message_length?: number;

@Column({ type: 'int' })
maxSubscriptions?: number;
max_subscriptions?: number;

@Column({ type: 'int' })
maxFilters?: number;
max_filters?: number;

@Column({ type: 'int' })
maxSubidLength?: number;
max_subid_length?: number;

@Column({ type: 'int' })
minPowDifficulty?: number;
min_pow_difficulty?: number;

@Column({ type: 'boolean' })
authRequired?: boolean;
auth_required?: boolean;

@Column({ type: 'boolean' })
paymentRequired?: boolean;
payment_required?: boolean;

@Column({ type: 'boolean' })
restrictedWrites?: boolean;
restricted_writes?: boolean;

@Column({ type: 'int' })
maxEventTags?: number;
max_event_tags?: number;

@Column({ type: 'int' })
maxContentLength?: number;
max_content_length?: number;

@Column({ type: 'bigint' })
createdAtLowerLimit?: number;
created_at_lower_limit?: number;

@Column({ type: 'bigint' })
createdAtUpperLimit?: number;
created_at_upper_limit?: number;

@Column({ type: 'int' })
maxQueryLimit?: number;
max_limit?: number;

@Column({ type: 'int' })
defaultQueryLimit?: number;
default_query_limit?: number;
}
Loading

0 comments on commit 7b342d3

Please sign in to comment.