38 lines
1.3 KiB
TypeScript
38 lines
1.3 KiB
TypeScript
import { $fetch } from 'ofetch'
|
|
import { createError, defineEventHandler, readBody, getHeader, getCookie } from 'h3'
|
|
import { useRuntimeConfig } from '#imports'
|
|
import { getTenantFromContext } from '../../../utils/tenant'
|
|
|
|
/**
|
|
* 提交/更新企业资质(信息+证件)
|
|
* POST /api/tender/enterprise/save { name, creditCode, ..., materials: [] }
|
|
* 代理到 mp-api /api/hjc/enterprise/save;需登录态。
|
|
*/
|
|
export default defineEventHandler(async (event) => {
|
|
const config = useRuntimeConfig()
|
|
const ctx = getTenantFromContext(event, config)
|
|
const body = await readBody(event)
|
|
const cookieToken = getCookie(event, 'hjc_token')
|
|
const auth = getHeader(event, 'authorization') || (cookieToken ? `Bearer ${cookieToken}` : null)
|
|
|
|
try {
|
|
const res = await $fetch('/hjc/enterprise/save', {
|
|
baseURL: config.public.modulesApiBase,
|
|
method: 'POST',
|
|
headers: {
|
|
TenantId: ctx.tenantId,
|
|
...(auth ? { Authorization: auth } : {})
|
|
},
|
|
query: { TenantId: ctx.tenantId },
|
|
body
|
|
}) 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 save enterprise'
|
|
})
|
|
}
|
|
})
|