feat: complete scheduled publishing, security remediation and DEV_TICKETS implementation
This commit is contained in:
1 parent
d6d4158cbe
commit
efb3c473c4
35 files changed
+685
-185
No files matched your search
@@ -509,8 +509,13 @@ export class AdminService {
|
||||
};
|
||||
|
||||
let resolvedCategorySlug = data.categorySlug;
|
||||
if (data.categoryId && (!resolvedCategorySlug || resolvedCategorySlug === 'general')) {
|
||||
const cat = await this.prisma.category.findUnique({ where: { id: data.categoryId } });
|
||||
if (
|
||||
data.categoryId &&
|
||||
(!resolvedCategorySlug || resolvedCategorySlug === 'general')
|
||||
) {
|
||||
const cat = await this.prisma.category.findUnique({
|
||||
where: { id: data.categoryId },
|
||||
});
|
||||
if (cat) {
|
||||
resolvedCategorySlug = cat.slug;
|
||||
}
|
||||
@@ -597,12 +602,19 @@ 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)));
|
||||
const uniqueIngs = Array.from(
|
||||
new Set(
|
||||
data.ingredientList.map((i: string) => i.trim()).filter(Boolean),
|
||||
),
|
||||
);
|
||||
if (uniqueIngs.length > 0) {
|
||||
const resolvedIngs = await this.resolveIngredientCards(uniqueIngs);
|
||||
await this.prisma.productIngredient.createMany({
|
||||
data: uniqueIngs.map((ingredient: string) => ({
|
||||
data: resolvedIngs.map((item) => ({
|
||||
productId: product.id,
|
||||
ingredient,
|
||||
ingredient: item.ingredient,
|
||||
ingredientCardId: item.ingredientCardId,
|
||||
ingredientCardSlug: item.ingredientCardSlug,
|
||||
})),
|
||||
});
|
||||
}
|
||||
@@ -672,7 +684,9 @@ export class AdminService {
|
||||
|
||||
let resolvedCategorySlug = data.categorySlug;
|
||||
if (data.categoryId && !resolvedCategorySlug) {
|
||||
const cat = await this.prisma.category.findUnique({ where: { id: data.categoryId } });
|
||||
const cat = await this.prisma.category.findUnique({
|
||||
where: { id: data.categoryId },
|
||||
});
|
||||
if (cat) {
|
||||
resolvedCategorySlug = cat.slug;
|
||||
}
|
||||
@@ -687,9 +701,11 @@ export class AdminService {
|
||||
scientificTagline: data.scientificTagline,
|
||||
description: data.description,
|
||||
shortDescription: data.shortDescription,
|
||||
ingredients: data.ingredients !== undefined ? data.ingredients : undefined,
|
||||
ingredients:
|
||||
data.ingredients !== undefined ? data.ingredients : undefined,
|
||||
categoryId: data.categoryId,
|
||||
categorySlug: resolvedCategorySlug !== undefined ? resolvedCategorySlug : undefined,
|
||||
categorySlug:
|
||||
resolvedCategorySlug !== undefined ? resolvedCategorySlug : undefined,
|
||||
buyPrice: data.buyPrice !== undefined ? data.buyPrice : undefined,
|
||||
marginRetailPercent:
|
||||
marginRetail !== undefined ? marginRetail : undefined,
|
||||
@@ -772,14 +788,26 @@ export class AdminService {
|
||||
}
|
||||
}
|
||||
|
||||
if (data.ingredientList !== undefined && Array.isArray(data.ingredientList)) {
|
||||
await this.prisma.productIngredient.deleteMany({ where: { productId: id } });
|
||||
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)));
|
||||
const uniqueIngs = Array.from(
|
||||
new Set(
|
||||
data.ingredientList.map((i: string) => i.trim()).filter(Boolean),
|
||||
),
|
||||
);
|
||||
const resolvedIngs = await this.resolveIngredientCards(uniqueIngs);
|
||||
await this.prisma.productIngredient.createMany({
|
||||
data: uniqueIngs.map((ingredient: string) => ({
|
||||
data: resolvedIngs.map((item) => ({
|
||||
productId: id,
|
||||
ingredient,
|
||||
ingredient: item.ingredient,
|
||||
ingredientCardId: item.ingredientCardId,
|
||||
ingredientCardSlug: item.ingredientCardSlug,
|
||||
})),
|
||||
});
|
||||
}
|
||||
@@ -1781,4 +1809,47 @@ export class AdminService {
|
||||
totalMatched: products.length,
|
||||
};
|
||||
}
|
||||
|
||||
async resolveIngredientCards(ingredients: string[]): Promise<
|
||||
Array<{
|
||||
ingredient: string;
|
||||
ingredientCardId: string | null;
|
||||
ingredientCardSlug: string | null;
|
||||
}>
|
||||
> {
|
||||
if (!ingredients || ingredients.length === 0) return [];
|
||||
const allCards = await this.prisma.ingredient.findMany({
|
||||
select: { id: true, slug: true, nameFa: true, nameEn: true },
|
||||
});
|
||||
|
||||
const normalize = (str: string) =>
|
||||
str.toLowerCase().replace(/[()]/g, '').replace(/\s+/g, ' ').trim();
|
||||
|
||||
return ingredients.map((rawIng) => {
|
||||
const clean = rawIng.trim();
|
||||
const norm = normalize(clean);
|
||||
|
||||
const matchedCard = allCards.find((card) => {
|
||||
const cardFaNorm = normalize(card.nameFa);
|
||||
const cardEnNorm = normalize(card.nameEn);
|
||||
const cardSlugNorm = normalize(card.slug.replace(/-/g, ' '));
|
||||
|
||||
return (
|
||||
norm === cardFaNorm ||
|
||||
norm === cardEnNorm ||
|
||||
norm === cardSlugNorm ||
|
||||
norm.includes(cardFaNorm) ||
|
||||
cardFaNorm.includes(norm) ||
|
||||
norm.includes(cardEnNorm) ||
|
||||
cardEnNorm.includes(norm)
|
||||
);
|
||||
});
|
||||
|
||||
return {
|
||||
ingredient: clean,
|
||||
ingredientCardId: matchedCard ? matchedCard.id : null,
|
||||
ingredientCardSlug: matchedCard ? matchedCard.slug : null,
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user