prettier fix
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import type { AdminProductVariant, StoreProduct } from "@medusajs/types";
|
||||
import type { AdminProductVariant, StoreProduct } from '@medusajs/types';
|
||||
|
||||
type Product = {
|
||||
metadata?: {
|
||||
@@ -11,15 +11,26 @@ type Product = {
|
||||
} | null;
|
||||
} | null;
|
||||
|
||||
export const getAnalysisElementMedusaProductIds = (products: (Pick<StoreProduct, 'metadata'> & { variant?: Pick<AdminProductVariant, 'metadata'> })[]) => {
|
||||
export const getAnalysisElementMedusaProductIds = (
|
||||
products: (Pick<StoreProduct, 'metadata'> & {
|
||||
variant?: Pick<AdminProductVariant, 'metadata'>;
|
||||
})[],
|
||||
) => {
|
||||
if (!products) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const mapped = products
|
||||
.flatMap((product) => {
|
||||
const value = (product as Product)?.metadata?.analysisElementMedusaProductIds?.replaceAll("'", '"');
|
||||
const value_variant = (product as Product)?.variant?.metadata?.analysisElementMedusaProductIds?.replaceAll("'", '"');
|
||||
const value = (
|
||||
product as Product
|
||||
)?.metadata?.analysisElementMedusaProductIds?.replaceAll("'", '"');
|
||||
const value_variant = (
|
||||
product as Product
|
||||
)?.variant?.metadata?.analysisElementMedusaProductIds?.replaceAll(
|
||||
"'",
|
||||
'"',
|
||||
);
|
||||
|
||||
const result: string[] = [];
|
||||
try {
|
||||
@@ -27,14 +38,20 @@ export const getAnalysisElementMedusaProductIds = (products: (Pick<StoreProduct,
|
||||
result.push(...JSON.parse(value as string));
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Failed to parse analysisElementMedusaProductIds from analysis package variant, possibly invalid format", e);
|
||||
console.error(
|
||||
'Failed to parse analysisElementMedusaProductIds from analysis package variant, possibly invalid format',
|
||||
e,
|
||||
);
|
||||
}
|
||||
try {
|
||||
if (value_variant) {
|
||||
result.push(...JSON.parse(value_variant as string));
|
||||
}
|
||||
} 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 result;
|
||||
@@ -42,4 +59,4 @@ export const getAnalysisElementMedusaProductIds = (products: (Pick<StoreProduct,
|
||||
.filter(Boolean) as string[];
|
||||
|
||||
return [...new Set(mapped)];
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user