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
@@ -3,6 +3,7 @@ import {
|
||||
Get,
|
||||
Post,
|
||||
Put,
|
||||
Patch,
|
||||
Delete,
|
||||
Body,
|
||||
Param,
|
||||
@@ -19,7 +20,6 @@ import {
|
||||
ApiOperation,
|
||||
ApiQuery,
|
||||
} from '@nestjs/swagger';
|
||||
|
||||
import { PaginationDto } from '../common/dto/pagination.dto';
|
||||
|
||||
@ApiTags('Admin - مدیریت مقالات (بلاگ)')
|
||||
@@ -31,9 +31,9 @@ export class BlogsController {
|
||||
|
||||
@Get()
|
||||
@ApiOperation({ summary: 'لیست مقالات' })
|
||||
@ApiQuery({ name: 'page', required: false, description: 'شماره صفحه' })
|
||||
@ApiQuery({ name: 'limit', required: false, description: 'تعداد آیتمها' })
|
||||
@ApiQuery({ name: 'search', required: false, description: 'جستجو' })
|
||||
@ApiQuery({ name: 'page', required: false })
|
||||
@ApiQuery({ name: 'limit', required: false })
|
||||
@ApiQuery({ name: 'search', required: false })
|
||||
async getBlogs(@Query() query: PaginationDto) {
|
||||
return this.blogsService.getBlogs(query);
|
||||
}
|
||||
@@ -64,4 +64,43 @@ export class BlogsController {
|
||||
await this.blogsService.deleteBlog(id);
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
// Blog Comments endpoints
|
||||
@Get('comments')
|
||||
@ApiOperation({ summary: 'لیست نظرات مقالات' })
|
||||
@ApiQuery({
|
||||
name: 'status',
|
||||
required: false,
|
||||
description: 'PENDING | APPROVED | REJECTED',
|
||||
})
|
||||
@ApiQuery({ name: 'blogId', required: false })
|
||||
@ApiQuery({ name: 'page', required: false })
|
||||
@ApiQuery({ name: 'limit', required: false })
|
||||
async getComments(
|
||||
@Query()
|
||||
query: {
|
||||
page?: number;
|
||||
limit?: number;
|
||||
status?: string;
|
||||
blogId?: string;
|
||||
},
|
||||
) {
|
||||
return this.blogsService.getComments(query);
|
||||
}
|
||||
|
||||
@Patch('comments/:id/status')
|
||||
@ApiOperation({ summary: 'تغییر وضعیت نظر (تأیید/رد)' })
|
||||
async updateCommentStatus(
|
||||
@Param('id') id: string,
|
||||
@Body() body: { status: 'APPROVED' | 'REJECTED' },
|
||||
) {
|
||||
return this.blogsService.updateCommentStatus(id, body.status);
|
||||
}
|
||||
|
||||
@Delete('comments/:id')
|
||||
@ApiOperation({ summary: 'حذف نظر' })
|
||||
async deleteComment(@Param('id') id: string) {
|
||||
await this.blogsService.deleteComment(id);
|
||||
return { success: true };
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,13 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { Prisma } from '@prisma/client';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
|
||||
export class BlogQuery {
|
||||
page?: number | string;
|
||||
limit?: number | string;
|
||||
search?: string;
|
||||
}
|
||||
import { PaginationDto } from '../common/dto/pagination.dto';
|
||||
|
||||
@Injectable()
|
||||
export class BlogsService {
|
||||
constructor(private prisma: PrismaService) {}
|
||||
|
||||
async getBlogs(query: BlogQuery = {}) {
|
||||
async getBlogs(query: PaginationDto) {
|
||||
const page = Number(query.page) || 1;
|
||||
const limit = Number(query.limit) || 10;
|
||||
const skip = (page - 1) * limit;
|
||||
@@ -27,7 +22,10 @@ export class BlogsService {
|
||||
skip,
|
||||
take: limit,
|
||||
orderBy: { createdAt: 'desc' },
|
||||
include: { author: { select: { firstName: true, lastName: true } } },
|
||||
include: {
|
||||
author: { select: { firstName: true, lastName: true } },
|
||||
_count: { select: { comments: true } },
|
||||
},
|
||||
}),
|
||||
this.prisma.blog.count({ where }),
|
||||
]);
|
||||
@@ -63,4 +61,51 @@ export class BlogsService {
|
||||
if (!blog) throw new NotFoundException('Blog not found');
|
||||
return this.prisma.blog.delete({ where: { id } });
|
||||
}
|
||||
|
||||
// Blog Comments Management
|
||||
async getComments(query: {
|
||||
page?: number;
|
||||
limit?: number;
|
||||
status?: string;
|
||||
blogId?: string;
|
||||
}) {
|
||||
const page = Number(query.page) || 1;
|
||||
const limit = Number(query.limit) || 20;
|
||||
const skip = (page - 1) * limit;
|
||||
|
||||
const where: Prisma.BlogCommentWhereInput = {};
|
||||
if (query.status) where.status = query.status;
|
||||
if (query.blogId) where.blogId = query.blogId;
|
||||
|
||||
const [data, total] = await Promise.all([
|
||||
this.prisma.blogComment.findMany({
|
||||
where,
|
||||
skip,
|
||||
take: limit,
|
||||
orderBy: { createdAt: 'desc' },
|
||||
include: {
|
||||
blog: { select: { title: true, slug: true } },
|
||||
user: { select: { firstName: true, lastName: true, mobile: true } },
|
||||
},
|
||||
}),
|
||||
this.prisma.blogComment.count({ where }),
|
||||
]);
|
||||
|
||||
return {
|
||||
data,
|
||||
meta: { total, page, limit, lastPage: Math.ceil(total / limit) },
|
||||
};
|
||||
}
|
||||
|
||||
async updateCommentStatus(id: string, status: 'APPROVED' | 'REJECTED') {
|
||||
const comment = await this.prisma.blogComment.findUnique({ where: { id } });
|
||||
if (!comment) throw new NotFoundException('Comment not found');
|
||||
return this.prisma.blogComment.update({ where: { id }, data: { status } });
|
||||
}
|
||||
|
||||
async deleteComment(id: string) {
|
||||
const comment = await this.prisma.blogComment.findUnique({ where: { id } });
|
||||
if (!comment) throw new NotFoundException('Comment not found');
|
||||
return this.prisma.blogComment.delete({ where: { id } });
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user