Files
admin-web/src/modules/fba-pricing/customer-rules/api.ts
T
2026-08-04 21:01:39 +08:00

60 lines
1.9 KiB
TypeScript

import { http, unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http'
import type {
CreateCustomerRuleVersionRequest,
CustomerPricingRule,
CustomerRuleQuery,
} from './types'
type RawRule = Omit<CustomerPricingRule, 'id' | 'tenantId' | 'customerId'> & {
id: string | number
tenantId: string | number
customerId: string | number
}
function normalizeRule(rule: RawRule): CustomerPricingRule {
return {
...rule,
id: String(rule.id),
tenantId: String(rule.tenantId),
customerId: String(rule.customerId),
}
}
export async function listCustomerPricingRules(query: CustomerRuleQuery): Promise<CustomerPricingRule[]> {
const tenantId = query.tenantId?.trim()
const ruleCode = query.ruleCode?.trim()
const response = await http.get<never, ApiEnvelope<RawRule[]>>('/platform/v1/fba-pricing/customer-rules', {
params: {
...(tenantId ? { tenantId } : {}),
...(ruleCode ? { ruleCode } : {}),
},
})
return unwrapApiResponse(response).map(normalizeRule)
}
export async function getCustomerPricingRule(tenantId: string, id: string): Promise<CustomerPricingRule> {
const response = await http.get<never, ApiEnvelope<RawRule>>(`/platform/v1/fba-pricing/customer-rules/${id}`, {
params: { tenantId },
})
return normalizeRule(unwrapApiResponse(response))
}
export async function createCustomerPricingRuleVersion(
tenantId: string,
request: CreateCustomerRuleVersionRequest,
): Promise<CustomerPricingRule> {
const response = await http.post<never, ApiEnvelope<RawRule>>(
'/platform/v1/fba-pricing/customer-rules/versions',
request,
{ params: { tenantId } },
)
return normalizeRule(unwrapApiResponse(response))
}
export async function disableCustomerPricingRule(tenantId: string, id: string): Promise<void> {
const response = await http.delete<never, ApiEnvelope<unknown>>(`/platform/v1/fba-pricing/customer-rules/${id}`, {
params: { tenantId },
})
unwrapApiResponse(response)
}