be6a17d4bd
新增 shop-key-edit-model.ts(由列表行预填备注/紫鸟账号/令牌,令牌仅内存内
沿用) 并在 shop-key-api.ts 增加 updateShopKey(PUT /api/admin/shop-keys/{id})。
TDD: task-85.test.ts 8 用例先 RED 后 GREEN。
21 lines
1.2 KiB
TypeScript
21 lines
1.2 KiB
TypeScript
/** 店铺密钥编辑表单模型(任务 85):由列表行预填编辑表单,镜像后端更新语义,纯逻辑。 */
|
|
import type { ShopKeyItem } from './shop-dto.ts'
|
|
import type { ShopKeyFormValues } from './shop-key-form-model.ts'
|
|
|
|
function finiteId(value: unknown): number | null {
|
|
return typeof value === 'number' && Number.isFinite(value) && value >= 1 ? Math.floor(value) : null
|
|
}
|
|
|
|
/** 由已有密钥行预填编辑表单:备注/紫鸟账号/令牌沿用原值。
|
|
* 令牌为敏感字段,仅在内存中供本次编辑使用,不写入页面状态外的地方;
|
|
* 编辑保存时后端要求重新提交令牌,故沿用原行令牌(表单层面以掩码展示,见任务 86)。 */
|
|
export function buildShopKeyEditForm(item: ShopKeyItem | null | undefined): ShopKeyFormValues | null {
|
|
if (!item || typeof item !== 'object') return null
|
|
if (finiteId(item.id) === null) return null
|
|
return {
|
|
remarkName: typeof item.remarkName === 'string' ? item.remarkName : '',
|
|
ziniaoAccountName: typeof item.ziniaoAccountName === 'string' ? item.ziniaoAccountName : '',
|
|
ziniaoToken: typeof item.ziniaoToken === 'string' ? item.ziniaoToken : '',
|
|
}
|
|
}
|