task-91(店铺中心): 实现新增店铺表单
新增 shop-manage-form-model.ts(分组/店铺名/商城/账号/密码校验与 camel 创建 请求体,密码按敏感字段处理) 并在 shop-manage-api.ts 增加 submitCreateShopManage (POST /api/admin/shop-manages,createdById 由当前会话提供)。 TDD: task-91.test.ts 8 用例先 RED 后 GREEN。
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
/** 店铺列表加载与分组选项适配(任务 88/90):GET /api/admin/shop-manages(/groups) + 归一与解析。 */
|
||||
/** 店铺列表/分组/新增适配(任务 88/90/91):GET|POST /api/admin/shop-manages + 归一与解析。 */
|
||||
import { http } from '@/api/http'
|
||||
import { parseShopManagePage } from './shop-manage-model.ts'
|
||||
import { unwrap } from '@/api/envelope'
|
||||
import { parseShopManagePage, toShopSummary } from './shop-manage-model.ts'
|
||||
import { parseShopManageGroups } from './shop-group-model.ts'
|
||||
import {
|
||||
normalizeShopListParams,
|
||||
@@ -8,7 +9,13 @@ import {
|
||||
type ShopGroupOption,
|
||||
type ShopManageListParams,
|
||||
type ShopPageResult,
|
||||
type ShopSummary,
|
||||
} from './shop-dto.ts'
|
||||
import {
|
||||
toShopManageCreateRequest,
|
||||
validateShopManageForm,
|
||||
type ShopManageFormValues,
|
||||
} from './shop-manage-form-model.ts'
|
||||
|
||||
export const SHOP_MANAGE_ENDPOINT = '/api/admin/shop-manages'
|
||||
|
||||
@@ -25,3 +32,17 @@ export async function fetchShopManageGroups(): Promise<ShopGroupOption[]> {
|
||||
const { data } = await http.get<unknown>(SHOP_MANAGE_GROUPS_ENDPOINT)
|
||||
return parseShopManageGroups(data)
|
||||
}
|
||||
|
||||
/** 提交新增店铺:先校验(失败抛首条错误不发请求),POST /api/admin/shop-manages,解析返回记录。 */
|
||||
export async function submitCreateShopManage(form: ShopManageFormValues, createdById: number): Promise<ShopSummary> {
|
||||
const { valid, errors } = validateShopManageForm(form)
|
||||
if (!valid) {
|
||||
throw new Error(Object.values(errors)[0] || '店铺表单校验未通过')
|
||||
}
|
||||
const { data } = await http.post<unknown>(SHOP_MANAGE_ENDPOINT, toShopManageCreateRequest(form, createdById))
|
||||
const item = toShopSummary(unwrap<unknown>(data))
|
||||
if (!item) {
|
||||
throw new Error('新增店铺响应异常:未返回有效记录')
|
||||
}
|
||||
return item
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user