This commit is contained in:
2026-08-07 20:07:37 +08:00
parent 28d0b81c5a
commit 99413ee155
27 changed files with 1065 additions and 595 deletions
+15 -5
View File
@@ -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))