38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import type { Context } from '@netlify/functions'
|
|
import { guardMethod } from '../utils/method.js'
|
|
import { fail, ok } from '../utils/http.js'
|
|
import { readJson } from '../utils/request.js'
|
|
import { prisma } from '../utils/prisma.js'
|
|
import { withErrorBoundary } from '../utils/handler.js'
|
|
|
|
type SupplierInfoRequest = {
|
|
supplierIdentification?: string
|
|
}
|
|
|
|
export default withErrorBoundary(async (request: Request, _context: Context) => {
|
|
const methodResponse = guardMethod(request, ['POST'])
|
|
if (methodResponse) return methodResponse
|
|
|
|
const body = await readJson<SupplierInfoRequest>(request)
|
|
const supplierIdentification = String(body.supplierIdentification || '').trim().toLowerCase()
|
|
|
|
if (!supplierIdentification) {
|
|
return fail('供应商唯一标识不能为空')
|
|
}
|
|
|
|
const supplier = await prisma.supplierInfo.findUnique({
|
|
where: { supplierIdentification }
|
|
})
|
|
|
|
if (!supplier || supplier.deleted === 1) {
|
|
return fail('供应商信息未配置或已停用', 404, 'SUPPLIER_NOT_CONFIGURED')
|
|
}
|
|
|
|
return ok({
|
|
id: supplier.id,
|
|
supplierIdentification: supplier.supplierIdentification,
|
|
supplierId: supplier.supplierId,
|
|
supplierName: supplier.supplierName
|
|
})
|
|
})
|