813ab5db7b
新增 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。
32 lines
1.2 KiB
TypeScript
32 lines
1.2 KiB
TypeScript
/** 店铺编辑表单模型(任务 92):由店铺行预填可编辑字段(分组/名称/账号),纯逻辑。 */
|
|
import type { ShopSummary } from './shop-dto.ts'
|
|
import type { ShopManageFormValues } from './shop-manage-form-model.ts'
|
|
|
|
function finiteId(value: unknown): number | null {
|
|
return typeof value === 'number' && Number.isFinite(value) && value >= 1 ? Math.floor(value) : null
|
|
}
|
|
|
|
function groupIdOr(item: ShopSummary): number | null {
|
|
return typeof item.groupId === 'number' && Number.isFinite(item.groupId) && item.groupId >= 1
|
|
? Math.floor(item.groupId)
|
|
: null
|
|
}
|
|
|
|
function textField(value: unknown): string {
|
|
return typeof value === 'string' ? value : ''
|
|
}
|
|
|
|
/** 由店铺行预填编辑表单:密码掩码不回填明文,需保存时重新录入(后端更新要求必填)。 */
|
|
export function buildShopManageEditForm(item: ShopSummary | null | undefined): ShopManageFormValues | null {
|
|
if (!item || typeof item !== 'object') return null
|
|
if (finiteId(item.id) === null) return null
|
|
return {
|
|
groupId: groupIdOr(item),
|
|
shopName: textField(item.shopName),
|
|
mallName: textField(item.mallName),
|
|
znUsername: textField(item.znUsername),
|
|
account: textField(item.account),
|
|
password: '',
|
|
}
|
|
}
|