Skip to content

Commit

Permalink
fix(): fix linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
NarHakobyan committed Jun 24, 2024
1 parent 79ed159 commit 5a9c075
Show file tree
Hide file tree
Showing 59 changed files with 2,932 additions and 3,620 deletions.
15 changes: 8 additions & 7 deletions src/boilerplate.polyfill.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import 'source-map-support/register';

import { compact, map } from 'lodash';
import { Brackets, type ObjectLiteral, SelectQueryBuilder } from 'typeorm';
import type { ObjectLiteral } from 'typeorm';
import { Brackets, SelectQueryBuilder } from 'typeorm';

import { type AbstractEntity } from './common/abstract.entity';
import { type AbstractDto } from './common/dto/abstract.dto';
import { type CreateTranslationDto } from './common/dto/create-translation.dto';
import type { AbstractEntity } from './common/abstract.entity';
import type { AbstractDto } from './common/dto/abstract.dto';
import type { CreateTranslationDto } from './common/dto/create-translation.dto';
import { PageDto } from './common/dto/page.dto';
import { PageMetaDto } from './common/dto/page-meta.dto';
import { type PageOptionsDto } from './common/dto/page-options.dto';
import { type LanguageCode } from './constants/language-code';
import { type KeyOfType } from './types';
import type { PageOptionsDto } from './common/dto/page-options.dto';
import type { LanguageCode } from './constants/language-code';
import type { KeyOfType } from './types';

