54 lines
1.3 KiB
TypeScript
54 lines
1.3 KiB
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { PrismaService } from '../prisma/prisma.service';
|
|
|
|
@Injectable()
|
|
export class HomeService {
|
|
constructor(private prisma: PrismaService) {}
|
|
|
|
async getHomeData() {
|
|
// Fetch Banners
|
|
const heroBanners = await this.prisma.heroBanner.findMany({
|
|
where: { isActive: true },
|
|
orderBy: { order: 'asc' },
|
|
});
|
|
|
|
// Fetch Vet Testimonials
|
|
const vetTestimonials = await this.prisma.vetTestimonial.findMany({
|
|
where: { isActive: true },
|
|
orderBy: { order: 'asc' },
|
|
});
|
|
|
|
// Fetch Smart Advisor Rules
|
|
const smartAdvisorRules = await this.prisma.smartAdvisorRule.findMany({
|
|
include: {
|
|
product: {
|
|
select: {
|
|
id: true,
|
|
nameFa: true,
|
|
nameEn: true,
|
|
slug: true,
|
|
imageUrl: true,
|
|
priceValue: true,
|
|
priceDisplay: true,
|
|
categorySlug: true,
|
|
categoryId: true
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
// We can also fetch featured products here if needed, or rely on a separate endpoint
|
|
const featuredProducts = await this.prisma.product.findMany({
|
|
take: 4,
|
|
orderBy: { createdAt: 'desc' }, // Or any other criteria
|
|
});
|
|
|
|
return {
|
|
heroBanners,
|
|
vetTestimonials,
|
|
smartAdvisorRules,
|
|
featuredProducts
|
|
};
|
|
}
|
|
}
|