test: comprehensive test suites and quality gates pass across backend, storefront and admin
- 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.
This commit is contained in:
1 parent
1e73715169
commit
ddbf1ca026
439 files changed
+32911
-6107
No files matched your search
@@ -4,11 +4,11 @@ import {
|
||||
OnModuleInit,
|
||||
OnModuleDestroy,
|
||||
Logger,
|
||||
} from '@nestjs/common';
|
||||
import { Prisma } from '@prisma/client';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { PaginationDto } from '../common/dto/pagination.dto';
|
||||
import { RevalidationService } from '../common/revalidation/revalidation.service';
|
||||
} from "@nestjs/common";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { PrismaService } from "../prisma/prisma.service";
|
||||
import { PaginationDto } from "../common/dto/pagination.dto";
|
||||
import { RevalidationService } from "../common/revalidation/revalidation.service";
|
||||
|
||||
@Injectable()
|
||||
export class BlogsService implements OnModuleInit, OnModuleDestroy {
|
||||
@@ -25,7 +25,7 @@ export class BlogsService implements OnModuleInit, OnModuleDestroy {
|
||||
// Start background scheduled publishing worker (every 60 seconds)
|
||||
this.schedulerTimer = setInterval(() => {
|
||||
this.publishDueScheduledBlogs().catch((err) => {
|
||||
this.logger.error('Error in publishDueScheduledBlogs worker:', err);
|
||||
this.logger.error("Error in publishDueScheduledBlogs worker:", err);
|
||||
});
|
||||
}, 60000);
|
||||
// Run an initial check on startup
|
||||
@@ -42,13 +42,13 @@ export class BlogsService implements OnModuleInit, OnModuleDestroy {
|
||||
private async seedDefaultCategories() {
|
||||
try {
|
||||
const defaultCategories = [
|
||||
{ name: 'تغذیه و رژیم غذایی', slug: 'nutrition', order: 1 },
|
||||
{ name: 'سلامت گوارش و متابولیسم', slug: 'digestion', order: 2 },
|
||||
{ name: 'مفاصل، استخوان و اسکلت', slug: 'joints-bones', order: 3 },
|
||||
{ name: 'پوست، مو و آلرژی', slug: 'skin-coat', order: 4 },
|
||||
{ name: "تغذیه و رژیم غذایی", slug: "nutrition", order: 1 },
|
||||
{ name: "سلامت گوارش و متابولیسم", slug: "digestion", order: 2 },
|
||||
{ name: "مفاصل، استخوان و اسکلت", slug: "joints-bones", order: 3 },
|
||||
{ name: "پوست، مو و آلرژی", slug: "skin-coat", order: 4 },
|
||||
{
|
||||
name: 'ایمنی، پیشگیری و مراقبت بالینی',
|
||||
slug: 'health-prevention',
|
||||
name: "ایمنی، پیشگیری و مراقبت بالینی",
|
||||
slug: "health-prevention",
|
||||
order: 5,
|
||||
},
|
||||
];
|
||||
@@ -62,7 +62,7 @@ export class BlogsService implements OnModuleInit, OnModuleDestroy {
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn(
|
||||
'[BlogsService] Failed to seed default blog categories:',
|
||||
"[BlogsService] Failed to seed default blog categories:",
|
||||
err,
|
||||
);
|
||||
}
|
||||
@@ -83,9 +83,9 @@ export class BlogsService implements OnModuleInit, OnModuleDestroy {
|
||||
|
||||
if (query.search) {
|
||||
where.OR = [
|
||||
{ title: { contains: query.search, mode: 'insensitive' } },
|
||||
{ excerpt: { contains: query.search, mode: 'insensitive' } },
|
||||
{ slug: { contains: query.search, mode: 'insensitive' } },
|
||||
{ title: { contains: query.search, mode: "insensitive" } },
|
||||
{ excerpt: { contains: query.search, mode: "insensitive" } },
|
||||
{ slug: { contains: query.search, mode: "insensitive" } },
|
||||
];
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ export class BlogsService implements OnModuleInit, OnModuleDestroy {
|
||||
where,
|
||||
skip,
|
||||
take: limit,
|
||||
orderBy: { createdAt: 'desc' },
|
||||
orderBy: { createdAt: "desc" },
|
||||
include: {
|
||||
author: {
|
||||
select: { id: true, firstName: true, lastName: true, email: true },
|
||||
@@ -135,7 +135,7 @@ export class BlogsService implements OnModuleInit, OnModuleDestroy {
|
||||
tags: true,
|
||||
},
|
||||
});
|
||||
if (!blog) throw new NotFoundException('Blog not found');
|
||||
if (!blog) throw new NotFoundException("Blog not found");
|
||||
return blog;
|
||||
}
|
||||
|
||||
@@ -159,8 +159,8 @@ export class BlogsService implements OnModuleInit, OnModuleDestroy {
|
||||
if (trimmed) {
|
||||
const slug = trimmed
|
||||
.toLowerCase()
|
||||
.replace(/\s+/g, '-')
|
||||
.replace(/[^\w\u0600-\u06FF-]+/g, '');
|
||||
.replace(/\s+/g, "-")
|
||||
.replace(/[^\w\u0600-\u06FF-]+/g, "");
|
||||
tagConnectOrCreate.push({
|
||||
where: { name: trimmed },
|
||||
create: { name: trimmed, slug: slug || `tag-${Date.now()}` },
|
||||
@@ -174,20 +174,20 @@ export class BlogsService implements OnModuleInit, OnModuleDestroy {
|
||||
const parsedScheduledAt = scheduledAt ? new Date(scheduledAt) : null;
|
||||
const isFutureSchedule = parsedScheduledAt && parsedScheduledAt > now;
|
||||
|
||||
let finalStatus = rest.status || 'PUBLISHED';
|
||||
let finalStatus = rest.status || "PUBLISHED";
|
||||
let finalIsPublished =
|
||||
rest.isPublished !== undefined ? rest.isPublished : true;
|
||||
let finalPublishedAt = publishedAt ? new Date(publishedAt) : null;
|
||||
|
||||
if (isFutureSchedule) {
|
||||
finalStatus = 'SCHEDULED';
|
||||
finalStatus = "SCHEDULED";
|
||||
finalIsPublished = false;
|
||||
finalPublishedAt = null;
|
||||
} else if (parsedScheduledAt && parsedScheduledAt <= now) {
|
||||
finalStatus = 'PUBLISHED';
|
||||
finalStatus = "PUBLISHED";
|
||||
finalIsPublished = true;
|
||||
finalPublishedAt = parsedScheduledAt;
|
||||
} else if (!finalPublishedAt && finalStatus === 'PUBLISHED') {
|
||||
} else if (!finalPublishedAt && finalStatus === "PUBLISHED") {
|
||||
finalPublishedAt = now;
|
||||
}
|
||||
|
||||
@@ -220,7 +220,7 @@ export class BlogsService implements OnModuleInit, OnModuleDestroy {
|
||||
|
||||
async updateBlog(id: string, data: any) {
|
||||
const blog = await this.prisma.blog.findUnique({ where: { id } });
|
||||
if (!blog) throw new NotFoundException('Blog not found');
|
||||
if (!blog) throw new NotFoundException("Blog not found");
|
||||
|
||||
const {
|
||||
tags,
|
||||
@@ -252,11 +252,11 @@ export class BlogsService implements OnModuleInit, OnModuleDestroy {
|
||||
updatePayload.scheduledAt = parsedScheduledAt;
|
||||
|
||||
if (parsedScheduledAt && parsedScheduledAt > now) {
|
||||
updatePayload.status = 'SCHEDULED';
|
||||
updatePayload.status = "SCHEDULED";
|
||||
updatePayload.isPublished = false;
|
||||
updatePayload.publishedAt = null;
|
||||
} else if (parsedScheduledAt && parsedScheduledAt <= now) {
|
||||
updatePayload.status = 'PUBLISHED';
|
||||
updatePayload.status = "PUBLISHED";
|
||||
updatePayload.isPublished = true;
|
||||
updatePayload.publishedAt = parsedScheduledAt;
|
||||
updatePayload.createdAt = parsedScheduledAt;
|
||||
@@ -272,8 +272,8 @@ export class BlogsService implements OnModuleInit, OnModuleDestroy {
|
||||
if (trimmed) {
|
||||
const slug = trimmed
|
||||
.toLowerCase()
|
||||
.replace(/\s+/g, '-')
|
||||
.replace(/[^\w\u0600-\u06FF-]+/g, '');
|
||||
.replace(/\s+/g, "-")
|
||||
.replace(/[^\w\u0600-\u06FF-]+/g, "");
|
||||
tagConnectOrCreate.push({
|
||||
where: { name: trimmed },
|
||||
create: { name: trimmed, slug: slug || `tag-${Date.now()}` },
|
||||
@@ -302,7 +302,7 @@ export class BlogsService implements OnModuleInit, OnModuleDestroy {
|
||||
|
||||
async deleteBlog(id: string) {
|
||||
const blog = await this.prisma.blog.findUnique({ where: { id } });
|
||||
if (!blog) throw new NotFoundException('Blog not found');
|
||||
if (!blog) throw new NotFoundException("Blog not found");
|
||||
const res = await this.prisma.blog.delete({ where: { id } });
|
||||
await this.revalidationService.revalidateBlog(blog.slug);
|
||||
return res;
|
||||
@@ -318,14 +318,14 @@ export class BlogsService implements OnModuleInit, OnModuleDestroy {
|
||||
email: true,
|
||||
role: true,
|
||||
},
|
||||
orderBy: { firstName: 'asc' },
|
||||
orderBy: { firstName: "asc" },
|
||||
});
|
||||
}
|
||||
|
||||
// Blog Categories Management
|
||||
async getBlogCategories() {
|
||||
return this.prisma.blogCategory.findMany({
|
||||
orderBy: { order: 'asc' },
|
||||
orderBy: { order: "asc" },
|
||||
include: {
|
||||
parent: true,
|
||||
children: true,
|
||||
@@ -349,7 +349,7 @@ export class BlogsService implements OnModuleInit, OnModuleDestroy {
|
||||
// Blog Tags Management
|
||||
async getBlogTags() {
|
||||
return this.prisma.blogTag.findMany({
|
||||
orderBy: { createdAt: 'desc' },
|
||||
orderBy: { createdAt: "desc" },
|
||||
include: {
|
||||
_count: { select: { blogs: true } },
|
||||
},
|
||||
@@ -361,8 +361,8 @@ export class BlogsService implements OnModuleInit, OnModuleDestroy {
|
||||
data.slug ||
|
||||
data.name
|
||||
.toLowerCase()
|
||||
.replace(/\s+/g, '-')
|
||||
.replace(/[^\w\u0600-\u06FF-]+/g, '');
|
||||
.replace(/\s+/g, "-")
|
||||
.replace(/[^\w\u0600-\u06FF-]+/g, "");
|
||||
return this.prisma.blogTag.create({
|
||||
data: { name: data.name, slug: slug || `tag-${Date.now()}` },
|
||||
});
|
||||
@@ -392,7 +392,7 @@ export class BlogsService implements OnModuleInit, OnModuleDestroy {
|
||||
where,
|
||||
skip,
|
||||
take: limit,
|
||||
orderBy: { createdAt: 'desc' },
|
||||
orderBy: { createdAt: "desc" },
|
||||
include: {
|
||||
blog: { select: { title: true, slug: true } },
|
||||
user: { select: { firstName: true, lastName: true, mobile: true } },
|
||||
@@ -407,12 +407,12 @@ export class BlogsService implements OnModuleInit, OnModuleDestroy {
|
||||
};
|
||||
}
|
||||
|
||||
async updateCommentStatus(id: string, status: 'APPROVED' | 'REJECTED') {
|
||||
async updateCommentStatus(id: string, status: "APPROVED" | "REJECTED") {
|
||||
const comment = await this.prisma.blogComment.findUnique({
|
||||
where: { id },
|
||||
include: { blog: { select: { slug: true } } },
|
||||
});
|
||||
if (!comment) throw new NotFoundException('Comment not found');
|
||||
if (!comment) throw new NotFoundException("Comment not found");
|
||||
const updated = await this.prisma.blogComment.update({
|
||||
where: { id },
|
||||
data: { status },
|
||||
@@ -428,7 +428,7 @@ export class BlogsService implements OnModuleInit, OnModuleDestroy {
|
||||
where: { id },
|
||||
include: { blog: { select: { slug: true } } },
|
||||
});
|
||||
if (!comment) throw new NotFoundException('Comment not found');
|
||||
if (!comment) throw new NotFoundException("Comment not found");
|
||||
const res = await this.prisma.blogComment.delete({ where: { id } });
|
||||
if (comment.blog?.slug) {
|
||||
await this.revalidationService.revalidateBlog(comment.blog.slug);
|
||||
@@ -443,7 +443,7 @@ export class BlogsService implements OnModuleInit, OnModuleDestroy {
|
||||
const now = new Date();
|
||||
const dueBlogs = await this.prisma.blog.findMany({
|
||||
where: {
|
||||
status: 'SCHEDULED',
|
||||
status: "SCHEDULED",
|
||||
scheduledAt: { lte: now },
|
||||
},
|
||||
select: {
|
||||
@@ -469,7 +469,7 @@ export class BlogsService implements OnModuleInit, OnModuleDestroy {
|
||||
await this.prisma.blog.update({
|
||||
where: { id: blog.id },
|
||||
data: {
|
||||
status: 'PUBLISHED',
|
||||
status: "PUBLISHED",
|
||||
isPublished: true,
|
||||
publishedAt: publishDate,
|
||||
createdAt: publishDate,
|
||||
|
||||
Reference in new issue
Block a user