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:
@@ -33,6 +33,16 @@ export interface ShopManageCreatePayload {
|
||||
znUsername?: string
|
||||
}
|
||||
|
||||
/** 发送 PUT /api/admin/shop-manages/{id} 的请求体(与 Java ShopManageUpdateRequest camelCase 对齐)。 */
|
||||
export interface ShopManageUpdatePayload {
|
||||
groupId: number
|
||||
shopName: string
|
||||
mallName: string
|
||||
account: string
|
||||
password: string
|
||||
znUsername?: string
|
||||
}
|
||||
|
||||
export function emptyShopManageForm(): ShopManageFormValues {
|
||||
return { groupId: null, shopName: '', mallName: '', znUsername: '', account: '', password: '' }
|
||||
}
|
||||
@@ -66,8 +76,18 @@ export function validateShopManageForm(form: ShopManageFormValues): { valid: boo
|
||||
return { valid: Object.keys(errors).length === 0, errors }
|
||||
}
|
||||
|
||||
/** 新增表单 → 创建请求体;缺有效分组/必填时抛可操作错误(调用前应先校验)。 */
|
||||
export function toShopManageCreateRequest(form: ShopManageFormValues, createdById: number): ShopManageCreatePayload {
|
||||
/** 新增/更新共用的必填业务段。 */
|
||||
interface ManagePayloadBase {
|
||||
groupId: number
|
||||
shopName: string
|
||||
mallName: string
|
||||
account: string
|
||||
password: string
|
||||
znUsername?: string
|
||||
}
|
||||
|
||||
/** 通用必填段(校验 + 归一);缺有效分组/必填时抛可操作错误(调用前应先校验)。 */
|
||||
function requiredBase(form: ShopManageFormValues): ManagePayloadBase {
|
||||
const groupId = positiveGroupId(form.groupId)
|
||||
if (groupId === null) {
|
||||
throw new Error('分组不能为空')
|
||||
@@ -76,15 +96,24 @@ export function toShopManageCreateRequest(form: ShopManageFormValues, createdByI
|
||||
if (!errorText(form.mallName)) throw new Error('商城名称不能为空')
|
||||
if (!errorText(form.account)) throw new Error('账号不能为空')
|
||||
if (!errorText(form.password)) throw new Error('密码不能为空')
|
||||
const payload: ShopManageCreatePayload = {
|
||||
const payload: ManagePayloadBase = {
|
||||
groupId,
|
||||
shopName: errorText(form.shopName),
|
||||
mallName: errorText(form.mallName),
|
||||
account: errorText(form.account),
|
||||
password: errorText(form.password),
|
||||
createdById,
|
||||
}
|
||||
const znUsername = (form.znUsername || '').trim()
|
||||
if (znUsername) payload.znUsername = znUsername
|
||||
return payload
|
||||
}
|
||||
|
||||
/** 新增表单 → 创建请求体(含 createdById)。 */
|
||||
export function toShopManageCreateRequest(form: ShopManageFormValues, createdById: number): ShopManageCreatePayload {
|
||||
return { ...requiredBase(form), createdById }
|
||||
}
|
||||
|
||||
/** 编辑表单 → 更新请求体(与新增同字段,不含 createdById)。 */
|
||||
export function toShopManageUpdateRequest(form: ShopManageFormValues): ShopManageUpdatePayload {
|
||||
return requiredBase(form)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user