task-84(店铺中心): 实现新增店铺密钥表单
新增 shop-key-form-model.ts(备注/紫鸟账号/令牌校验与 camel 请求体序列化, 镜像 Java NotBlank/Size 规则,令牌去 Bearer 前缀) 并在 shop-key-api.ts 增加 submitCreateShopKey(POST /api/admin/shop-keys)。 TDD: task-84.test.ts 8 用例先 RED 后 GREEN。
This commit is contained in:
@@ -1,7 +1,19 @@
|
||||
/** 店铺密钥列表加载适配(任务 82):GET /api/admin/shop-keys + 分页归一与解析。 */
|
||||
/** 店铺密钥列表加载与新增适配(任务 82/84):GET/POST /api/admin/shop-keys + 归一与解析。 */
|
||||
import { http } from '@/api/http'
|
||||
import { parseShopKeyPage } from './shop-key-model'
|
||||
import { normalizeKeyListParams, toKeyPageQuery, type ShopKeyListParams, type ShopKeyPageResult } from './shop-dto.ts'
|
||||
import { unwrap } from '@/api/envelope'
|
||||
import { parseShopKeyPage, toShopKeyItem } from './shop-key-model.ts'
|
||||
import {
|
||||
normalizeKeyListParams,
|
||||
toKeyPageQuery,
|
||||
type ShopKeyItem,
|
||||
type ShopKeyListParams,
|
||||
type ShopKeyPageResult,
|
||||
} from './shop-dto.ts'
|
||||
import {
|
||||
toShopKeyCreateRequest,
|
||||
validateShopKeyForm,
|
||||
type ShopKeyFormValues,
|
||||
} from './shop-key-form-model.ts'
|
||||
|
||||
export const SHOP_KEYS_ENDPOINT = '/api/admin/shop-keys'
|
||||
|
||||
@@ -10,3 +22,17 @@ export async function fetchShopKeyList(params: Partial<ShopKeyListParams> = {}):
|
||||
const { data } = await http.get<unknown>(SHOP_KEYS_ENDPOINT, { params: toKeyPageQuery(normalized) })
|
||||
return parseShopKeyPage(data)
|
||||
}
|
||||
|
||||
/** 提交新增店铺密钥:先校验(失败抛首条错误不发请求),再 POST,解析返回的新记录。 */
|
||||
export async function submitCreateShopKey(form: ShopKeyFormValues): Promise<ShopKeyItem> {
|
||||
const { valid, errors } = validateShopKeyForm(form)
|
||||
if (!valid) {
|
||||
throw new Error(Object.values(errors)[0] || '店铺密钥表单校验未通过')
|
||||
}
|
||||
const { data } = await http.post<unknown>(SHOP_KEYS_ENDPOINT, toShopKeyCreateRequest(form))
|
||||
const item = toShopKeyItem(unwrap<unknown>(data))
|
||||
if (!item) {
|
||||
throw new Error('新增店铺密钥响应异常:未返回有效记录')
|
||||
}
|
||||
return item
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user