feat(MED-131): fix medusa vs medipost vs b2b product ids mixed

This commit is contained in:
2025-08-04 16:27:54 +03:00
parent 36816cfcd5
commit 8790b515d5
4 changed files with 88 additions and 71 deletions

View File

@@ -5,15 +5,13 @@ import type { StoreOrder } from '@medusajs/types';
export async function createOrder({
medusaOrder,
orderedAnalysisElements,
}: {
medusaOrder: StoreOrder;
orderedAnalysisElements: { analysisElementId: number }[];
}) {
const supabase = getSupabaseServerClient();
const analysisElementIds = medusaOrder.items
?.filter(({ product }) => product?.handle?.startsWith('analysis-element-'))
.map(({ product }) => Number(product?.handle.replace('analysis-element-', '')))
.filter((id) => !Number.isNaN(id)) as number[];
const { data: { user } } = await supabase.auth.getUser();
if (!user) {
throw new Error('User not found');
@@ -21,7 +19,7 @@ export async function createOrder({
const orderResult = await supabase.schema('medreport')
.from('analysis_orders')
.insert({
analysis_element_ids: analysisElementIds,
analysis_element_ids: orderedAnalysisElements.map(({ analysisElementId }) => analysisElementId),
analysis_ids: [],
status: 'QUEUED',
user_id: user.id,