feat: implement SalesInvoiceTspSwitchService and SalesInvoiceTspService for handling TSP provider interactions
- Add SalesInvoiceTspSwitchService to manage TSP provider selection and sending invoices. - Introduce SalesInvoiceTspService for creating, sending, and retrieving sales invoices. - Implement NamaProviderSwitchAdapter for communication with the NAMA TSP provider API. - Define DTOs for request and response structures specific to the NAMA provider. - Enhance error handling and logging for TSP provider interactions.
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import {
|
||||
FetchRequestContext,
|
||||
FetchRequestInterceptor,
|
||||
} from '@/common/interceptors/fetch-request.interceptor'
|
||||
import { Injectable } from '@nestjs/common'
|
||||
|
||||
@Injectable()
|
||||
export class HttpClientUtil {
|
||||
async request(
|
||||
url: string,
|
||||
init: RequestInit = {},
|
||||
interceptors: FetchRequestInterceptor[] = [],
|
||||
): Promise<Response> {
|
||||
let context: FetchRequestContext = { url, init }
|
||||
|
||||
for (const interceptor of interceptors) {
|
||||
if (!interceptor.onRequest) {
|
||||
continue
|
||||
}
|
||||
|
||||
context = await interceptor.onRequest(context)
|
||||
}
|
||||
|
||||
try {
|
||||
let response = await fetch(context.url, context.init)
|
||||
|
||||
for (const interceptor of interceptors) {
|
||||
if (!interceptor.onResponse) {
|
||||
continue
|
||||
}
|
||||
response = await interceptor.onResponse(context, response)
|
||||
console.log('response')
|
||||
console.log(response)
|
||||
}
|
||||
|
||||
return response
|
||||
} catch (error: any) {
|
||||
for (const interceptor of interceptors) {
|
||||
if (!interceptor.onError) {
|
||||
continue
|
||||
}
|
||||
await interceptor.onError(context, error)
|
||||
}
|
||||
throw error
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,3 +3,4 @@ export * from './enum-translator.util'
|
||||
export * from './mappers/consumer_mappers.util'
|
||||
export * from './password.util'
|
||||
export * from './tracking-code-generator.util'
|
||||
export * from './http-client.util'
|
||||
|
||||
Reference in New Issue
Block a user