重构后台管理服务并推进渐进式类型化

This commit is contained in:
yml2213
2026-04-14 09:21:20 +08:00
parent fa36be6539
commit 335eb44104
35 changed files with 4143 additions and 2738 deletions
@@ -1,5 +1,11 @@
// @ts-check
import { query } from '../db/client.js'
/** @typedef {import('../types/repository-inputs.js').OrderItemReplaceInput} OrderItemReplaceInput */
/** @typedef {import('../types/repository-rows.js').OrderItemRow} OrderItemRow */
/** @returns {Promise<OrderItemRow[]>} */
export async function listOrderItemsByOrderId(orderId) {
const result = await query(
`
@@ -11,9 +17,11 @@ export async function listOrderItemsByOrderId(orderId) {
[Number(orderId)],
)
return result.rows
return /** @type {OrderItemRow[]} */ (result.rows)
}
/** @returns {Promise<OrderItemRow[]>} */
/** @param {OrderItemReplaceInput[]} items */
export async function replaceOrderItems(orderId, items) {
await query('DELETE FROM order_items WHERE order_id = $1', [Number(orderId)])
@@ -47,7 +55,8 @@ export async function replaceOrderItems(orderId, items) {
return listOrderItemsByOrderId(orderId)
}
/** @returns {Promise<OrderItemRow | null>} */
export async function getOrderItemById(orderItemId) {
const result = await query('SELECT * FROM order_items WHERE id = $1 LIMIT 1', [Number(orderItemId)])
return result.rows[0] || null
return /** @type {OrderItemRow | null} */ (result.rows[0] || null)
}