重构后台管理服务并推进渐进式类型化
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user