more
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
// Simulated data functions - Replace these with API calls when ready
|
||||
// Example: export async function getPricingHistory(partId: string) { ... }
|
||||
|
||||
export interface PriceHistoryPoint {
|
||||
date: string; // ISO date string
|
||||
price: number;
|
||||
}
|
||||
|
||||
export interface RetailerOffer {
|
||||
id: string;
|
||||
retailerName: string;
|
||||
price: number;
|
||||
originalPrice?: number;
|
||||
inStock: boolean;
|
||||
affiliateUrl: string;
|
||||
lastUpdated: string; // ISO date string
|
||||
}
|
||||
|
||||
/**
|
||||
* Get pricing history for a part
|
||||
* TODO: Replace with API call: GET /api/parts/{partId}/pricing-history
|
||||
*/
|
||||
export function getPricingHistory(
|
||||
partId: string,
|
||||
basePrice: number,
|
||||
): PriceHistoryPoint[] {
|
||||
// Generate 30 days of price history with some variation
|
||||
const days = 30;
|
||||
const history: PriceHistoryPoint[] = [];
|
||||
const today = new Date();
|
||||
|
||||
for (let i = days - 1; i >= 0; i--) {
|
||||
const date = new Date(today);
|
||||
date.setDate(date.getDate() - i);
|
||||
|
||||
// Simulate price fluctuations (±15% variation)
|
||||
const variation = (Math.random() - 0.5) * 0.3; // -15% to +15%
|
||||
const price = basePrice * (1 + variation);
|
||||
|
||||
history.push({
|
||||
date: date.toISOString().split("T")[0],
|
||||
price: Math.round(price * 100) / 100,
|
||||
});
|
||||
}
|
||||
|
||||
return history;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get retailer offers for a part
|
||||
* TODO: Replace with API call: GET /api/parts/{partId}/retailers
|
||||
*/
|
||||
export function getRetailerOffers(
|
||||
partId: string,
|
||||
basePrice: number,
|
||||
baseAffiliateUrl: string,
|
||||
): RetailerOffer[] {
|
||||
const retailers = [
|
||||
"Primary Arms",
|
||||
"Brownells",
|
||||
"Optics Planet",
|
||||
"MidwayUSA",
|
||||
"Palmetto State Armory",
|
||||
];
|
||||
|
||||
return retailers.map((retailer, index) => {
|
||||
// Simulate price variations between retailers
|
||||
const priceVariation = (Math.random() - 0.4) * 0.2; // -8% to +12%
|
||||
const price = basePrice * (1 + priceVariation);
|
||||
const hasSale = Math.random() > 0.6; // 40% chance of sale
|
||||
const originalPrice = hasSale ? price * 1.15 : undefined;
|
||||
const inStock = Math.random() > 0.2; // 80% chance in stock
|
||||
|
||||
return {
|
||||
id: `retailer-${index}`,
|
||||
retailerName: retailer,
|
||||
price: Math.round(price * 100) / 100,
|
||||
originalPrice: originalPrice
|
||||
? Math.round(originalPrice * 100) / 100
|
||||
: undefined,
|
||||
inStock,
|
||||
affiliateUrl: baseAffiliateUrl.replace("example.com", `${retailer.toLowerCase().replace(/\s+/g, "")}.com`),
|
||||
lastUpdated: new Date().toISOString(),
|
||||
};
|
||||
}).sort((a, b) => a.price - b.price); // Sort by price ascending
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user