use analysisElementMedusaProductIds from order product selected variant if it exists
This commit is contained in:
@@ -566,7 +566,7 @@ async function syncPrivateMessage({
|
||||
);
|
||||
}
|
||||
|
||||
const { data: allOrderResponseElements} = await supabase
|
||||
const { data: allOrderResponseElements } = await supabase
|
||||
.schema('medreport')
|
||||
.from('analysis_response_elements')
|
||||
.select('*')
|
||||
@@ -714,7 +714,12 @@ export async function getOrderedAnalysisIds({
|
||||
throw new Error(`Got ${orderedPackagesProducts.length} ordered packages products, expected ${orderedPackageIds.length}`);
|
||||
}
|
||||
|
||||
const ids = getAnalysisElementMedusaProductIds(orderedPackagesProducts);
|
||||
const ids = getAnalysisElementMedusaProductIds(
|
||||
orderedPackagesProducts.map(({ id, metadata }) => ({
|
||||
metadata,
|
||||
variant: orderedPackages.find(({ product }) => product?.id === id)?.variant,
|
||||
})),
|
||||
);
|
||||
if (ids.length === 0) {
|
||||
return [];
|
||||
}
|
||||
@@ -755,10 +760,10 @@ export async function createMedipostActionLog({
|
||||
hasError = false,
|
||||
}: {
|
||||
action:
|
||||
| 'send_order_to_medipost'
|
||||
| 'sync_analysis_results_from_medipost'
|
||||
| 'send_fake_analysis_results_to_medipost'
|
||||
| 'send_analysis_results_to_medipost';
|
||||
| 'send_order_to_medipost'
|
||||
| 'sync_analysis_results_from_medipost'
|
||||
| 'send_fake_analysis_results_to_medipost'
|
||||
| 'send_analysis_results_to_medipost';
|
||||
xml: string;
|
||||
hasAnalysisResults?: boolean;
|
||||
medusaOrderId?: string | null;
|
||||
|
||||
@@ -1,17 +1,27 @@
|
||||
export const getAnalysisElementMedusaProductIds = (products: ({
|
||||
import { StoreProduct } from "@medusajs/types";
|
||||
|
||||
type Product = {
|
||||
metadata?: {
|
||||
analysisElementMedusaProductIds?: string;
|
||||
} | null;
|
||||
} | null)[]) => {
|
||||
variant?: {
|
||||
metadata?: {
|
||||
analysisElementMedusaProductIds?: string;
|
||||
} | null;
|
||||
} | null;
|
||||
} | null;
|
||||
|
||||
export const getAnalysisElementMedusaProductIds = (products: Pick<StoreProduct, 'metadata'>[]) => {
|
||||
if (!products) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const mapped = products
|
||||
.flatMap((product) => {
|
||||
const value = product?.metadata?.analysisElementMedusaProductIds?.replaceAll("'", '"');
|
||||
const value = (product as Product)?.metadata?.analysisElementMedusaProductIds?.replaceAll("'", '"');
|
||||
const value_variant = (product as Product)?.variant?.metadata?.analysisElementMedusaProductIds?.replaceAll("'", '"');
|
||||
try {
|
||||
return JSON.parse(value as string);
|
||||
return [...JSON.parse(value as string), ...JSON.parse(value_variant as string)];
|
||||
} catch (e) {
|
||||
console.error("Failed to parse analysisElementMedusaProductIds from analysis package, possibly invalid format", e);
|
||||
return [];
|
||||
|
||||
Reference in New Issue
Block a user