优化
This commit is contained in:
@@ -1,24 +1,34 @@
|
||||
import { http, unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http'
|
||||
import type {
|
||||
CustomerDimensionConfig,
|
||||
CustomerDimensionRule,
|
||||
UpdateCustomerDimensionConfigRequest,
|
||||
} from './types'
|
||||
|
||||
const dimensionConfigPath = '/platform/v1/first-leg/customer-dimension-config'
|
||||
|
||||
type RawDimensionConfig = Omit<CustomerDimensionConfig, 'tenantId'> & {
|
||||
type RawRule = Omit<CustomerDimensionRule, 'id' | 'version'> & {
|
||||
id: string | number
|
||||
version: string | number
|
||||
}
|
||||
type RawConfig = Omit<CustomerDimensionConfig, 'tenantId' | 'rules'> & {
|
||||
tenantId: string | number
|
||||
rules: RawRule[]
|
||||
}
|
||||
|
||||
function normalizeConfig(config: RawDimensionConfig): CustomerDimensionConfig {
|
||||
function normalizeRule(rule: RawRule): CustomerDimensionRule {
|
||||
return { ...rule, id: String(rule.id), version: Number(rule.version) }
|
||||
}
|
||||
|
||||
function normalizeConfig(config: RawConfig): CustomerDimensionConfig {
|
||||
return {
|
||||
...config,
|
||||
tenantId: String(config.tenantId),
|
||||
rules: config.rules.map(normalizeRule),
|
||||
}
|
||||
}
|
||||
|
||||
export async function getCustomerDimensionConfig(tenantId: string): Promise<CustomerDimensionConfig> {
|
||||
const response = await http.get<never, ApiEnvelope<RawDimensionConfig>>(dimensionConfigPath, {
|
||||
const response = await http.get<never, ApiEnvelope<RawConfig>>(dimensionConfigPath, {
|
||||
params: { tenantId },
|
||||
})
|
||||
return normalizeConfig(unwrapApiResponse(response))
|
||||
@@ -28,7 +38,7 @@ export async function updateCustomerDimensionConfig(
|
||||
tenantId: string,
|
||||
request: UpdateCustomerDimensionConfigRequest,
|
||||
): Promise<CustomerDimensionConfig> {
|
||||
const response = await http.put<never, ApiEnvelope<RawDimensionConfig>>(dimensionConfigPath, request, {
|
||||
const response = await http.put<never, ApiEnvelope<RawConfig>>(dimensionConfigPath, request, {
|
||||
params: { tenantId },
|
||||
})
|
||||
return normalizeConfig(unwrapApiResponse(response))
|
||||
|
||||
Reference in New Issue
Block a user