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
@@ -0,0 +1,89 @@
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Put,
|
||||
Delete,
|
||||
Body,
|
||||
Param,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { FaqService } from './faq.service';
|
||||
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
|
||||
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
||||
import { RolesGuard } from '../common/guards/roles.guard';
|
||||
import { Roles } from '../common/decorators/roles.decorator';
|
||||
|
||||
@ApiTags('FAQ - سوالات متداول')
|
||||
@Controller('faq')
|
||||
export class FaqController {
|
||||
constructor(private readonly faqService: FaqService) {}
|
||||
|
||||
@Get()
|
||||
@ApiOperation({ summary: 'دریافت سوالات متداول فعال برای صفحه اصلی' })
|
||||
findActive() {
|
||||
return this.faqService.findActive();
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles('Admin')
|
||||
@ApiBearerAuth()
|
||||
@Get('admin')
|
||||
@ApiOperation({ summary: 'دریافت تمام سوالات (ادمین)' })
|
||||
findAll() {
|
||||
return this.faqService.findAll();
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles('Admin')
|
||||
@ApiBearerAuth()
|
||||
@Post()
|
||||
@ApiOperation({ summary: 'ایجاد سوال متداول جدید' })
|
||||
create(
|
||||
@Body()
|
||||
body: {
|
||||
question: string;
|
||||
answer: string;
|
||||
order?: number;
|
||||
isActive?: boolean;
|
||||
},
|
||||
) {
|
||||
return this.faqService.create(body);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles('Admin')
|
||||
@ApiBearerAuth()
|
||||
@Put('reorder')
|
||||
@ApiOperation({ summary: 'مرتبسازی سوالات' })
|
||||
reorder(@Body() body: { items: { id: string; order: number }[] }) {
|
||||
return this.faqService.reorder(body.items);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles('Admin')
|
||||
@ApiBearerAuth()
|
||||
@Put(':id')
|
||||
@ApiOperation({ summary: 'ویرایش سوال متداول' })
|
||||
update(
|
||||
@Param('id') id: string,
|
||||
@Body()
|
||||
body: Partial<{
|
||||
question: string;
|
||||
answer: string;
|
||||
order: number;
|
||||
isActive: boolean;
|
||||
}>,
|
||||
) {
|
||||
return this.faqService.update(id, body);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles('Admin')
|
||||
@ApiBearerAuth()
|
||||
@Delete(':id')
|
||||
@ApiOperation({ summary: 'حذف سوال متداول' })
|
||||
remove(@Param('id') id: string) {
|
||||
return this.faqService.remove(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { FaqController } from './faq.controller';
|
||||
import { FaqService } from './faq.service';
|
||||
|
||||
@Module({
|
||||
controllers: [FaqController],
|
||||
providers: [FaqService],
|
||||
})
|
||||
export class FaqModule {}
|
||||
@@ -0,0 +1,63 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
|
||||
@Injectable()
|
||||
export class FaqService {
|
||||
constructor(private prisma: PrismaService) {}
|
||||
|
||||
// Public: only active FAQs
|
||||
async findActive() {
|
||||
return this.prisma.fAQ.findMany({
|
||||
where: { isActive: true },
|
||||
orderBy: { order: 'asc' },
|
||||
});
|
||||
}
|
||||
|
||||
// Admin: all FAQs
|
||||
async findAll() {
|
||||
return this.prisma.fAQ.findMany({
|
||||
orderBy: { order: 'asc' },
|
||||
});
|
||||
}
|
||||
|
||||
async create(data: {
|
||||
question: string;
|
||||
answer: string;
|
||||
order?: number;
|
||||
isActive?: boolean;
|
||||
}) {
|
||||
return this.prisma.fAQ.create({ data });
|
||||
}
|
||||
|
||||
async update(
|
||||
id: string,
|
||||
data: Partial<{
|
||||
question: string;
|
||||
answer: string;
|
||||
order: number;
|
||||
isActive: boolean;
|
||||
}>,
|
||||
) {
|
||||
const faq = await this.prisma.fAQ.findUnique({ where: { id } });
|
||||
if (!faq) throw new NotFoundException('سوال یافت نشد');
|
||||
return this.prisma.fAQ.update({ where: { id }, data });
|
||||
}
|
||||
|
||||
async remove(id: string) {
|
||||
const faq = await this.prisma.fAQ.findUnique({ where: { id } });
|
||||
if (!faq) throw new NotFoundException('سوال یافت نشد');
|
||||
return this.prisma.fAQ.delete({ where: { id } });
|
||||
}
|
||||
|
||||
async reorder(items: { id: string; order: number }[]) {
|
||||
await Promise.all(
|
||||
items.map((item) =>
|
||||
this.prisma.fAQ.update({
|
||||
where: { id: item.id },
|
||||
data: { order: item.order },
|
||||
}),
|
||||
),
|
||||
);
|
||||
return { success: true };
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user