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