task-85(店铺中心): 实现编辑店铺密钥表单

新增 shop-key-edit-model.ts(由列表行预填备注/紫鸟账号/令牌,令牌仅内存内
沿用) 并在 shop-key-api.ts 增加 updateShopKey(PUT /api/admin/shop-keys/{id})。

TDD: task-85.test.ts 8 用例先 RED 后 GREEN。
This commit is contained in:
2026-09-05 16:39:04 +08:00
parent 72a8f75dc5
commit be6a17d4bd
3 changed files with 128 additions and 0 deletions
@@ -36,3 +36,17 @@ export async function submitCreateShopKey(form: ShopKeyFormValues): Promise<Shop
}
return item
}
/** 提交更新店铺密钥:编辑沿用原令牌/账号,更新体字段与新增一致;PUT /api/admin/shop-keys/{id}。 */
export async function updateShopKey(id: number, form: ShopKeyFormValues): Promise<ShopKeyItem> {
const { valid, errors } = validateShopKeyForm(form)
if (!valid) {
throw new Error(Object.values(errors)[0] || '店铺密钥表单校验未通过')
}
const { data } = await http.put<unknown>(`${SHOP_KEYS_ENDPOINT}/${id}`, toShopKeyCreateRequest(form))
const item = toShopKeyItem(unwrap<unknown>(data))
if (!item) {
throw new Error('更新店铺密钥响应异常:未返回有效记录')
}
return item
}
@@ -0,0 +1,20 @@
/** 店铺密钥编辑表单模型(任务 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 : '',
}
}