重构后台管理服务并推进渐进式类型化
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
// @ts-check
|
||||
|
||||
import { query } from '../db/client.js'
|
||||
|
||||
/** @typedef {import('../types/repository-rows.js').TaskInventoryBindingRow} TaskInventoryBindingRow */
|
||||
/** @typedef {import('../types/repository-rows.js').TaskInventoryBindingSummaryRow} TaskInventoryBindingSummaryRow */
|
||||
|
||||
/** @returns {Promise<TaskInventoryBindingRow[]>} */
|
||||
export async function listTaskInventoryBindingsByTaskId(taskId) {
|
||||
const result = await query(
|
||||
`
|
||||
@@ -29,9 +35,10 @@ export async function listTaskInventoryBindingsByTaskId(taskId) {
|
||||
[Number(taskId)],
|
||||
)
|
||||
|
||||
return result.rows
|
||||
return /** @type {TaskInventoryBindingRow[]} */ (result.rows)
|
||||
}
|
||||
|
||||
/** @returns {Promise<TaskInventoryBindingRow | null>} */
|
||||
export async function getTaskInventoryBindingById(bindingId) {
|
||||
const result = await query(
|
||||
`
|
||||
@@ -61,9 +68,10 @@ export async function getTaskInventoryBindingById(bindingId) {
|
||||
[Number(bindingId)],
|
||||
)
|
||||
|
||||
return result.rows[0] || null
|
||||
return /** @type {TaskInventoryBindingRow | null} */ (result.rows[0] || null)
|
||||
}
|
||||
|
||||
/** @returns {Promise<TaskInventoryBindingSummaryRow[]>} */
|
||||
export async function listTaskInventoryBindingSummariesByTaskIds(taskIds = []) {
|
||||
const normalizedTaskIds = Array.from(new Set((Array.isArray(taskIds) ? taskIds : [])
|
||||
.map((value) => Number(value))
|
||||
@@ -89,5 +97,5 @@ export async function listTaskInventoryBindingSummariesByTaskIds(taskIds = []) {
|
||||
[normalizedTaskIds],
|
||||
)
|
||||
|
||||
return result.rows
|
||||
return /** @type {TaskInventoryBindingSummaryRow[]} */ (result.rows)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user