This commit is contained in:
shafi54 2026-08-12 16:26:49 +05:30
parent df84e4a6c9
commit 25f3fb099c
5 changed files with 57 additions and 12 deletions

View file

@ -11,3 +11,5 @@
- Prefers using icons from Hicons (rather than custom/hand-authored SVGs or other icon libraries). Confidence: 0.9 - 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 - 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 - 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 <Text> component" warnings. Confidence: 0.8

View file

@ -25,12 +25,12 @@ interface PersistedCache<T> {
} }
const CACHE_STORAGE_KEYS = { const CACHE_STORAGE_KEYS = {
products: 'cache:products', products: 'cache_products',
stores: 'cache:stores', stores: 'cache_stores',
slots: 'cache:slots', slots: 'cache_slots',
banners: 'cache:banners', banners: 'cache_banners',
availability: 'cache:availability', availability: 'cache_availability',
storeProducts: (storeId: number) => `cache:store:${storeId}`, storeProducts: (storeId: number) => `cache_store_${storeId}`,
} as const } as const
async function readPersistedCache<T>(key: string): Promise<PersistedCache<T> | null> { async function readPersistedCache<T>(key: string): Promise<PersistedCache<T> | null> {

View file

@ -606,7 +606,11 @@ export async function rebalanceSlots(slotIds: number[]): Promise<AdminRebalanceS
with: { with: {
orderItems: { orderItems: {
with: { with: {
sku: true, sku: {
with: {
marketStats: true,
},
},
}, },
}, },
couponUsages: { couponUsages: {
@ -619,14 +623,15 @@ export async function rebalanceSlots(slotIds: number[]): Promise<AdminRebalanceS
const processedOrdersData = ordersList.map((order: any) => { const processedOrdersData = ordersList.map((order: any) => {
let newTotal = order.orderItems.reduce((acc: number, item: any) => { 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) const amount = latestPrice * Number(item.quantity)
return acc + amount return acc + amount
}, 0) }, 0)
order.orderItems.forEach((item: any) => { order.orderItems.forEach((item: any) => {
item.price = item.sku.price const latestPrice = item.sku?.marketStats?.ourPrice
item.discountedPrice = item.sku.price item.price = latestPrice
item.discountedPrice = latestPrice
}) })
const coupon = order.couponUsages[0]?.coupon const coupon = order.couponUsages[0]?.coupon

View file

@ -267,9 +267,28 @@ export async function getAddressByIdAndUser(
} }
export async function getProductById(skuId: number) { export async function getProductById(skuId: number) {
return db.query.productSkus.findFirst({ const sku = await db.query.productSkus.findFirst({
where: eq(productSkus.id, skuId), 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<boolean> { export async function checkUserSuspended(userId: number): Promise<boolean> {

View file

@ -141,9 +141,28 @@ export async function getProductReviews(productId: number, limit: number, offset
} }
export async function getProductById(skuId: number) { export async function getProductById(skuId: number) {
return db.query.productSkus.findFirst({ const sku = await db.query.productSkus.findFirst({
where: eq(productSkus.id, skuId), 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( export async function createProductReview(