后端迁移后台管理读侧映射
This commit is contained in:
+4
-10
@@ -1,19 +1,13 @@
|
||||
// @ts-check
|
||||
|
||||
import { getInventoryItemById } from '../../repositories/inventory-repo.js'
|
||||
import { getOrderById } from '../../repositories/order-repo.js'
|
||||
import { getTaskById } from '../../repositories/task-repo.js'
|
||||
import { createHttpError } from '../../utils/http.js'
|
||||
import { mapAdminTaskSummary } from './admin-task-read-helpers.js'
|
||||
|
||||
/** @typedef {import('../../types/admin-read-models.js').AdminInventoryItemListItem} AdminInventoryItemListItem */
|
||||
/** @typedef {import('../../types/repository-rows.js').InventoryItemRow} InventoryItemRow */
|
||||
import type { AdminInventoryItemListItem } from '../../types/admin-read-models.js'
|
||||
import type { InventoryItemRow } from '../../types/repository-rows.js'
|
||||
|
||||
/**
|
||||
* @param {InventoryItemRow} item
|
||||
* @returns {Promise<AdminInventoryItemListItem>}
|
||||
*/
|
||||
export async function mapAdminInventoryListItem(item) {
|
||||
export async function mapAdminInventoryListItem(item: InventoryItemRow): Promise<AdminInventoryItemListItem> {
|
||||
const task = item.reserved_by_task_id ? await getTaskById(item.reserved_by_task_id) : null
|
||||
const order = task?.order_id ? await getOrderById(task.order_id) : null
|
||||
const taskSummary = task ? mapAdminTaskSummary(task) : null
|
||||
@@ -38,7 +32,7 @@ export async function mapAdminInventoryListItem(item) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function getRequiredInventoryItem(inventoryItemId) {
|
||||
export async function getRequiredInventoryItem(inventoryItemId: number | string): Promise<InventoryItemRow> {
|
||||
const inventoryItem = await getInventoryItemById(Number(inventoryItemId))
|
||||
|
||||
if (!inventoryItem) {
|
||||
+4
-10
@@ -1,19 +1,13 @@
|
||||
// @ts-check
|
||||
|
||||
import { listOrderItemsByOrderId } from '../../repositories/order-item-repo.js'
|
||||
import { listTasksByOrderId } from '../../repositories/task-repo.js'
|
||||
import { formatFenToAmount, normalizeFen } from '../../utils/money.js'
|
||||
import { resolveDisplayShopName, resolveOrderItemTitle } from './admin-read-shared-helpers.js'
|
||||
import { buildOrderBindingSummary, getTaskBindingSummaryMap } from './admin-task-read-helpers.js'
|
||||
|
||||
/** @typedef {import('../../types/admin-read-models.js').AdminOrderListItem} AdminOrderListItem */
|
||||
/** @typedef {import('../../types/repository-rows.js').OrderListRow} OrderListRow */
|
||||
import type { AdminOrderListItem } from '../../types/admin-read-models.js'
|
||||
import type { OrderItemRow, OrderListRow } from '../../types/repository-rows.js'
|
||||
|
||||
/**
|
||||
* @param {OrderListRow} item
|
||||
* @returns {Promise<AdminOrderListItem>}
|
||||
*/
|
||||
export async function mapAdminOrderListItem(item) {
|
||||
export async function mapAdminOrderListItem(item: OrderListRow): Promise<AdminOrderListItem> {
|
||||
const [tasks, orderItems] = await Promise.all([
|
||||
listTasksByOrderId(item.id),
|
||||
listOrderItemsByOrderId(item.id),
|
||||
@@ -55,7 +49,7 @@ export async function mapAdminOrderListItem(item) {
|
||||
}
|
||||
}
|
||||
|
||||
export function summarizeOrderItems(items) {
|
||||
export function summarizeOrderItems(items: OrderItemRow[] | null | undefined): string {
|
||||
const normalizedItems = Array.isArray(items) ? items : []
|
||||
|
||||
if (normalizedItems.length === 0) {
|
||||
-2
@@ -1,5 +1,3 @@
|
||||
// @ts-check
|
||||
|
||||
export {
|
||||
getRequiredInventoryItem,
|
||||
mapAdminInventoryListItem,
|
||||
+17
-14
@@ -1,19 +1,22 @@
|
||||
// @ts-check
|
||||
|
||||
import { listTasksByOrderId } from '../../repositories/task-repo.js'
|
||||
import { formatFenToAmount, parseAmountToFen } from '../../utils/money.js'
|
||||
import { extractAgisoTradePayload, resolveAgisoTradePlatformOrderId } from '../order/agiso-trade-parsing.js'
|
||||
import { safeParseJson } from './admin-query-utils.js'
|
||||
import { resolveDisplayShopName } from './admin-read-shared-helpers.js'
|
||||
|
||||
/** @typedef {import('../../types/admin-read-models.js').AdminWebhookEventListItem} AdminWebhookEventListItem */
|
||||
/** @typedef {import('../../types/repository-rows.js').WebhookEventRow} WebhookEventRow */
|
||||
import type { AdminWebhookEventListItem } from '../../types/admin-read-models.js'
|
||||
import type { WebhookEventRow } from '../../types/repository-rows.js'
|
||||
|
||||
/**
|
||||
* @param {WebhookEventRow} item
|
||||
* @returns {Promise<AdminWebhookEventListItem>}
|
||||
*/
|
||||
export async function mapAdminWebhookEvent(item, { includeRaw = false } = {}) {
|
||||
type JsonRecord = Record<string, any>
|
||||
|
||||
type MapAdminWebhookEventOptions = {
|
||||
includeRaw?: boolean
|
||||
}
|
||||
|
||||
export async function mapAdminWebhookEvent(
|
||||
item: WebhookEventRow,
|
||||
{ includeRaw = false }: MapAdminWebhookEventOptions = {},
|
||||
): Promise<AdminWebhookEventListItem> {
|
||||
const headers = normalizeRecord(safeParseJson(item.headers_json))
|
||||
const query = normalizeRecord(safeParseJson(item.query_json))
|
||||
const body = normalizeRecord(safeParseJson(item.body_json))
|
||||
@@ -131,11 +134,11 @@ export async function mapAdminWebhookEvent(item, { includeRaw = false } = {}) {
|
||||
}
|
||||
}
|
||||
|
||||
function extractWebhookPayload(body) {
|
||||
function extractWebhookPayload(body: JsonRecord): JsonRecord {
|
||||
return extractAgisoTradePayload(body)
|
||||
}
|
||||
|
||||
function extractWebhookItemSources(payload) {
|
||||
function extractWebhookItemSources(payload: unknown): JsonRecord[] {
|
||||
const normalizedPayload = normalizeRecord(payload)
|
||||
const candidates = [
|
||||
normalizedPayload.orders,
|
||||
@@ -167,7 +170,7 @@ function extractWebhookItemSources(payload) {
|
||||
return []
|
||||
}
|
||||
|
||||
export function resolveWebhookVisibilityLevel(processError) {
|
||||
export function resolveWebhookVisibilityLevel(processError: unknown): string {
|
||||
const normalized = String(processError || '').trim()
|
||||
|
||||
if (normalized.startsWith('ignored_')) {
|
||||
@@ -177,11 +180,11 @@ export function resolveWebhookVisibilityLevel(processError) {
|
||||
return 'important'
|
||||
}
|
||||
|
||||
function normalizeRecord(value) {
|
||||
function normalizeRecord(value: unknown): JsonRecord {
|
||||
return value && typeof value === 'object' && !Array.isArray(value) ? value : {}
|
||||
}
|
||||
|
||||
function pickFirstNonEmpty(values) {
|
||||
function pickFirstNonEmpty(values: unknown[]): string {
|
||||
for (const value of values) {
|
||||
if (typeof value === 'string' && value.trim()) {
|
||||
return value.trim()
|
||||
Reference in New Issue
Block a user