import laravelHelper from "../../utils/laravelHelper"; import errorHandlingHelper from "../../utils/errorHandlingHelper"; import fetchHelper from "../../utils/fetchHelper"; // POST /api/ffn/bom-products-list // body: { orderSourceId } // Loads the Order Source and asks Laravel for all JTL BOM articles (Stücklisten) of the merchant, // each with its billOfMaterialsComponents and whether the master already exists in iDempiere. // Read-only — feeds the "Sync BOM components" modal. export default defineEventHandler(async (event) => { try { const token = await getTokenHelper(event) const body = await readBody(event) if (!body?.orderSourceId) return { status: 400, success: false, message: 'orderSourceId is required' } const os: any = await fetchHelper(event, `models/c_ordersource/${body.orderSourceId}`, 'GET', token, null) if (!os) return { status: 404, success: false, message: 'Order Source not found' } const res: any = await laravelHelper(event, 'fulfiller/bom-products-list', 'POST', { orderSource: os }) return { status: 200, ...(res || {}) } } catch (err: any) { const data = errorHandlingHelper(err?.data ?? err, err?.data ?? err) return { status: Number(data?.status || err?.status || 500), success: false, message: data?.message || err?.message || 'BOM product list failed', error: err?.data ?? null } } })