declare global {
export type Uuid = string & { _uuidBrand: undefined };
Expand Down
8 changes: 4 additions & 4 deletions src/common/abstract-client.service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { type ClientProxy } from '@nestjs/microservices';
import type { ClientProxy } from '@nestjs/microservices';
import { plainToInstance } from 'class-transformer';
import { firstValueFrom } from 'rxjs';

import { PageTypeException } from '../exceptions/page-type.exception';
import { type Constructor } from '../types';
import { type PageDto } from './dto/page.dto';
import { type PageMetaDto } from './dto/page-meta.dto';
import type { Constructor } from '../types';
import type { PageDto } from './dto/page.dto';
import type { PageMetaDto } from './dto/page-meta.dto';

/**
* Fixme: This class designed to use with @nestjs/microservices by extending and creating a new class.
Expand Down
7 changes: 2 additions & 5 deletions src/common/abstract.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ import {
} from 'typeorm';

import { LanguageCode } from '../constants';
import { type Constructor } from '../types';
import {
type AbstractDto,
type AbstractTranslationDto,
} from './dto/abstract.dto';
import type { Constructor } from '../types';
import type { AbstractDto, AbstractTranslationDto } from './dto/abstract.dto';

/**
* Abstract Entity
Expand Down
5 changes: 2 additions & 3 deletions src/common/dto/abstract.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
UUIDField,
} from '../../decorators';
import { ContextProvider } from '../../providers';
import { type AbstractEntity } from '../abstract.entity';
import type { AbstractEntity } from '../abstract.entity';

export class AbstractDto {
@UUIDField()
Expand Down Expand Up @@ -43,8 +43,7 @@ export class AbstractDto {
);

if (metadata) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
fields[key] = translationEntity[key];
fields[key] = (translationEntity as never)[key];
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/common/dto/page-meta.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BooleanField, NumberField } from '../../decorators';
import { type PageOptionsDto } from './page-options.dto';
import type { PageOptionsDto } from './page-options.dto';

interface IPageMetaDtoParameters {
pageOptionsDto: PageOptionsDto;
Expand Down
2 changes: 1 addition & 1 deletion src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function getVariableName<TResult>(
);
}

const fullMemberName = m[1];
const fullMemberName = m[1]!;

const memberParts = fullMemberName.split('.');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type MigrationInterface, type QueryRunner } from 'typeorm';
import type { MigrationInterface, QueryRunner } from 'typeorm';

export class CreateUsersTable1622299665807 implements MigrationInterface {
name = 'createUsersTable1622299665807';
Expand Down
2 changes: 1 addition & 1 deletion src/database/migrations/1639940635548-add-user-settings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type MigrationInterface, type QueryRunner } from 'typeorm';
import type { MigrationInterface, QueryRunner } from 'typeorm';

export class AddUserSettings1639940635548 implements MigrationInterface {
name = 'addUserSettings1639940635548';
Expand Down
2 changes: 1 addition & 1 deletion src/database/migrations/1641994291086-add-posts-table.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type MigrationInterface, type QueryRunner } from 'typeorm';
import type { MigrationInterface, QueryRunner } from 'typeorm';

export class AddPostsTable1641994291086 implements MigrationInterface {
name = 'addPostsTable1641994291086';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { applyDecorators, type Type } from '@nestjs/common';
import type { Type } from '@nestjs/common';
import { applyDecorators } from '@nestjs/common';
import type { ApiResponseOptions } from '@nestjs/swagger';
import { ApiExtraModels, ApiOkResponse, getSchemaPath } from '@nestjs/swagger';

import { PageDto } from '../common/dto/page.dto';

export function ApiPageOkResponse<T extends Type>(options: {
export function ApiPageResponse<T extends Type>(options: {
type: T;
description?: string;
}): MethodDecorator {
Expand All @@ -25,6 +27,6 @@ export function ApiPageOkResponse<T extends Type>(options: {
},
],
},
}),
} as ApiResponseOptions | undefined),
);
}
3 changes: 2 additions & 1 deletion src/decorators/auth-user.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createParamDecorator, type ExecutionContext } from '@nestjs/common';
import type { ExecutionContext } from '@nestjs/common';
import { createParamDecorator } from '@nestjs/common';

export function AuthUser() {
return createParamDecorator((_data: unknown, context: ExecutionContext) => {
Expand Down
5 changes: 3 additions & 2 deletions src/decorators/field.decorators.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable unicorn/no-null */
import { applyDecorators } from '@nestjs/common';
import { ApiProperty, type ApiPropertyOptions } from '@nestjs/swagger';
import type { ApiPropertyOptions } from '@nestjs/swagger';
import { ApiProperty } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import {
ArrayMaxSize,
Expand All @@ -25,7 +26,7 @@ import {
} from 'class-validator';

import { supportedLanguageCount } from '../constants';
import { type Constructor } from '../types';
import type { Constructor } from '../types';
import { ApiEnumProperty, ApiUUIDProperty } from './property.decorators';
import {
PhoneNumberSerializer,
Expand Down
6 changes: 3 additions & 3 deletions src/decorators/http.decorators.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type { PipeTransform } from '@nestjs/common';
import {
applyDecorators,
Param,
ParseUUIDPipe,
type PipeTransform,
UseGuards,
UseInterceptors,
} from '@nestjs/common';
import { type Type } from '@nestjs/common/interfaces';
import type { Type } from '@nestjs/common/interfaces';
import { ApiBearerAuth, ApiUnauthorizedResponse } from '@nestjs/swagger';

import { type RoleType } from '../constants';
import type { RoleType } from '../constants';
import { AuthGuard } from '../guards/auth.guard';
import { RolesGuard } from '../guards/roles.guard';
import { AuthUserInterceptor } from '../interceptors/auth-user-interceptor.service';
Expand Down
2 changes: 1 addition & 1 deletion src/decorators/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './api-page-ok-response.decorator';
export * from './api-page-response.decorator';
export * from './auth-user.decorator';
export * from './field.decorators';
export * from './http.decorators';
Expand Down
3 changes: 2 additions & 1 deletion src/decorators/property.decorators.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ApiProperty, type ApiPropertyOptions } from '@nestjs/swagger';
import type { ApiPropertyOptions } from '@nestjs/swagger';
import { ApiProperty } from '@nestjs/swagger';

import { getVariableName } from '../common/utils';

Expand Down
3 changes: 2 additions & 1 deletion src/decorators/public-route.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { type CustomDecorator, SetMetadata } from '@nestjs/common';
import type { CustomDecorator } from '@nestjs/common';
import { SetMetadata } from '@nestjs/common';

export const PUBLIC_ROUTE_KEY = 'public_route';

Expand Down
12 changes: 7 additions & 5 deletions src/decorators/swagger.schema.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/ban-types,@typescript-eslint/no-unsafe-argument */
import { type Type } from '@nestjs/common';
import type { Type } from '@nestjs/common';
import { applyDecorators, UseInterceptors } from '@nestjs/common';
import {
PARAMTYPES_METADATA,
Expand All @@ -13,14 +13,14 @@ import {
ApiExtraModels,
getSchemaPath,
} from '@nestjs/swagger';
import {
type ReferenceObject,
type SchemaObject,
import type {
ReferenceObject,
SchemaObject,
} from '@nestjs/swagger/dist/interfaces/open-api-spec.interface';
import { reverseObjectKeys } from '@nestjs/swagger/dist/utils/reverse-object-keys.util';
import _ from 'lodash';

import { type IApiFile } from '../interfaces';
import type { IApiFile } from '../interfaces';

function explore(instance: Object, propertyKey: string | symbol) {
const types: Array<Type<unknown>> = Reflect.getMetadata(
Expand Down Expand Up @@ -51,6 +51,8 @@ function explore(instance: Object, propertyKey: string | symbol) {
return value.type;
}
}

return null;
}

function RegisterModels(): MethodDecorator {
Expand Down
2 changes: 1 addition & 1 deletion src/decorators/translate.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type ITranslationDecoratorInterface } from '../interfaces';
import type { ITranslationDecoratorInterface } from '../interfaces';

export const STATIC_TRANSLATION_DECORATOR_KEY = 'custom:static-translate';
export const DYNAMIC_TRANSLATION_DECORATOR_KEY = 'custom:dynamic-translate';
Expand Down
4 changes: 2 additions & 2 deletions src/decorators/use-dto.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { type Constructor } from '../types';
import type { Constructor } from '../types';

export function UseDto(dtoClass: Constructor): ClassDecorator {
return (ctor) => {
// FIXME make dtoClass function returning dto

if (!(<unknown>dtoClass)) {
if (!(dtoClass as unknown)) {
throw new Error('UseDto decorator requires dtoClass');
}

Expand Down
4 changes: 2 additions & 2 deletions src/decorators/validator.decorators.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { ValidationOptions } from 'class-validator';
import {
IsPhoneNumber as isPhoneNumber,
registerDecorator,
ValidateIf,
type ValidationOptions,
} from 'class-validator';
import { isString } from 'lodash';

Expand Down Expand Up @@ -47,7 +47,7 @@ export function IsTmpKey(
options: validationOptions,
validator: {
validate(value: string): boolean {
return isString(value) && /^tmp\//.test(value);
return isString(value) && value.startsWith('tmp/');
},
defaultMessage(): string {
return 'error.invalidTmpKey';
Expand Down
10 changes: 5 additions & 5 deletions src/entity-subscribers/user-subscriber.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
type EntitySubscriberInterface,
EventSubscriber,
type InsertEvent,
type UpdateEvent,
import type {
EntitySubscriberInterface,
InsertEvent,
UpdateEvent,
} from 'typeorm';
import { EventSubscriber } from 'typeorm';

import { generateHash } from '../common/utils';
import { UserEntity } from '../modules/user/user.entity';
Expand Down
12 changes: 4 additions & 8 deletions src/filters/bad-request.filter.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import {
type ArgumentsHost,
Catch,
type ExceptionFilter,
UnprocessableEntityException,
} from '@nestjs/common';
import type { ArgumentsHost, ExceptionFilter } from '@nestjs/common';
import { Catch, UnprocessableEntityException } from '@nestjs/common';
import { Reflector } from '@nestjs/core';
import { type ValidationError } from 'class-validator';
import { type Response } from 'express';
import type { ValidationError } from 'class-validator';
import type { Response } from 'express';
import _ from 'lodash';

@Catch(UnprocessableEntityException)
Expand Down
10 changes: 3 additions & 7 deletions src/filters/query-failed.filter.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { STATUS_CODES } from 'node:http';

import {
type ArgumentsHost,
Catch,
type ExceptionFilter,
HttpStatus,
} from '@nestjs/common';
import type { ArgumentsHost, ExceptionFilter } from '@nestjs/common';
import { Catch, HttpStatus } from '@nestjs/common';
import { Reflector } from '@nestjs/core';
import { type Response } from 'express';
import type { Response } from 'express';
import { QueryFailedError } from 'typeorm';

import { constraintErrors } from './constraint-errors';
Expand Down
7 changes: 2 additions & 5 deletions src/guards/auth.guard.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import {
AuthGuard as NestAuthGuard,
type IAuthGuard,
type Type,
} from '@nestjs/passport';
import type { IAuthGuard, Type } from '@nestjs/passport';
import { AuthGuard as NestAuthGuard } from '@nestjs/passport';

export function AuthGuard(
options?: Partial<{ public: boolean }>,
Expand Down
14 changes: 7 additions & 7 deletions src/interceptors/auth-user-interceptor.service.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import {
type CallHandler,
type ExecutionContext,
Injectable,
type NestInterceptor,
import type {
CallHandler,
ExecutionContext,
NestInterceptor,
} from '@nestjs/common';
import { Injectable } from '@nestjs/common';

import { type UserEntity } from '../modules/user/user.entity';
import type { UserEntity } from '../modules/user/user.entity';
import { ContextProvider } from '../providers';

@Injectable()
export class AuthUserInterceptor implements NestInterceptor {
intercept(context: ExecutionContext, next: CallHandler) {
const request = context.switchToHttp().getRequest();

const user = <UserEntity>request.user;
const user = request.user as UserEntity;
ContextProvider.setAuthUser(user);

return next.handle();
Expand Down
19 changes: 7 additions & 12 deletions src/interceptors/language-interceptor.service.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
import {
type CallHandler,
type ExecutionContext,
Injectable,
type NestInterceptor,
UseInterceptors,
import type {
CallHandler,
ExecutionContext,
NestInterceptor,
} from '@nestjs/common';
import { type Observable } from 'rxjs';
import { Injectable, UseInterceptors } from '@nestjs/common';

import { LanguageCode } from '../constants';
import { ContextProvider } from '../providers';

@Injectable()
export class LanguageInterceptor implements NestInterceptor {
intercept(
context: ExecutionContext,
next: CallHandler,
): Observable<undefined> {
intercept(context: ExecutionContext, next: CallHandler) {
const request = context.switchToHttp().getRequest();
const language: string = request.headers['x-language-code'];
const language: LanguageCode = request.headers['x-language-code'];

if (LanguageCode[language]) {
ContextProvider.setLanguage(language);
Expand Down
Loading

0 comments on commit 5a9c075

Please sign in to comment.