Hey there! Currently, I am in the process of setting up a store using nextjs pages router and supabase. However, I have encountered a peculiar bug with my product filtering system when dealing with numbers exceeding 4 digits (e.g., 11000).
The structure of my API route is as follows:
async function handler(req: NextApiRequest, res: NextApiResponse) {
if (req.method !== "POST") {
// Handle unsupported request methods
res.status(405).json({ error: "Method Not Allowed" });
return;
}
const {
minPrice,
maxPrice,
oferta,
garment,
category,
search,
}: {
minPrice: number | undefined | null;
maxPrice: number | undefined | null;
oferta: string | undefined | null;
garment: string | undefined | null;
category: string | undefined | null;
search: string | undefined | null;
} = req.body;
let query = supabase
.from("products")
.select(
"seller!inner( status ), id, published, published_version, created_at"
)
.eq("suspended", "false")
.eq("published", "true")
.eq("seller.status", "live");
if (oferta === "si") {
query = query.neq("published_version->>offer_price", "");
}
if (oferta === "no") {
query = query.eq("published_version->>offer_price", "");
}
if (category) {
query = query.eq("published_version->category->>main", category);
}
if (garment) {
query = query.eq("published_version->category->>garment", garment);
}
if (minPrice) {
console.log("minPrice", minPrice);
query = query.gte("published_version->>price", minPrice);
}
// Fetch products based on filters and order them
query = query.order("created_at", { ascending: false }).limit(50);
const { data, error } = await query;
if (error || !data) {
console.log("ERROR", error);
res.status(500).json({ error: error.message });
}
const products = data?.map((product) => {
return {
...product,
data: {
...product.published_version,
},
};
});
res.status(200).json({ data: products });
}
Despite everything working smoothly, I'm encountering an issue with the minPrice and maxPrice filter. It seems that filtering with a number greater than 9999 isn't functioning properly.
If anyone can offer assistance or guidance on this matter, it would be greatly appreciated. Thank you!