diff --git a/.commandcode/taste/taste/taste.md b/.commandcode/taste/taste/taste.md index 39d3aab..8a46220 100644 --- a/.commandcode/taste/taste/taste.md +++ b/.commandcode/taste/taste/taste.md @@ -11,3 +11,5 @@ - Prefers using icons from Hicons (rather than custom/hand-authored SVGs or other icon libraries). Confidence: 0.9 - When a feature or page is repurposed, wants file names, route names, and code references renamed to match the new purpose (not just UI content/icons). Confidence: 0.8 - Wants analysis findings and plans persisted in a markdown file before any implementation begins, with explicit confirmation that implementation is paused until instructed. Confidence: 0.8 +- When changing cache or storage keys, wants both the read and write paths verified to use the same single source of truth (e.g., a shared `CACHE_STORAGE_KEYS` constant). Confidence: 0.8 +- In React Native with react-native-paper's `Text` component (wrapped as `MyText`), prefers avoiding mixed string/expression children; use template literals to produce a single string child to prevent "Text strings must be rendered within a component" warnings. Confidence: 0.8 diff --git a/apps/user-ui/src/hooks/prominent-api-hooks.ts b/apps/user-ui/src/hooks/prominent-api-hooks.ts index c0c9a38..f1f5cf7 100644 --- a/apps/user-ui/src/hooks/prominent-api-hooks.ts +++ b/apps/user-ui/src/hooks/prominent-api-hooks.ts @@ -25,12 +25,12 @@ interface PersistedCache { } const CACHE_STORAGE_KEYS = { - products: 'cache:products', - stores: 'cache:stores', - slots: 'cache:slots', - banners: 'cache:banners', - availability: 'cache:availability', - storeProducts: (storeId: number) => `cache:store:${storeId}`, + products: 'cache_products', + stores: 'cache_stores', + slots: 'cache_slots', + banners: 'cache_banners', + availability: 'cache_availability', + storeProducts: (storeId: number) => `cache_store_${storeId}`, } as const async function readPersistedCache(key: string): Promise | null> { diff --git a/packages/db_helper_sqlite/src/admin-apis/order.ts b/packages/db_helper_sqlite/src/admin-apis/order.ts index 3165739..66b5d41 100644 --- a/packages/db_helper_sqlite/src/admin-apis/order.ts +++ b/packages/db_helper_sqlite/src/admin-apis/order.ts @@ -606,7 +606,11 @@ export async function rebalanceSlots(slotIds: number[]): Promise { let newTotal = order.orderItems.reduce((acc: number, item: any) => { - const latestPrice = +item.sku.price + const latestPrice = +(item.sku?.marketStats?.ourPrice ?? 0) const amount = latestPrice * Number(item.quantity) return acc + amount }, 0) order.orderItems.forEach((item: any) => { - item.price = item.sku.price - item.discountedPrice = item.sku.price + const latestPrice = item.sku?.marketStats?.ourPrice + item.price = latestPrice + item.discountedPrice = latestPrice }) const coupon = order.couponUsages[0]?.coupon diff --git a/packages/db_helper_sqlite/src/user-apis/order.ts b/packages/db_helper_sqlite/src/user-apis/order.ts index 8456968..aa82550 100644 --- a/packages/db_helper_sqlite/src/user-apis/order.ts +++ b/packages/db_helper_sqlite/src/user-apis/order.ts @@ -267,9 +267,28 @@ export async function getAddressByIdAndUser( } export async function getProductById(skuId: number) { - return db.query.productSkus.findFirst({ + const sku = await db.query.productSkus.findFirst({ where: eq(productSkus.id, skuId), + with: { + marketStats: true, + product: true, + }, }) + + if (!sku) { + return null + } + + const marketStats = sku.marketStats + + return { + ...sku, + price: marketStats?.ourPrice ? String(marketStats.ourPrice) : '0', + marketPrice: marketStats?.marketPrice ? String(marketStats.marketPrice) : null, + flashPrice: marketStats?.flashPrice ? String(marketStats.flashPrice) : null, + isFlashAvailable: marketStats?.isFlashAvailable ?? false, + isOutOfStock: marketStats?.isOutOfStock ?? false, + } } export async function checkUserSuspended(userId: number): Promise { diff --git a/packages/db_helper_sqlite/src/user-apis/product.ts b/packages/db_helper_sqlite/src/user-apis/product.ts index 36ee830..d49ac3c 100644 --- a/packages/db_helper_sqlite/src/user-apis/product.ts +++ b/packages/db_helper_sqlite/src/user-apis/product.ts @@ -141,9 +141,28 @@ export async function getProductReviews(productId: number, limit: number, offset } export async function getProductById(skuId: number) { - return db.query.productSkus.findFirst({ + const sku = await db.query.productSkus.findFirst({ where: eq(productSkus.id, skuId), + with: { + marketStats: true, + product: true, + }, }) + + if (!sku) { + return null + } + + const marketStats = sku.marketStats + + return { + ...sku, + price: marketStats?.ourPrice ? String(marketStats.ourPrice) : '0', + marketPrice: marketStats?.marketPrice ? String(marketStats.marketPrice) : null, + flashPrice: marketStats?.flashPrice ? String(marketStats.flashPrice) : null, + isFlashAvailable: marketStats?.isFlashAvailable ?? false, + isOutOfStock: marketStats?.isOutOfStock ?? false, + } } export async function createProductReview(