Files

40 lines
1.2 KiB
TypeScript

import { $fetch } from 'ofetch'
import { createError, defineEventHandler, getQuery } from 'h3'
import { useRuntimeConfig } from '#imports'
import { getTenantFromContext } from '../../utils/tenant'
/**
* 标书项目列表
* GET /api/tender/list?page=1&limit=10&keywords=xx&category=xx
* 代理到后端 hjc 标书项目列表(仅上架 status=1),归一化为 { list, count }。
*/
export default defineEventHandler(async (event) => {
const config = useRuntimeConfig()
const ctx = getTenantFromContext(event, config)
const query = getQuery(event)
const modulesApiBase = config.public.modulesApiBase as string
try {
const res = await $fetch('/hjc/bid-project/list', {
baseURL: modulesApiBase,
headers: { TenantId: ctx.tenantId },
query: {
...query,
status: 1,
TenantId: ctx.tenantId
}
}) as any
const data = (res && res.data !== undefined ? res.data : res) || {}
return {
list: Array.isArray(data.list) ? data.list : [],
count: data.count ?? data.total ?? 0
}
} catch (error: any) {
throw createError({
statusCode: error?.statusCode || error?.response?.status || 502,
statusMessage: error?.statusMessage || 'Failed to fetch tender list'
})
}
})