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

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

View file

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

View file

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