x
This commit is contained in:
1 parent
46968782b6
commit
08045eabff
18 files changed
+943
-104
No files matched your search
@@ -1473,10 +1473,15 @@ async function resolveProductsForSection(payload: any, lang: string) {
|
||||
};
|
||||
|
||||
if (payload.type === "featured") {
|
||||
const whereClause: any = { isDeleted: false };
|
||||
if (payload.categoryId && Number(payload.categoryId) > 0) {
|
||||
whereClause.categoryId = Number(payload.categoryId);
|
||||
}
|
||||
products = await prisma.product.findMany({
|
||||
where: { categoryId: Number(payload.categoryId) || 1, isDeleted: false },
|
||||
where: whereClause,
|
||||
include: productInclude,
|
||||
take: limit,
|
||||
orderBy: { createdAt: "desc" as const },
|
||||
});
|
||||
} else if (
|
||||
(payload.type === "scent" || payload.type === "brand") &&
|
||||
@@ -1486,9 +1491,10 @@ async function resolveProductsForSection(payload: any, lang: string) {
|
||||
where: { brandId: Number(payload.brandId || payload.scentId), isDeleted: false },
|
||||
include: productInclude,
|
||||
take: limit,
|
||||
orderBy: { createdAt: "desc" as const },
|
||||
});
|
||||
} else if (payload.type === "custom" && Array.isArray(payload.productIds)) {
|
||||
const ids = payload.productIds.map(Number);
|
||||
const ids = payload.productIds.map(Number).filter((id: number) => !isNaN(id) && id > 0);
|
||||
if (ids.length > 0) {
|
||||
products = await prisma.product.findMany({
|
||||
where: { id: { in: ids }, isDeleted: false },
|
||||
@@ -1501,6 +1507,7 @@ async function resolveProductsForSection(payload: any, lang: string) {
|
||||
where: { isDeleted: false },
|
||||
include: productInclude,
|
||||
take: limit,
|
||||
orderBy: { createdAt: "desc" as const },
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1538,8 +1545,7 @@ export async function hydrateSectionPayload(section: any, lang: string) {
|
||||
|
||||
if (
|
||||
section.type === "PRODUCTS" ||
|
||||
(section.type === "PRODUCT_CAROUSEL" &&
|
||||
!Array.isArray(populatedPayload.products))
|
||||
section.type === "PRODUCT_CAROUSEL"
|
||||
) {
|
||||
populatedPayload.products = await resolveProductsForSection(payload, lang);
|
||||
} else if (section.type === "CATEGORIES") {
|
||||
|
||||
Reference in new issue
Block a user