45 lines
2.4 KiB
TypeScript
45 lines
2.4 KiB
TypeScript
/**
|
|
* features/admin/api/shipping-identity-rules.api.ts
|
|
* 用途:调用货代可配置客户识别定义和规则集管理 API。
|
|
* 依赖:requestJson、认证请求头、规则 DTO。
|
|
* 逻辑:所有写入由后端校验已发布上下文字段、版本锁和自动化风险上限。
|
|
*/
|
|
|
|
import { requestJson } from '@/shared/api/client';
|
|
import { getAuthHeaders } from '@/shared/utils/auth';
|
|
import type { ShippingIdentityDefinition, ShippingIdentityRuleCatalog, ShippingIdentityRuleSet } from '../types/shipping-identity-rules.types';
|
|
|
|
const auth = () => ({ headers: getAuthHeaders() });
|
|
const jsonAuth = () => ({ headers: { 'Content-Type': 'application/json', ...getAuthHeaders() } });
|
|
|
|
export const getShippingIdentityRuleCatalog = () =>
|
|
requestJson<ShippingIdentityRuleCatalog>('/api/admin/shipping-identity-rules/definitions', auth());
|
|
|
|
export const saveShippingIdentityDefinition = (payload: Record<string, unknown>, id?: string) =>
|
|
requestJson<ShippingIdentityDefinition>(`/api/admin/shipping-identity-rules/definitions${id ? `/${id}` : ''}`, {
|
|
method: id ? 'PUT' : 'POST', body: JSON.stringify(payload), ...jsonAuth(),
|
|
});
|
|
|
|
export const retireShippingIdentityDefinition = (id: string) =>
|
|
requestJson<ShippingIdentityDefinition>(`/api/admin/shipping-identity-rules/definitions/${id}/retire`, {
|
|
method: 'POST', ...jsonAuth(),
|
|
});
|
|
|
|
export const listShippingIdentityRuleSets = () =>
|
|
requestJson<{ items: ShippingIdentityRuleSet[] }>('/api/admin/shipping-identity-rules/rule-sets', auth());
|
|
|
|
export const createShippingIdentityRuleSet = (payload: { copy_from_rule_set_id?: number; change_note?: string }) =>
|
|
requestJson<ShippingIdentityRuleSet>('/api/admin/shipping-identity-rules/rule-sets', {
|
|
method: 'POST', body: JSON.stringify(payload), ...jsonAuth(),
|
|
});
|
|
|
|
export const saveShippingIdentityRuleSet = (id: number, payload: { definition_ids: string[]; expected_lock_version: number; change_note?: string }) =>
|
|
requestJson<ShippingIdentityRuleSet>(`/api/admin/shipping-identity-rules/rule-sets/${id}`, {
|
|
method: 'PUT', body: JSON.stringify(payload), ...jsonAuth(),
|
|
});
|
|
|
|
export const publishShippingIdentityRuleSet = (id: number, expectedLockVersion: number) =>
|
|
requestJson<ShippingIdentityRuleSet>(`/api/admin/shipping-identity-rules/rule-sets/${id}/publish`, {
|
|
method: 'POST', body: JSON.stringify({ expected_lock_version: expectedLockVersion }), ...jsonAuth(),
|
|
});
|