import { $fetch } from 'ofetch' import { createError, defineEventHandler, getHeader, getCookie } from 'h3' import { useRuntimeConfig } from '#imports' import { getTenantFromContext } from '../../utils/tenant' /** * 我的企业资质(含证件材料) * GET /api/tender/enterprise * 代理到 mp-api /api/hjc/enterprise/my;需登录态。 */ export default defineEventHandler(async (event) => { const config = useRuntimeConfig() const ctx = getTenantFromContext(event, config) const cookieToken = getCookie(event, 'hjc_token') const auth = getHeader(event, 'authorization') || (cookieToken ? `Bearer ${cookieToken}` : null) try { const res = await $fetch('/hjc/enterprise/my', { baseURL: config.public.modulesApiBase, headers: { TenantId: ctx.tenantId, ...(auth ? { Authorization: auth } : {}) }, query: { TenantId: ctx.tenantId } }) as any const data = res && res.data !== undefined ? res.data : res return data } catch (error: any) { throw createError({ statusCode: error?.statusCode || error?.response?.status || 502, statusMessage: error?.statusMessage || 'Failed to fetch enterprise' }) } })