forked from Shared/esg
final update on moallm client
This commit is contained in:
32
src/common/helpers/inquiry-response.helper.ts
Normal file
32
src/common/helpers/inquiry-response.helper.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { BaseInquiryResponseDto } from '../dto/base-inquiry-response.dto';
|
||||
import { NormalizedErrorDto } from '../dto/normalized-error.dto';
|
||||
|
||||
export function buildInquiryResponse<T = Record<string, unknown>>(params: {
|
||||
success: boolean;
|
||||
provider: string;
|
||||
trackingCode: string;
|
||||
message: string;
|
||||
duration: number;
|
||||
data?: T | null;
|
||||
error?: NormalizedErrorDto | null;
|
||||
}): BaseInquiryResponseDto<T> {
|
||||
return {
|
||||
success: params.success,
|
||||
provider: params.provider,
|
||||
trackingCode: params.trackingCode,
|
||||
message: params.message,
|
||||
duration: params.duration,
|
||||
data: params.success ? (params.data ?? null) : null,
|
||||
error: params.success ? null : (params.error ?? null),
|
||||
};
|
||||
}
|
||||
|
||||
export function normalizeInquiryResponse<T = Record<string, unknown>>(
|
||||
response: BaseInquiryResponseDto<T>,
|
||||
): BaseInquiryResponseDto<T> {
|
||||
return {
|
||||
...response,
|
||||
data: response.success ? (response.data ?? null) : null,
|
||||
error: response.success ? null : (response.error ?? null),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user