1.4.6-beta-4 • Published 28 days ago
@lactea-blue/universe v1.4.6-beta-4
Description
공통적으로 쓰이는 함수 및 module, decorator 등을 모아놓은 라이브러리.
라이브러리를 만들어, 코드 중복을 막고 수정을 간편하게 하기 위해 만들어졌다.
라이브러리에 대한 자세한 설명은 아래의 링크에 있다. 해당 라이브러리를 사용할 때, 참고하여 사용하면 편리하다.
https://lactea-blue-library.s3.ap-northeast-2.amazonaws.com/universe/index.html
Installation
$ npm i @lactea-blue/universe
jwt module 사용법
- jwt service를 사용하고자 하는 곳의 Host module에 아래와 같이 JwtConfigModule을 Import 해준다.
- 그 후, 필요한 곳에 JwtService를 inject하여 사용하면 된다.
@Module({
imports: [
JwtConfigModule
],
controllers: [ SampleController ],
providers: [
SamepleService
],
})
export class SampleModule {}
@Injectable()
export class SampleService {
constructor(
private readonly JwtUtilService: JwtUtilService,
private readonly jwtService: JwtService
) {
}
}
ApiCall
- ApiCall은 외부 API를 편리하기 호출하기 위해 만들어진 데코레이터다.
ApiCall 사용법
- 호출하고자 하는 HOST를 ./env/.env.{운영환경} 파일 또는 ./common/env/{운영환경}/.env.host 파일에 작성한다.
- 우선순위 : ./env/.env
EXAMPLE_HOST="https://example.com"
- 클래스 레벨에서 @ApiCall 데코레이터를 설정한다.
- hostName : 호출하고 하는 API의 HOST (필수 값)
- .env 파일에 작성한 변수명
- headers: 공통적으로 사용하는 헤더 값들 (선택 값)
- hostName : 호출하고 하는 API의 HOST (필수 값)
@Injectable()
@ApiCall(
"EXAMPLE_HOST",
{
"Content-Type" : "application/json",
}
)
export class ExampleApiClient { }
@Injectable()
@ApiCall(
"EXAMPLE_HOST",
)
export class ExampleApiClient { }
- 외부 호출이 필요한 메소드를 ApiCall 전용 Http Method 데코레이터와 Paramter 데코레이터와 함께 작성한다. cf) NestJs에서 제공하는 데코레이터와 거의 유사하다. (Import시 주의)
- ApiCall 전용 Http Method 데코레이터
- @Get()
- @Post()
- @Put()
- @Delete()
- ApiCall 전용 Parameter 데코레이터
- @Body()
- @Query()
- @Param()
- @Header()
@Get("/search")
async searchUser(@Query("name") userName: string): Promise<GetUserInfoRes> { return }
@Post("/user")
async createUser(@Body() req: createUserReq): Promise<CreateUserRes> { return }
@Put("/users/{:id}")
async updateUser(
@Param("id") userId: string,
@Body() req: UpdateUserReq,
): Promise<UpdateUserRes> { return }
@Delete("/users")
async deleteUser(@Query("userId") userId: string): Promise<DelteUserRes> { return }
특정 메소드에만 header 정보를 추가하고 싶을 때
@Put("/users/{:id}")
async updateUser(
@Header("Content-Type") contentType: string,
@Param("id") userId: string,
@Body() req: UpdateUserReq,
): Promise<UpdateUserRes> { return }
만약 공통 헤더와 메소드 헤더의 key값이 같다면 메소드의 헤더의 value가 우선 순위가 된다.
@Injectable()
@ApiCall(
"EXAMPLE_HOST",
{
"Content-Type" : "application/json",
}
)
export class ExampleApiClient {
@Put("/users/{:id}")
async updateUser(
@Header("Content-Type") contentType: string,
): Promise<UpdateUserRes> { return }
}
ApiCall 사용 예제
@Injectable()
@ApiCall(
"EXAMPLE_HOST",
{
"Content-Type" : "application/json",
}
)
export class ExampleApiClient {
@Post("/example")
async callExample(@Body() req: ExampleReq): Promise<ExampleRes> { return }
}
@Injectable()
export class ExampleService {
constructor(
private readonly exampleApiClient: ExampleApiClient,
)
async doExample(req: ExampleReq): Promise<ExampleRes> {
let response: ExampleRes = exampleApiClient.callExample(req)
// 비즈니스 로직 작성
}
}
1.4.6-beta-3
28 days ago
1.4.6-beta-4
28 days ago
1.4.6
1 month ago
1.4.7
1 month ago
1.4.6-beta-2
2 months ago
1.4.6-beta-1
2 months ago
1.4.4-beta
3 months ago
1.4.5
3 months ago
1.4.4
3 months ago
1.4.3
3 months ago
1.4.3-test
3 months ago
1.4.2
4 months ago
1.4.2-beta
4 months ago
1.4.0-beta1
7 months ago
1.4.1
6 months ago
1.4.0
7 months ago
1.3.1
8 months ago
1.3.0
8 months ago
1.2.0
12 months ago
1.1.0
1 year ago
1.0.1
1 year ago
1.0.0
1 year ago
1.0.0-beta2
1 year ago
1.0.0-beta1
1 year ago