Nest.js
-
NestJS event-emitter 사용시 런타임 에러 발생시 서버 중단 현상 최근에 패치됨Nest.js 2024. 8. 31. 20:45
해당 이슈를 확인 해보면 수정 된것을 알 수 있다.- ( https://github.com/nestjs/event-emitter/pull/936/commits/e322cb820f528640545e2e5685bdb141bfdc9142 )- ( https://github.com/nestjs/event-emitter/releases/tag/2.0.2 ) 버전 릴리즈를 살펴보면 해당 936 Pr이 2.0.2에 반영된것을 알 수있다.그렇기 때문에 @nestjs/event-emitter 사용시 >=2.0.2 로 버전업 되어 있는지 체크하고 사용해야 한다. 2.0.2 이전버전을 사용하게 된다면@OnEvent('event.fired', { async: true })public async handleEvent(even..
-
catch 할 수 없는 에러들을 slack 웹훅을 통해 slack 실시간 알림 보내기Nest.js 2024. 8. 16. 12:28
@slack/client deprecated가 되었다. @slack/webhook 라이브러리가 @slack/cleint와 비슷하고 유지보수도 잘 되고 있는것 같아 이것을 사용하기로 했다.$ npm i @slack/webhook main.tsall-exception.filter.ts피드 삭제시 TypeORM 에러가 발생 했을때 slack 아주 잘 동작한다!Reference- (https://velog.io/@inmyblue0930/Sentry-Slack-%EC%97%B0%EB%8F%99-%EC%8B%A4%EC%8B%9C%EA%B0%84-%EB%A1%9C%EA%B7%B8%EB%AA%A8%EB%8B%88%ED%84%B0%EB%A7%81)- ( https://www.npmjs.com/package/@slack/..
-
NestJS 꼭 알아야 되는 Exception filter 주의점Nest.js 2024. 8. 14. 17:31
NestJS 여러개의 exception filter와 모든 exception catch filter 사용시 주의할점에 대해서 알아보자.예시 Exception filter 종류BadRequestFilter : 400 bad request 를 catch 하는 filterServiceHttpExceptionFilter : service 에러 catch 하는 filterAllExceptionFilter : 모든 에러를 catch 하는 filter// exceptionapp.useGlobalFilters( new BadRequestServiceExceptionFilter() new ServiceHttpExceptionFilter(), new AllExceptionFilter(httpAdapterH..
-
TypeORM 쿼리빌더 사용시 where절 사용시 괄호 우선순위와 Brackets 사용Nest.js/TypeOrm 2024. 8. 10. 16:27
TypeORM의 쿼리빌더 사용시에 where절을 사용하는 메서드 where, andWhere, orWhere 사용시에 괄호를 사용하여 where절에 사용하고 싶으면 Brackets를 사용하면 된다.SelectQueryBuilder.d.ts Brackets 사용 괄호로 감싸주고 싶을때 사용 WHERE "a"."isPublic" = true OR "a"."memberId" = '410b7202-660a-4423-a6c3-6377857241cc' AND "a"."isPublic" = false 실제 쿼리 인데 OR 뒤의 부분을 괄호를 이용하여 감싸고 싶을때 사용 하면된다. WHERE "a"."isPublic" = true OR ("a"."memberId" = '410b7202-660a-4423-a6c3-6..
-
TypeOrm에서 queryBuilder사용시 관계 데이터 집계 결과를 order by 하는 방법Nest.js/TypeOrm 2024. 8. 8. 02:32
결론부터 말하는 아직 방법을 찾지 못했다. 생각보다 원하는 방향으로 참고 할 만한 자료를 찾지 못했다. addSelectloadRelationCountAndMap두가지 방법을 사용해서 하는 방법이 있지만 둘다 동작하지 않는다. loadRelationCountAndMap 첫번째 인자값은 가상의 프로퍼티를 entity에 생성해주고 해당 프로퍼티를 넣어주고두번째 인자값은 관계대상의 @ManyToOne에서 post가 가르키는 post.comments를 넣어주고세번째 인자값은 alias 이름을 넣어준다. 하지만 loadRelationCountAndMap 사용은 굉장히 구리다. 일딴 무조건 getMany랑 함께 사용 해야 하는데 getMany를 사용하게 되면 select 칼럼들을 alias 할 수 없다. getM..
-
NestJS에서 passport-naver와 passport-kakao 로그인 문제점Nest.js 2024. 7. 25. 13:03
Reference- (https://github.com/naver/passport-naver)- (https://github.com/rotoshine/passport-kakao)- (https://orangebrother.dev/blog/%08nestjs-google-oauth-passport)- (https://github.com/nestjs/passport/blob/master/lib/passport/passport.strategy.ts) NestJS에서 naver로그인과 kakao 로그인을 구현 할때 다운로드 수 와 게시글들을 비교 했을때 선택할 수 있는 라이브러리지만 9년전에 만들어 졌고 typescript를 지원하지 않는 라이브러리라 따로 @types를 설치 해주어야 한다.문제 1 NestJS에..
-
외부 api사용시 class-transformer의 클래스 인스턴스화 하기Nest.js/class-transformer 2024. 7. 15. 15:51
외부에서 받은 response 결과가 리터럴 객체라서 추가 가공은 별도의 함수에서 처리 해야 하는데 이로 인해 상태와 행위가 따로 노는 응집력이 떨어지는 코드가 된다.그래서 class-transformer를 이용하여 클래스 인스턴스화 하여 받은 값 가공 로직을 클래스 내부에 둔다면 상태와 행위가 한 곳에 있는 응집력 있는 코드가 된다. 1. @Expose 데코레이터로 카멜케이스 스네이크2. @Exclude 데코레이터로 특정 필드 제외3. @Type 데코레이터로 중첩 객체 변환4. @Transforemr 데코레이터를 이용한 데이터 가공 Reference- (https://jojoldu.tistory.com/617)