task-92(店铺中心): 实现编辑店铺表单
新增 shop-manage-edit-form.ts(店铺行预填编辑字段,密码掩码不回填需重录),
补充 toShopManageUpdateRequest(不含 createdById),并在 shop-manage-api.ts 增加
submitUpdateShopManage(PUT /api/admin/shop-manages/{id})。
TDD: task-92.test.ts 8 用例先 RED 后 GREEN。
This commit is contained in:
@@ -13,6 +13,7 @@ import {
|
||||
} from './shop-dto.ts'
|
||||
import {
|
||||
toShopManageCreateRequest,
|
||||
toShopManageUpdateRequest,
|
||||
validateShopManageForm,
|
||||
type ShopManageFormValues,
|
||||
} from './shop-manage-form-model.ts'
|
||||
@@ -46,3 +47,17 @@ export async function submitCreateShopManage(form: ShopManageFormValues, created
|
||||
}
|
||||
return item
|
||||
}
|
||||
|
||||
/** 提交编辑店铺:先校验(失败抛首条错误不发请求),PUT /api/admin/shop-manages/{id}。 */
|
||||
export async function submitUpdateShopManage(id: number, form: ShopManageFormValues): Promise<ShopSummary> {
|
||||
const { valid, errors } = validateShopManageForm(form)
|
||||
if (!valid) {
|
||||
throw new Error(Object.values(errors)[0] || '店铺表单校验未通过')
|
||||
}
|
||||
const { data } = await http.put<unknown>(`${SHOP_MANAGE_ENDPOINT}/${id}`, toShopManageUpdateRequest(form))
|
||||
const item = toShopSummary(unwrap<unknown>(data))
|
||||
if (!item) {
|
||||
throw new Error('更新店铺响应异常:未返回有效记录')
|
||||
}
|
||||
return item
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user