feat: complete app democking, fix types, add blogs api
This commit is contained in:
1 parent
6027e635db
commit
945c007a79
25 files changed
+557
-56
No files matched your search
@@ -140,6 +140,7 @@ model Product {
|
||||
symptoms ProductSymptom[]
|
||||
reminders Reminder[]
|
||||
orderItems OrderItem[]
|
||||
advisorRules SmartAdvisorRule[]
|
||||
|
||||
@@index([categorySlug])
|
||||
@@index([suitableFor])
|
||||
@@ -321,3 +322,43 @@ model ScientificTerm {
|
||||
@@map("scientific_terms")
|
||||
}
|
||||
|
||||
model HeroBanner {
|
||||
id String @id @default(uuid()) @db.Uuid
|
||||
title String @db.VarChar(200)
|
||||
subtitle String? @db.Text
|
||||
imageUrl String @map("image_url") @db.Text
|
||||
buttonText String? @map("button_text") @db.VarChar(100)
|
||||
buttonLink String? @map("button_link") @db.Text
|
||||
isActive Boolean @default(true) @map("is_active")
|
||||
order Int @default(0)
|
||||
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz()
|
||||
|
||||
@@map("hero_banners")
|
||||
}
|
||||
|
||||
model VetTestimonial {
|
||||
id String @id @default(uuid()) @db.Uuid
|
||||
vetName String @map("vet_name") @db.VarChar(150)
|
||||
clinicName String? @map("clinic_name") @db.VarChar(150)
|
||||
imageUrl String? @map("image_url") @db.Text
|
||||
quote String @db.Text
|
||||
rating Int @default(5)
|
||||
isActive Boolean @default(true) @map("is_active")
|
||||
order Int @default(0)
|
||||
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz()
|
||||
|
||||
@@map("vet_testimonials")
|
||||
}
|
||||
|
||||
model SmartAdvisorRule {
|
||||
id String @id @default(uuid()) @db.Uuid
|
||||
condition String @db.VarChar(200)
|
||||
targetPetType String? @map("target_pet_type") @db.VarChar(50)
|
||||
recommendedProduct String @map("recommended_product_id") @db.Uuid
|
||||
reason String @db.Text
|
||||
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz()
|
||||
|
||||
product Product @relation(fields: [recommendedProduct], references: [id], onDelete: Cascade)
|
||||
|
||||
@@map("smart_advisor_rules")
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
async function main() {
|
||||
console.log('Start seeding blogs...');
|
||||
|
||||
// Create a default admin author if not exists
|
||||
let admin = await prisma.user.findFirst({ where: { role: 'admin' } });
|
||||
if (!admin) {
|
||||
admin = await prisma.user.create({
|
||||
data: {
|
||||
id: "123e4567-e89b-12d3-a456-426614174000",
|
||||
firstName: 'مدیر',
|
||||
lastName: 'سیستم',
|
||||
mobile: '09000000000',
|
||||
role: 'admin',
|
||||
password: 'hashed_password' // just dummy
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const blogs = [
|
||||
{
|
||||
title: 'اهمیت کلسیم در رشد استخوان تولهسگها',
|
||||
slug: 'calcium-importance-for-puppies',
|
||||
content: '<p>کلسیم یکی از مهمترین مواد معدنی برای رشد ساختار استخوانی است. تولهسگها در ماههای اول زندگی به کلسیم بیشتری نیاز دارند...</p>',
|
||||
imageUrl: '/images/wiki/calcium.webp',
|
||||
metaTitle: 'اهمیت کلسیم در رشد سگ',
|
||||
metaDescription: 'چرا کلسیم برای توله سگ ها مهم است؟',
|
||||
keywords: 'کلسیم, سگ, رشد',
|
||||
authorId: admin.id
|
||||
},
|
||||
{
|
||||
title: 'ویتامینهای گروه B و سلامت پوست و مو',
|
||||
slug: 'b-vitamins-and-skin-health',
|
||||
content: '<p>ویتامینهای B Complex نقش حیاتی در حفظ سلامت پوست و درخشش موی گربهها و سگها ایفا میکنند...</p>',
|
||||
imageUrl: '/images/wiki/vitamins.webp',
|
||||
metaTitle: 'ویتامین ب در سلامت پت',
|
||||
metaDescription: 'تاثیر ویتامین بی بر پوست و مو',
|
||||
keywords: 'ویتامین B, پوست, مو, گربه, سگ',
|
||||
authorId: admin.id
|
||||
}
|
||||
];
|
||||
|
||||
for (const blog of blogs) {
|
||||
await prisma.blog.upsert({
|
||||
where: { slug: blog.slug },
|
||||
update: blog,
|
||||
create: blog,
|
||||
});
|
||||
}
|
||||
|
||||
console.log('Seeding blogs finished.');
|
||||
}
|
||||
|
||||
main()
|
||||
.then(async () => {
|
||||
await prisma.$disconnect();
|
||||
})
|
||||
.catch(async (e) => {
|
||||
console.error(e);
|
||||
await prisma.$disconnect();
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -0,0 +1,107 @@
|
||||
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();
|
||||
});
|
||||
Reference in new issue
Block a user