feat: implement DEV_TICKETS including product categories seeding, SEO metaTitle/metaDescription, scientificTagline, requiresRx notice, and suitableFor normalization
This commit is contained in:
1 parent
913e6acd3d
commit
d6d4158cbe
7 files changed
+116
-24
No files matched your search
@@ -508,6 +508,14 @@ 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 (cat) {
|
||||
resolvedCategorySlug = cat.slug;
|
||||
}
|
||||
}
|
||||
|
||||
const product = await this.prisma.product.create({
|
||||
data: {
|
||||
artNo: data.artNo || `ART-${Date.now()}`,
|
||||
@@ -518,7 +526,7 @@ export class AdminService {
|
||||
shortDescription: data.shortDescription || '',
|
||||
ingredients: data.ingredients || null,
|
||||
categoryId: data.categoryId || '',
|
||||
categorySlug: data.categorySlug || 'general',
|
||||
categorySlug: resolvedCategorySlug || 'general',
|
||||
buyPrice: data.buyPrice !== undefined ? data.buyPrice : 0,
|
||||
marginRetailPercent:
|
||||
marginRetail !== undefined ? marginRetail : undefined,
|
||||
@@ -662,6 +670,14 @@ export class AdminService {
|
||||
: {}),
|
||||
};
|
||||
|
||||
let resolvedCategorySlug = data.categorySlug;
|
||||
if (data.categoryId && !resolvedCategorySlug) {
|
||||
const cat = await this.prisma.category.findUnique({ where: { id: data.categoryId } });
|
||||
if (cat) {
|
||||
resolvedCategorySlug = cat.slug;
|
||||
}
|
||||
}
|
||||
|
||||
const product = await this.prisma.product.update({
|
||||
where: { id },
|
||||
data: {
|
||||
@@ -673,7 +689,7 @@ export class AdminService {
|
||||
shortDescription: data.shortDescription,
|
||||
ingredients: data.ingredients !== undefined ? data.ingredients : undefined,
|
||||
categoryId: data.categoryId,
|
||||
categorySlug: data.categorySlug,
|
||||
categorySlug: resolvedCategorySlug !== undefined ? resolvedCategorySlug : undefined,
|
||||
buyPrice: data.buyPrice !== undefined ? data.buyPrice : undefined,
|
||||
marginRetailPercent:
|
||||
marginRetail !== undefined ? marginRetail : undefined,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { Injectable, NotFoundException, OnModuleInit } from '@nestjs/common';
|
||||
import { Prisma } from '@prisma/client';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
|
||||
@@ -9,9 +9,37 @@ export class CategoryQuery {
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class CategoriesService {
|
||||
export class CategoriesService implements OnModuleInit {
|
||||
constructor(private prisma: PrismaService) {}
|
||||
|
||||
async onModuleInit() {
|
||||
await this.seedDefaultCategories();
|
||||
}
|
||||
|
||||
private async seedDefaultCategories() {
|
||||
try {
|
||||
const defaultCategories = [
|
||||
{ name: 'مفاصل و استخوان', slug: 'joints', description: 'مکملهای ارتوپدی و مفاصل حاوی عصاره صدف سبز و GAG' },
|
||||
{ name: 'سیستم ایمنی و گوارش', slug: 'immune', description: 'تقویت سیستم دفاعی بدن و پروبیوتیکهای تخصصی' },
|
||||
{ name: 'ویتامینها و انرژیبخشها', slug: 'energy', description: 'مولتیویتامینها و تونیکهای انرژیبخش' },
|
||||
{ name: 'مراقبتهای ویژه (پوست، دندان و چشم)', slug: 'special-care', description: 'محلولهای نقره، قطرههای شستشو و ژل دندان' },
|
||||
{ name: 'تقویت عمومی', slug: 'general', description: 'مکملهای پایهای و روزانه سگ و گربه' },
|
||||
{ name: 'تغذیه تخصصی', slug: 'nutrition', description: 'شیر خشک، پودر خون گاو و مکملهای تخصصی پرورش' },
|
||||
{ name: 'مکملهای غذایی و درمانی', slug: 'supplements', description: 'طیف کامل مکملهای گرید دارویی Canina' },
|
||||
];
|
||||
|
||||
for (const cat of defaultCategories) {
|
||||
await this.prisma.category.upsert({
|
||||
where: { slug: cat.slug },
|
||||
update: { name: cat.name, description: cat.description },
|
||||
create: { name: cat.name, slug: cat.slug, description: cat.description },
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn('[CategoriesService] Failed to seed default categories:', err);
|
||||
}
|
||||
}
|
||||
|
||||
async getCategories(query: CategoryQuery = {}) {
|
||||
const page = Number(query.page) || 1;
|
||||
const limit = Number(query.limit) || 10;
|
||||
|
||||
@@ -15,10 +15,10 @@ export class GetProductsDto extends PaginationDto {
|
||||
|
||||
@ApiPropertyOptional({
|
||||
description: 'فیلتر بر اساس نوع حیوان',
|
||||
enum: ['سگ', 'گربه', 'all'],
|
||||
enum: ['سگ', 'گربه', 'سگ و گربه', 'هر دو', 'all'],
|
||||
})
|
||||
@IsOptional()
|
||||
@IsEnum(['سگ', 'گربه', 'all'])
|
||||
@IsEnum(['سگ', 'گربه', 'سگ و گربه', 'هر دو', 'all'])
|
||||
petType?: string;
|
||||
|
||||
@ApiPropertyOptional({ description: 'فیلتر بر اساس یک علامت درمانی خاص' })
|
||||
|
||||
@@ -21,7 +21,7 @@ export class ProductsService {
|
||||
minPrice,
|
||||
maxPrice,
|
||||
page = 1,
|
||||
limit = 10,
|
||||
limit = 50,
|
||||
sortBy = 'createdAt',
|
||||
sortOrder = 'desc',
|
||||
} = filters;
|
||||
@@ -39,7 +39,9 @@ export class ProductsService {
|
||||
}
|
||||
|
||||
if (petType && petType !== 'all') {
|
||||
andConditions.push({ suitableFor: { in: [petType, 'هر دو'] } });
|
||||
andConditions.push({
|
||||
suitableFor: { in: [petType, 'سگ و گربه', 'هر دو'] },
|
||||
});
|
||||
}
|
||||
|
||||
if (symptom) {
|
||||
@@ -230,7 +232,13 @@ export class ProductsService {
|
||||
return {
|
||||
categories,
|
||||
symptoms: symptomsDb.map((s) => s.symptom).filter(Boolean),
|
||||
petTypes: petTypesDb.map((p) => p.suitableFor).filter(Boolean),
|
||||
petTypes: Array.from(
|
||||
new Set(
|
||||
petTypesDb
|
||||
.map((p) => (p.suitableFor === 'هر دو' ? 'سگ و گربه' : p.suitableFor))
|
||||
.filter(Boolean),
|
||||
),
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user