This commit is contained in:
shafi54 2026-01-26 23:38:08 +05:30
parent 6b8680570b
commit 419fa83b8c
4 changed files with 22 additions and 27 deletions

File diff suppressed because one or more lines are too long

View file

@ -30,6 +30,9 @@ export const bannerRouter = router({
}) })
); );
console.log({bannersWithSignedUrls})
return { return {
banners: bannersWithSignedUrls, banners: bannersWithSignedUrls,
}; };

View file

@ -10,24 +10,26 @@ import {
import { eq, and, gt, asc } from "drizzle-orm"; import { eq, and, gt, asc } from "drizzle-orm";
import { generateSignedUrlsFromS3Urls } from "../../lib/s3-client"; import { generateSignedUrlsFromS3Urls } from "../../lib/s3-client";
import { getAllSlots as getAllSlotsFromCache, getSlotById as getSlotByIdFromCache } from "../../stores/slot-store"; import { getAllSlots as getAllSlotsFromCache, getSlotById as getSlotByIdFromCache } from "../../stores/slot-store";
import dayjs from 'dayjs';
// Helper method to get formatted slot data by ID // Helper method to get formatted slot data by ID
async function getSlotData(slotId: number) { async function getSlotData(slotId: number) {
// Get slot from cache
const slot = await getSlotByIdFromCache(slotId); const slot = await getSlotByIdFromCache(slotId);
if (!slot) { if (!slot) {
return null; // Slot not found return null;
} }
// Filter out out-of-stock products and format to match home page display structure const currentTime = new Date();
const products = slot.products.filter((product) => !product.isOutOfStock); if (dayjs(slot.freezeTime).isBefore(currentTime)) {
return null;
}
return { return {
deliveryTime: slot.deliveryTime, deliveryTime: slot.deliveryTime,
freezeTime: slot.freezeTime, freezeTime: slot.freezeTime,
slotId: slot.id, slotId: slot.id,
products, products: slot.products.filter((product) => !product.isOutOfStock),
}; };
} }
@ -43,12 +45,15 @@ export const slotsRouter = router({
}), }),
getSlotsWithProducts: publicProcedure.query(async () => { getSlotsWithProducts: publicProcedure.query(async () => {
// Get all slots from cache const allSlots = await getAllSlotsFromCache();
const slotsWithProducts = await getAllSlotsFromCache(); const currentTime = new Date();
const validSlots = allSlots.filter((slot) =>
dayjs(slot.freezeTime).isAfter(currentTime)
);
return { return {
slots: slotsWithProducts, slots: validSlots,
count: slotsWithProducts.length, count: validSlots.length,
}; };
}), }),
@ -75,21 +80,6 @@ export const slotsRouter = router({
getSlotById: publicProcedure getSlotById: publicProcedure
.input(z.object({ slotId: z.number() })) .input(z.object({ slotId: z.number() }))
.query(async ({ input }) => { .query(async ({ input }) => {
// Get slot from cache return await getSlotData(input.slotId);
const slot = await getSlotByIdFromCache(input.slotId);
if (!slot) {
return null; // Slot not found
}
// Filter out out-of-stock products and format to match home page display structure
const products = slot.products.filter((product) => !product.isOutOfStock);
return {
deliveryTime: slot.deliveryTime,
freezeTime: slot.freezeTime,
slotId: slot.id,
products,
};
}), }),
}); });

View file

@ -26,6 +26,8 @@ export default function BannerCarousel() {
// Fetch banners data // Fetch banners data
const { data: bannersData, isLoading, error } = trpc.user.banner.getBanners.useQuery(); const { data: bannersData, isLoading, error } = trpc.user.banner.getBanners.useQuery();
console.log({bannersData})
const banners = bannersData?.banners || []; const banners = bannersData?.banners || [];
// Auto-play functionality // Auto-play functionality