Files
crawler-plugin/admin-frontend-vue/src/pages/shop/shop-manage-api.ts
T
huangzd1997 554ff64aa7 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。
2026-09-05 16:47:01 +08:00

64 lines
2.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/** 店铺列表/分组/新增适配(任务 88/90/91):GET|POST /api/admin/shop-manages + 归一与解析。 */
import { http } from '@/api/http'
import { unwrap } from '@/api/envelope'
import { parseShopManagePage, toShopSummary } from './shop-manage-model.ts'
import { parseShopManageGroups } from './shop-group-model.ts'
import {
normalizeShopListParams,
toShopManagePageQuery,
type ShopGroupOption,
type ShopManageListParams,
type ShopPageResult,
type ShopSummary,
} from './shop-dto.ts'
import {
toShopManageCreateRequest,
toShopManageUpdateRequest,
validateShopManageForm,
type ShopManageFormValues,
} from './shop-manage-form-model.ts'
export const SHOP_MANAGE_ENDPOINT = '/api/admin/shop-manages'
export async function fetchShopManageList(params: Partial<ShopManageListParams> = {}): Promise<ShopPageResult> {
const normalized = normalizeShopListParams(params)
const { data } = await http.get<unknown>(SHOP_MANAGE_ENDPOINT, { params: toShopManagePageQuery(normalized) })
return parseShopManagePage(data)
}
export const SHOP_MANAGE_GROUPS_ENDPOINT = '/api/admin/shop-manages/groups'
/** 加载店铺分组下拉选项(超级管理员取全部,普通管理员由后端限定可访问分组)。 */
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
}
/** 提交编辑店铺:先校验(失败抛首条错误不发请求),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
}