feat: resolve doctors query error, add FAQ, testimonials, blog preview, and full menu management
Deploy Canina / deploy (push) Successful in 1m41s
Deploy Canina / deploy (push) Successful in 1m41s
This commit is contained in:
1 parent
70d58e7086
commit
2c452215c3
31 files changed
+1987
-76
No files matched your search
@@ -1,4 +1,14 @@
|
||||
import { Controller, Get, Param, HttpStatus, Query } from '@nestjs/common';
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Param,
|
||||
Body,
|
||||
HttpStatus,
|
||||
Query,
|
||||
UseGuards,
|
||||
Request,
|
||||
} from '@nestjs/common';
|
||||
import { BlogsService } from './blogs.service';
|
||||
import {
|
||||
ApiTags,
|
||||
@@ -6,8 +16,10 @@ import {
|
||||
ApiResponse,
|
||||
ApiOkResponse,
|
||||
ApiNotFoundResponse,
|
||||
ApiBearerAuth,
|
||||
} from '@nestjs/swagger';
|
||||
import { PaginationDto } from '../common/dto/pagination.dto';
|
||||
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
||||
|
||||
@ApiTags('Blogs - مجله سلامت')
|
||||
@Controller('blogs')
|
||||
@@ -25,6 +37,13 @@ export class BlogsController {
|
||||
return this.blogsService.findAll(query);
|
||||
}
|
||||
|
||||
@Get('homepage')
|
||||
@ApiOperation({ summary: 'دریافت مقالات برای نمایش در صفحه اصلی' })
|
||||
@ApiOkResponse({ description: 'مقالات انتخاب شده برای صفحه اصلی' })
|
||||
findHomepage() {
|
||||
return this.blogsService.findHomepage();
|
||||
}
|
||||
|
||||
@Get(':slug')
|
||||
@ApiOperation({ summary: 'دریافت مقاله با اسلاگ (Slug)' })
|
||||
@ApiOkResponse({ description: 'اطلاعات کامل مقاله' })
|
||||
@@ -32,4 +51,25 @@ export class BlogsController {
|
||||
findOne(@Param('slug') slug: string) {
|
||||
return this.blogsService.findOneBySlug(slug);
|
||||
}
|
||||
|
||||
@Get(':slug/comments')
|
||||
@ApiOperation({ summary: 'دریافت نظرات تأیید شده مقاله' })
|
||||
findComments(@Param('slug') slug: string) {
|
||||
return this.blogsService.findCommentsBySlug(slug);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@Post(':slug/comments')
|
||||
@ApiOperation({ summary: 'ارسال نظر برای مقاله (نیازمند ورود)' })
|
||||
addComment(
|
||||
@Param('slug') slug: string,
|
||||
@Body() body: { userName: string; content: string },
|
||||
@Request() req: any,
|
||||
) {
|
||||
return this.blogsService.addComment(slug, {
|
||||
...body,
|
||||
userId: req.user?.id,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,9 @@ export class BlogsService {
|
||||
author: {
|
||||
select: { firstName: true, lastName: true },
|
||||
},
|
||||
_count: {
|
||||
select: { comments: true },
|
||||
},
|
||||
},
|
||||
}),
|
||||
this.prisma.blog.count({ where: whereClause }),
|
||||
@@ -52,6 +55,36 @@ export class BlogsService {
|
||||
};
|
||||
}
|
||||
|
||||
async findHomepage() {
|
||||
// Find blogs that have showOnHome = true (selected mode)
|
||||
const selectedBlogs = await this.prisma.blog.findMany({
|
||||
where: { isPublished: true, showOnHome: true },
|
||||
take: 3,
|
||||
orderBy: { createdAt: 'desc' },
|
||||
include: {
|
||||
author: { select: { firstName: true, lastName: true } },
|
||||
_count: { select: { comments: true } },
|
||||
},
|
||||
});
|
||||
|
||||
if (selectedBlogs.length > 0) {
|
||||
return { mode: 'selected', blogs: selectedBlogs };
|
||||
}
|
||||
|
||||
// Fallback: return newest 3 published blogs
|
||||
const newestBlogs = await this.prisma.blog.findMany({
|
||||
where: { isPublished: true },
|
||||
take: 3,
|
||||
orderBy: { createdAt: 'desc' },
|
||||
include: {
|
||||
author: { select: { firstName: true, lastName: true } },
|
||||
_count: { select: { comments: true } },
|
||||
},
|
||||
});
|
||||
|
||||
return { mode: 'newest', blogs: newestBlogs };
|
||||
}
|
||||
|
||||
async findOneBySlug(slug: string) {
|
||||
const blog = await this.prisma.blog.findUnique({
|
||||
where: { slug, isPublished: true },
|
||||
@@ -59,6 +92,9 @@ export class BlogsService {
|
||||
author: {
|
||||
select: { firstName: true, lastName: true },
|
||||
},
|
||||
_count: {
|
||||
select: { comments: true },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -66,6 +102,46 @@ export class BlogsService {
|
||||
throw new NotFoundException('مقاله یافت نشد');
|
||||
}
|
||||
|
||||
return blog;
|
||||
// Increment view count
|
||||
await this.prisma.blog.update({
|
||||
where: { id: blog.id },
|
||||
data: { viewCount: { increment: 1 } },
|
||||
});
|
||||
|
||||
return { ...blog, viewCount: blog.viewCount + 1 };
|
||||
}
|
||||
|
||||
async findCommentsBySlug(slug: string) {
|
||||
const blog = await this.prisma.blog.findUnique({
|
||||
where: { slug, isPublished: true },
|
||||
select: { id: true },
|
||||
});
|
||||
if (!blog) throw new NotFoundException('مقاله یافت نشد');
|
||||
|
||||
return this.prisma.blogComment.findMany({
|
||||
where: { blogId: blog.id, status: 'APPROVED' },
|
||||
orderBy: { createdAt: 'asc' },
|
||||
});
|
||||
}
|
||||
|
||||
async addComment(
|
||||
slug: string,
|
||||
data: { userName: string; content: string; userId?: string },
|
||||
) {
|
||||
const blog = await this.prisma.blog.findUnique({
|
||||
where: { slug, isPublished: true },
|
||||
select: { id: true },
|
||||
});
|
||||
if (!blog) throw new NotFoundException('مقاله یافت نشد');
|
||||
|
||||
return this.prisma.blogComment.create({
|
||||
data: {
|
||||
blogId: blog.id,
|
||||
userName: data.userName,
|
||||
content: data.content,
|
||||
userId: data.userId,
|
||||
status: 'PENDING',
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user