x
This commit is contained in:
1 parent
46968782b6
commit
08045eabff
18 files changed
+943
-104
No files matched your search
@@ -558,25 +558,31 @@ async function resolveProductsForSection(payload, lang) {
|
||||
},
|
||||
};
|
||||
if (payload.type === "featured") {
|
||||
const whereClause = { 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 },
|
||||
where: whereClause,
|
||||
include: productInclude,
|
||||
take: limit,
|
||||
orderBy: { createdAt: "desc" },
|
||||
});
|
||||
}
|
||||
else if ((payload.type === "scent" || payload.type === "brand") &&
|
||||
(payload.scentId || payload.brandId)) {
|
||||
products = await prisma.product.findMany({
|
||||
where: { brandId: Number(payload.brandId || payload.scentId) },
|
||||
where: { brandId: Number(payload.brandId || payload.scentId), isDeleted: false },
|
||||
include: productInclude,
|
||||
take: limit,
|
||||
orderBy: { createdAt: "desc" },
|
||||
});
|
||||
}
|
||||
else if (payload.type === "custom" && Array.isArray(payload.productIds)) {
|
||||
const ids = payload.productIds.map(Number);
|
||||
const ids = payload.productIds.map(Number).filter(id => !isNaN(id) && id > 0);
|
||||
if (ids.length > 0) {
|
||||
products = await prisma.product.findMany({
|
||||
where: { id: { in: ids } },
|
||||
where: { id: { in: ids }, isDeleted: false },
|
||||
include: productInclude,
|
||||
});
|
||||
products.sort((a, b) => ids.indexOf(a.id) - ids.indexOf(b.id));
|
||||
@@ -584,8 +590,10 @@ async function resolveProductsForSection(payload, lang) {
|
||||
}
|
||||
else {
|
||||
products = await prisma.product.findMany({
|
||||
where: { isDeleted: false },
|
||||
include: productInclude,
|
||||
take: limit,
|
||||
orderBy: { createdAt: "desc" },
|
||||
});
|
||||
}
|
||||
return products.map((p) => {
|
||||
@@ -619,8 +627,7 @@ export async function hydrateSectionPayload(section, lang) {
|
||||
return section;
|
||||
const populatedPayload = { ...payload };
|
||||
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