- Backend (NestJS): 82 suites, 641 tests passing; 0 ESLint errors; 0 tsc errors. Hardened SSL cert/key matching, SSRF IP pinning, and eBank validation. - Admin Panel (Vite/React): 48 suites, 300 tests passing; 0 ESLint errors; 0 tsc errors. Full coverage across all pages and settings. - Storefront (Next.js): 62 suites, 368 tests passing; 0 ESLint errors; 0 tsc errors. - Fixed unmount lifecycle guards, promise error handling, and component edge cases.
71 lines
2.0 KiB
TypeScript
71 lines
2.0 KiB
TypeScript
import { Injectable } from "@nestjs/common";
|
|
import { PrismaService } from "../prisma/prisma.service";
|
|
|
|
@Injectable()
|
|
export class SeoService {
|
|
constructor(private prisma: PrismaService) {}
|
|
|
|
async getSitemapUrls() {
|
|
const [products, categories, blogs] = await Promise.all([
|
|
this.prisma.product.findMany({ select: { slug: true, createdAt: true } }),
|
|
this.prisma.category.findMany({
|
|
select: { slug: true, createdAt: true },
|
|
}),
|
|
this.prisma.blog.findMany({
|
|
where: { isPublished: true },
|
|
select: { slug: true, updatedAt: true },
|
|
}),
|
|
]);
|
|
|
|
return {
|
|
products: products.map((p) => ({
|
|
url: `/shop/${p.slug}`,
|
|
lastmod: p.createdAt,
|
|
})),
|
|
categories: categories.map((c) => ({
|
|
url: `/shop?category=${c.slug}`,
|
|
lastmod: c.createdAt,
|
|
})),
|
|
blogs: blogs.map((b) => ({
|
|
url: `/blog/${b.slug}`,
|
|
lastmod: b.updatedAt,
|
|
})),
|
|
};
|
|
}
|
|
|
|
async getProductSchema(idOrSlug: string) {
|
|
const isUuid =
|
|
/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/.test(
|
|
idOrSlug,
|
|
);
|
|
const product = await this.prisma.product.findFirst({
|
|
where: isUuid ? { id: idOrSlug } : { slug: idOrSlug },
|
|
});
|
|
|
|
if (!product) return null;
|
|
|
|
return {
|
|
"@context": "https://schema.org/",
|
|
"@type": "Product",
|
|
name: product.nameFa,
|
|
alternateName: product.nameEn,
|
|
image: [product.imageUrl],
|
|
description: product.description,
|
|
sku: product.artNo,
|
|
gtin: product.barcode || undefined,
|
|
brand: {
|
|
"@type": "Brand",
|
|
name: "Canina Pharma",
|
|
},
|
|
offers: {
|
|
"@type": "Offer",
|
|
url: `https://canina.ir/shop/${product.slug}`,
|
|
priceCurrency: "IRR",
|
|
price: Number(product.priceValue) * 10, // Toman to Rial conversion if needed
|
|
availability: "https://schema.org/InStock",
|
|
itemCondition: "https://schema.org/NewCondition",
|
|
},
|
|
};
|
|
}
|
|
}
|