canina/backend/prisma/seed-home.ts
parsa aghaei 7615aa0e51 fix: resolve seed encoding, search param, and wiki data source issues
- Fix seed-products.ts TS error (implicit any) and BOM handling
- Re-run full seed to restore correct Persian encoding in DB
- Fix productService query→search param mismatch
- Fix IngredientWiki hardcoded port 4000→use settingsStore
- Restore seed-products-data.json from git after accidental corruption
2026-07-11 15:40:49 +03:30

108 lines
3.7 KiB
TypeScript

import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
async function main() {
console.log('Seeding Home Page Components...');
// 1. Seed Hero Banners
const banners = [
{
title: 'محصولات تخصصی مراقبت از مفاصل',
subtitle: 'برای سگ‌های مسن و پرتحرک، تضمین سلامت و شادابی با کلاژن فعال',
imageUrl: '/images/slider/slide1.webp', // Assuming we have these in public/images
buttonText: 'مشاهده محصولات مفاصل',
buttonLink: '/shop/joints',
order: 1,
isActive: true,
},
{
title: 'ویتامین‌های ضروری برای رشد توله سگ‌ها',
subtitle: 'رشد کامل استخوان‌ها و تقویت سیستم ایمنی از ماه اول',
imageUrl: '/images/slider/slide2.webp',
buttonText: 'خرید ویتامین توله',
buttonLink: '/shop/puppy',
order: 2,
isActive: true,
}
];
await prisma.heroBanner.deleteMany(); // Reset
for (const b of banners) {
await prisma.heroBanner.create({ data: b });
}
console.log('Seeded Hero Banners.');
// 2. Seed Vet Testimonials
const vets = [
{
vetName: 'دکتر علیرضا رضایی',
clinicName: 'کلینیک دامپزشکی پایتخت',
imageUrl: '/images/vets/vet1.webp',
quote: 'مکمل‌های مفصلی کانینا از نظر سرعت جذب و اثربخشی در سگ‌های نژاد بزرگ بی‌نظیر هستند. ما نتایج فوق‌العاده‌ای روی دیسپلازی هیپ مشاهده کردیم.',
rating: 5,
order: 1,
isActive: true,
},
{
vetName: 'دکتر سارا شمس',
clinicName: 'بیمارستان دامپزشکی تهران',
imageUrl: '/images/vets/vet2.webp',
quote: 'من همیشه برای ریزش مو و مشکلات پوستی گربه‌ها، قرص‌های مخمر و بیوتین کانینا را تجویز می‌کنم. نتایج معمولاً در کمتر از ۳ هفته قابل مشاهده است.',
rating: 5,
order: 2,
isActive: true,
}
];
await prisma.vetTestimonial.deleteMany();
for (const v of vets) {
await prisma.vetTestimonial.create({ data: v });
}
console.log('Seeded Vet Testimonials.');
// 3. Seed Smart Advisor Rules
// We need to fetch an actual product ID to link
const product = await prisma.product.findFirst();
if (product) {
const rules = [
{
condition: 'ریزش مو شدید',
targetPetType: 'سگ',
reason: 'حاوی بیوتین و روی بالا برای توقف ریزش مو و براق شدن پوشش',
recommendedProduct: product.id,
},
{
condition: 'لنگش یا ضعف مفاصل',
targetPetType: 'سگ',
reason: 'غنی از گلوکزامین، کندرویتین و پودر صدف سبز نیوزلندی برای ترمیم غضروف',
recommendedProduct: product.id,
},
{
condition: 'بی‌اشتهایی',
targetPetType: 'گربه',
reason: 'مخمر خالص و ویتامین‌های گروه B برای افزایش اشتها و شادابی',
recommendedProduct: product.id,
}
];
await prisma.smartAdvisorRule.deleteMany();
for (const r of rules) {
await prisma.smartAdvisorRule.create({ data: r });
}
console.log('Seeded Smart Advisor Rules.');
} else {
console.log('No products found in DB! Skipping Smart Advisor Rules seeding.');
}
}
main()
.catch(e => {
console.error(e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});