fix(admin-panel): fix blog bugs and add ingredients editor, draft autosave, and category seeding
This commit is contained in:
1 parent
ebc61d5be2
commit
913e6acd3d
11 files changed
+375
-20
No files matched your search
@@ -445,7 +445,7 @@ export class AdminService {
|
||||
skip,
|
||||
take: limit,
|
||||
orderBy: { [sortField]: sortDirection },
|
||||
include: { category: true, symptoms: true },
|
||||
include: { category: true, symptoms: true, ingredientList: true },
|
||||
}),
|
||||
this.prisma.product.count({ where }),
|
||||
]);
|
||||
@@ -516,6 +516,7 @@ export class AdminService {
|
||||
scientificTagline: data.scientificTagline || '',
|
||||
description: data.description || '',
|
||||
shortDescription: data.shortDescription || '',
|
||||
ingredients: data.ingredients || null,
|
||||
categoryId: data.categoryId || '',
|
||||
categorySlug: data.categorySlug || 'general',
|
||||
buyPrice: data.buyPrice !== undefined ? data.buyPrice : 0,
|
||||
@@ -587,6 +588,18 @@ export class AdminService {
|
||||
});
|
||||
}
|
||||
|
||||
if (data.ingredientList && Array.isArray(data.ingredientList)) {
|
||||
const uniqueIngs = Array.from(new Set(data.ingredientList.map((i: string) => i.trim()).filter(Boolean)));
|
||||
if (uniqueIngs.length > 0) {
|
||||
await this.prisma.productIngredient.createMany({
|
||||
data: uniqueIngs.map((ingredient: string) => ({
|
||||
productId: product.id,
|
||||
ingredient,
|
||||
})),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
await this.revalidationService.revalidateProduct(
|
||||
product.slug,
|
||||
product.artNo,
|
||||
@@ -658,6 +671,7 @@ export class AdminService {
|
||||
scientificTagline: data.scientificTagline,
|
||||
description: data.description,
|
||||
shortDescription: data.shortDescription,
|
||||
ingredients: data.ingredients !== undefined ? data.ingredients : undefined,
|
||||
categoryId: data.categoryId,
|
||||
categorySlug: data.categorySlug,
|
||||
buyPrice: data.buyPrice !== undefined ? data.buyPrice : undefined,
|
||||
@@ -742,11 +756,27 @@ export class AdminService {
|
||||
}
|
||||
}
|
||||
|
||||
if (data.ingredientList !== undefined && Array.isArray(data.ingredientList)) {
|
||||
await this.prisma.productIngredient.deleteMany({ where: { productId: id } });
|
||||
if (data.ingredientList.length > 0) {
|
||||
const uniqueIngs = Array.from(new Set(data.ingredientList.map((i: string) => i.trim()).filter(Boolean)));
|
||||
await this.prisma.productIngredient.createMany({
|
||||
data: uniqueIngs.map((ingredient: string) => ({
|
||||
productId: id,
|
||||
ingredient,
|
||||
})),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
await this.revalidationService.revalidateProduct(
|
||||
product.slug,
|
||||
product.artNo,
|
||||
);
|
||||
return product;
|
||||
return this.prisma.product.findUnique({
|
||||
where: { id },
|
||||
include: { category: true, symptoms: true, ingredientList: true },
|
||||
});
|
||||
}
|
||||
|
||||
async deleteProduct(id: string) {
|
||||
|
||||
Reference in new issue
Block a user