Nest.js
-
메일 전송시 Promise.allSettled 사용하기Nest.js 2024. 6. 8. 18:27
Promise.allSettled를 활용해서 여러개의 메일을 전송할때 Promise.allSettled는 Pormise 객체가 성공 했을때 "fulfilled" 실패 했을때 "rejected" 와 상관없이 전부 다 실행이 되고 성공 한값과 실패한 값을 전부 받을 수 있다.그래서 "nodemailer"를 사용 했을때 모두 전송이 완료 되었을때 "fulfilled" 상태값일때 "value"값을 받고 "rejected" 상태값일때 "reason"값을 가지고 mail-log를 만들면 좋을것 같았다. 그러나 nodemailer는 rejected가 되는 상황이 생각보다 많이 없었다. 무슨 말이냐면 예를들어 수신자의 메일 주소가 존재하지 않는 메일주소인 경우에도 fulfilled로 결과를 반환 받는다. 즉, 메일이 ..
-
NestJS에서 repository의 insert메서드로 유동적으로 데이터 생성하기Nest.js 2024. 6. 4. 18:30
// group repository create methodexport interface ICreateGroupArgs{ id: string; name: string; description: string; memberId: string;}async createGroup(createGroupArgs:ICreateGroupArgs){ await this.groupRepository.insert(createArgs)}예를들어 그룹을 생성하는 repository 메서드의 createGroup 메서드를 생성하여 사용하고 있다고 가정 했을때만약에 group-service에서 createGroup 메서드가 있고 createGroupAndCorverImage 메서드가 있다고 가정 해보자. // grou..
-
NestJS Response Dto에 generic을 swagger ApiProperty 데코레이터에 사용하기Nest.js 2024. 6. 4. 14:34
// pagination response{ list:T[]; page:number; totalPage:number; }// cursor pagination response{ list:T[]; cursor:{ after: string; }; count: number; next: string;} 보통 pagiantion이 필요하거나 cursor pagination이 필요한 api는 위와 같은 동일한 response형식을 가질것이다. // feed-get-all-res-dto.tsimport { ApiProperty } from '@nestjs/swagger';import { FeedResDto } from './feed-res.dto';export class Fe..
-
cookie-option secure: true 옵션 사용시 Safari localhost에서 쿠키 저장이 안되는 문제Nest.js 2024. 5. 23. 16:39
Referencehttps://shanepark.tistory.com/454 Safari 에서만 localhost에 쿠키가 저장 안되는 문제 해결문제 쿠키에 JWT 를 저장하고, 토큰값 기반 로그인을 구현 해 두었다. 그런데 Chrome 이나 Firefox, Opera 등 다른 브라우저에서는 다 문제 없이 작동하는데 유독 사파리에서만 동작이 안된다. Network를shanepark.tistory.com secure:true 옵션은 `Marks the cookie to be used with HTTPS only.` 즉 HTTPS에서만 사용가능한 옵션인데 크롬에서는 localhost에서 잘 동작하지만 safari에서는 동작하지 않는다.제목과 그대로 cookie-option중에서 secure:true는 운영 ..
-
NestJS에서 TypeOrm에서 쿼리로그Nest.js/TypeOrm 2024. 4. 22. 12:53
슬로우 쿼리가 발생했을때 해당 쿼리를 찾거나, 의도한 쿼리와 실제 쿼리가 다른지 확인할때 실제 쿼리 로그를 확인한다. 하지만 typeorm에서 제공해주는 로그 옵션으로 dev 개발 환경에서 보게되면 $ query: SELECT "MemberEntity"."id" AS "MemberEntity_id", "MemberEntity"."username" AS "MemberEntity_username", "MemberEntity"."profileImage" AS "MemberEntity_profileImage", "MemberEntity__MemberEntity_memberGroups"."id" AS "MemberEntity__MemberEntity_memberGroups_id", "MemberEntity__Me..
-
NestJS에서 nest-cli로 실행 시킬때 src폴더 외 루트 경로 인식 못할때Nest.js 2024. 4. 17. 21:33
NestJS에서 start:dev나 start 그리고 build 명령어를 사용하면 dist 폴더가 생성된다. 하지만 src 밖에 생성되는것들을 인식 하지 못한다. // nest-cli.json { "$schema": "https://json.schemastore.org/nest-cli", "collection": "@nestjs/schematics", "sourceRoot": "src", "compilerOptions": { "deleteOutDir": true } } nest-cli.json에서 sourceRoot를 src를 해두면 dis폴더에 src에 있는것들이 빌드되어 생성된다. src 외부에 루트경로에 있는것들을 nest cli 명령어로 시작해서 생성된 dist 폴더에서 인식 하게 해주려면 따로..
-
jest unit 테스트 경로와 e2e 테스트 경로 잡아주기Nest.js/TDD 2024. 4. 16. 18:58
tsconfig.json { "compilerOptions": { .... "paths": { "@/*": ["src/*"], "test/*": ["test/*"] } } } import path를 유용하게 잡기 위해 paths 옵션을 주었을때와 루트 디렉토리 경로에서 src폴더와 별개로 테스트 파일들을 한곳에 모아서 관리하고 싶었다. 프로젝트 구조 /src /test /test/unit /test/e2e /test/jest-e2e.json Unit 테스트 파일 경로 설정하기 // 기존 package.json ... "jest": { "moduleFileExtensions": [ "js", "json", "ts" ], "rootDir": "src", "testRegex": ".*\\.spec\\.ts$"..