90 lines
2.2 KiB
TypeScript
90 lines
2.2 KiB
TypeScript
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);
|
|
}
|
|
}
|