chore: ran biome format
This commit is contained in:
@@ -2,75 +2,75 @@ import { isFixedPrice } from "@/internal/products/prices/priceUtils/usagePriceUt
|
||||
import { isPriceItem } from "@/internal/products/product-items/productItemUtils/getItemType.js";
|
||||
import { nullish } from "@/utils/genUtils.js";
|
||||
import {
|
||||
BillingInterval,
|
||||
FixedPriceConfig,
|
||||
FullProduct,
|
||||
Price,
|
||||
ProductItem,
|
||||
ProductV2,
|
||||
BillingInterval,
|
||||
FixedPriceConfig,
|
||||
FullProduct,
|
||||
Price,
|
||||
ProductItem,
|
||||
ProductV2,
|
||||
} from "@autumn/shared";
|
||||
|
||||
export const addPrefixToProducts = ({
|
||||
products,
|
||||
prefix,
|
||||
products,
|
||||
prefix,
|
||||
}: {
|
||||
products: ProductV2[];
|
||||
prefix: string;
|
||||
products: ProductV2[];
|
||||
prefix: string;
|
||||
}) => {
|
||||
for (const product of products) {
|
||||
product.id = `${prefix}_${product.id}`;
|
||||
product.name = `${prefix} ${product.name}`;
|
||||
product.group = prefix;
|
||||
}
|
||||
for (const product of products) {
|
||||
product.id = `${prefix}_${product.id}`;
|
||||
product.name = `${prefix} ${product.name}`;
|
||||
product.group = prefix;
|
||||
}
|
||||
|
||||
return products;
|
||||
return products;
|
||||
};
|
||||
|
||||
export const replaceItems = ({
|
||||
featureId,
|
||||
interval,
|
||||
intervalCount,
|
||||
newItem,
|
||||
items,
|
||||
featureId,
|
||||
interval,
|
||||
intervalCount,
|
||||
newItem,
|
||||
items,
|
||||
}: {
|
||||
featureId?: string;
|
||||
interval?: BillingInterval;
|
||||
intervalCount?: number;
|
||||
newItem: ProductItem;
|
||||
items: ProductItem[];
|
||||
featureId?: string;
|
||||
interval?: BillingInterval;
|
||||
intervalCount?: number;
|
||||
newItem: ProductItem;
|
||||
items: ProductItem[];
|
||||
}) => {
|
||||
let newItems = structuredClone(items);
|
||||
let newItems = structuredClone(items);
|
||||
|
||||
let index;
|
||||
if (featureId) {
|
||||
index = newItems.findIndex((item) => item.feature_id == featureId);
|
||||
}
|
||||
let index;
|
||||
if (featureId) {
|
||||
index = newItems.findIndex((item) => item.feature_id == featureId);
|
||||
}
|
||||
|
||||
if (interval) {
|
||||
index = newItems.findIndex(
|
||||
(item) =>
|
||||
item.interval == (interval as any) &&
|
||||
(intervalCount ? item.interval_count == intervalCount : true) &&
|
||||
nullish(item.feature_id)
|
||||
);
|
||||
}
|
||||
if (interval) {
|
||||
index = newItems.findIndex(
|
||||
(item) =>
|
||||
item.interval == (interval as any) &&
|
||||
(intervalCount ? item.interval_count == intervalCount : true) &&
|
||||
nullish(item.feature_id),
|
||||
);
|
||||
}
|
||||
|
||||
if (index == -1) {
|
||||
throw new Error("Item not found");
|
||||
}
|
||||
if (index == -1) {
|
||||
throw new Error("Item not found");
|
||||
}
|
||||
|
||||
newItems[index!] = newItem;
|
||||
newItems[index!] = newItem;
|
||||
|
||||
return newItems;
|
||||
return newItems;
|
||||
};
|
||||
|
||||
export const getBasePrice = ({ product }: { product: ProductV2 }) => {
|
||||
return product.items.find((item) => isPriceItem(item))?.price || 0;
|
||||
return product.items.find((item) => isPriceItem(item))?.price || 0;
|
||||
};
|
||||
|
||||
export const v1ProductToBasePrice = ({ prices }: { prices: Price[] }) => {
|
||||
let fixedPrice = prices.find((price) => isFixedPrice({ price }));
|
||||
if (fixedPrice) {
|
||||
return (fixedPrice.config as FixedPriceConfig).amount;
|
||||
} else return 0;
|
||||
let fixedPrice = prices.find((price) => isFixedPrice({ price }));
|
||||
if (fixedPrice) {
|
||||
return (fixedPrice.config as FixedPriceConfig).amount;
|
||||
} else return 0;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user