36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import { http, unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http'
|
|||
|
|
import type {
|
||
|
|
CustomerDimensionConfig,
|
||
|
|
UpdateCustomerDimensionConfigRequest,
|
||
|
|
} from './types'
|
||
|
|
|
||
|
|
const dimensionConfigPath = '/platform/v1/first-leg/customer-dimension-config'
|
||
|
|
|
||
|
|
type RawDimensionConfig = Omit<CustomerDimensionConfig, 'tenantId'> & {
|
||
|
|
tenantId: string | number
|
||
|
|
}
|
||
|
|
|
||
|
|
function normalizeConfig(config: RawDimensionConfig): CustomerDimensionConfig {
|
||
|
|
return {
|
||
|
|
...config,
|
||
|
|
tenantId: String(config.tenantId),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function getCustomerDimensionConfig(tenantId: string): Promise<CustomerDimensionConfig> {
|
||
|
|
const response = await http.get<never, ApiEnvelope<RawDimensionConfig>>(dimensionConfigPath, {
|
||
|
|
params: { tenantId },
|
||
|
|
})
|
||
|
|
return normalizeConfig(unwrapApiResponse(response))
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function updateCustomerDimensionConfig(
|
||
|
|
tenantId: string,
|
||
|
|
request: UpdateCustomerDimensionConfigRequest,
|
||
|
|
): Promise<CustomerDimensionConfig> {
|
||
|
|
const response = await http.put<never, ApiEnvelope<RawDimensionConfig>>(dimensionConfigPath, request, {
|
||
|
|
params: { tenantId },
|
||
|
|
})
|
||
|
|
return normalizeConfig(unwrapApiResponse(response))
|
||
|
|
}
|