feat(backend): implement CmsModule for full CRUD of HeroBanners, VetTestimonials, and SmartAdvisorRules
This commit is contained in:
1 parent
0162bc7b6d
commit
0046fb7106
7 files changed
+482
-59
No files matched your search
@@ -0,0 +1,91 @@
|
||||
import { Controller, Get, Post, Put, Delete, Body, Param, UseGuards } from '@nestjs/common';
|
||||
import { CmsService } from './cms.service';
|
||||
import { CreateHeroBannerDto, CreateVetTestimonialDto, CreateSmartAdvisorRuleDto } from './dto/cms.dto';
|
||||
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
|
||||
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
||||
import { RolesGuard } from '../auth/roles.guard';
|
||||
import { Roles } from '../auth/roles.decorator';
|
||||
|
||||
@ApiTags('CMS - مدیریت بنرها، نظرات دامپزشکان و قوانین مشاوره')
|
||||
@Controller('admin/cms')
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles('ADMIN')
|
||||
@ApiBearerAuth()
|
||||
export class CmsController {
|
||||
constructor(private readonly cmsService: CmsService) {}
|
||||
|
||||
// Hero Banners Admin
|
||||
@Get('hero-banners')
|
||||
@ApiOperation({ summary: 'لیست تمام بنرهای هیرو' })
|
||||
getHeroBanners() {
|
||||
return this.cmsService.getHeroBanners();
|
||||
}
|
||||
|
||||
@Post('hero-banners')
|
||||
@ApiOperation({ summary: 'ایجاد بنر جدید هیرو' })
|
||||
createHeroBanner(@Body() dto: CreateHeroBannerDto) {
|
||||
return this.cmsService.createHeroBanner(dto);
|
||||
}
|
||||
|
||||
@Put('hero-banners/:id')
|
||||
@ApiOperation({ summary: 'ویرایش بنر هیرو' })
|
||||
updateHeroBanner(@Param('id') id: string, @Body() dto: Partial<CreateHeroBannerDto>) {
|
||||
return this.cmsService.updateHeroBanner(id, dto);
|
||||
}
|
||||
|
||||
@Delete('hero-banners/:id')
|
||||
@ApiOperation({ summary: 'حذف بنر هیرو' })
|
||||
deleteHeroBanner(@Param('id') id: string) {
|
||||
return this.cmsService.deleteHeroBanner(id);
|
||||
}
|
||||
|
||||
// Vet Testimonials Admin
|
||||
@Get('vet-testimonials')
|
||||
@ApiOperation({ summary: 'لیست تمام نظرات دامپزشکان' })
|
||||
getVetTestimonials() {
|
||||
return this.cmsService.getVetTestimonials();
|
||||
}
|
||||
|
||||
@Post('vet-testimonials')
|
||||
@ApiOperation({ summary: 'ایجاد نظر دامپزشک جدید' })
|
||||
createVetTestimonial(@Body() dto: CreateVetTestimonialDto) {
|
||||
return this.cmsService.createVetTestimonial(dto);
|
||||
}
|
||||
|
||||
@Put('vet-testimonials/:id')
|
||||
@ApiOperation({ summary: 'ویرایش نظر دامپزشک' })
|
||||
updateVetTestimonial(@Param('id') id: string, @Body() dto: Partial<CreateVetTestimonialDto>) {
|
||||
return this.cmsService.updateVetTestimonial(id, dto);
|
||||
}
|
||||
|
||||
@Delete('vet-testimonials/:id')
|
||||
@ApiOperation({ summary: 'حذف نظر دامپزشک' })
|
||||
deleteVetTestimonial(@Param('id') id: string) {
|
||||
return this.cmsService.deleteVetTestimonial(id);
|
||||
}
|
||||
|
||||
// Smart Advisor Rules Admin
|
||||
@Get('smart-advisor-rules')
|
||||
@ApiOperation({ summary: 'لیست قوانین دستیار هوشمند سلامت' })
|
||||
getSmartAdvisorRules() {
|
||||
return this.cmsService.getSmartAdvisorRules();
|
||||
}
|
||||
|
||||
@Post('smart-advisor-rules')
|
||||
@ApiOperation({ summary: 'ایجاد قانون مشاوره هوشمند جدید' })
|
||||
createSmartAdvisorRule(@Body() dto: CreateSmartAdvisorRuleDto) {
|
||||
return this.cmsService.createSmartAdvisorRule(dto);
|
||||
}
|
||||
|
||||
@Put('smart-advisor-rules/:id')
|
||||
@ApiOperation({ summary: 'ویرایش قانون مشاوره هوشمند' })
|
||||
updateSmartAdvisorRule(@Param('id') id: string, @Body() dto: Partial<CreateSmartAdvisorRuleDto>) {
|
||||
return this.cmsService.updateSmartAdvisorRule(id, dto);
|
||||
}
|
||||
|
||||
@Delete('smart-advisor-rules/:id')
|
||||
@ApiOperation({ summary: 'حذف قانون مشاوره هوشمند' })
|
||||
deleteSmartAdvisorRule(@Param('id') id: string) {
|
||||
return this.cmsService.deleteSmartAdvisorRule(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { CmsController } from './cms.controller';
|
||||
import { CmsService } from './cms.service';
|
||||
import { PrismaModule } from '../prisma/prisma.module';
|
||||
|
||||
@Module({
|
||||
imports: [PrismaModule],
|
||||
controllers: [CmsController],
|
||||
providers: [CmsService],
|
||||
exports: [CmsService],
|
||||
})
|
||||
export class CmsModule {}
|
||||
@@ -0,0 +1,71 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { CreateHeroBannerDto, CreateVetTestimonialDto, CreateSmartAdvisorRuleDto } from './dto/cms.dto';
|
||||
|
||||
@Injectable()
|
||||
export class CmsService {
|
||||
constructor(private prisma: PrismaService) {}
|
||||
|
||||
// --- Hero Banners ---
|
||||
async getHeroBanners() {
|
||||
return this.prisma.heroBanner.findMany({
|
||||
orderBy: { order: 'asc' },
|
||||
});
|
||||
}
|
||||
|
||||
async createHeroBanner(dto: CreateHeroBannerDto) {
|
||||
return this.prisma.heroBanner.create({ data: dto });
|
||||
}
|
||||
|
||||
async updateHeroBanner(id: string, dto: Partial<CreateHeroBannerDto>) {
|
||||
const exists = await this.prisma.heroBanner.findUnique({ where: { id } });
|
||||
if (!exists) throw new NotFoundException('Hero banner not found');
|
||||
return this.prisma.heroBanner.update({ where: { id }, data: dto });
|
||||
}
|
||||
|
||||
async deleteHeroBanner(id: string) {
|
||||
return this.prisma.heroBanner.delete({ where: { id } });
|
||||
}
|
||||
|
||||
// --- Vet Testimonials ---
|
||||
async getVetTestimonials() {
|
||||
return this.prisma.vetTestimonial.findMany({
|
||||
orderBy: { order: 'asc' },
|
||||
});
|
||||
}
|
||||
|
||||
async createVetTestimonial(dto: CreateVetTestimonialDto) {
|
||||
return this.prisma.vetTestimonial.create({ data: dto });
|
||||
}
|
||||
|
||||
async updateVetTestimonial(id: string, dto: Partial<CreateVetTestimonialDto>) {
|
||||
const exists = await this.prisma.vetTestimonial.findUnique({ where: { id } });
|
||||
if (!exists) throw new NotFoundException('Vet testimonial not found');
|
||||
return this.prisma.vetTestimonial.update({ where: { id }, data: dto });
|
||||
}
|
||||
|
||||
async deleteVetTestimonial(id: string) {
|
||||
return this.prisma.vetTestimonial.delete({ where: { id } });
|
||||
}
|
||||
|
||||
// --- Smart Advisor Rules ---
|
||||
async getSmartAdvisorRules() {
|
||||
return this.prisma.smartAdvisorRule.findMany({
|
||||
include: { product: true },
|
||||
});
|
||||
}
|
||||
|
||||
async createSmartAdvisorRule(dto: CreateSmartAdvisorRuleDto) {
|
||||
return this.prisma.smartAdvisorRule.create({ data: dto });
|
||||
}
|
||||
|
||||
async updateSmartAdvisorRule(id: string, dto: Partial<CreateSmartAdvisorRuleDto>) {
|
||||
const exists = await this.prisma.smartAdvisorRule.findUnique({ where: { id } });
|
||||
if (!exists) throw new NotFoundException('Smart advisor rule not found');
|
||||
return this.prisma.smartAdvisorRule.update({ where: { id }, data: dto });
|
||||
}
|
||||
|
||||
async deleteSmartAdvisorRule(id: string) {
|
||||
return this.prisma.smartAdvisorRule.delete({ where: { id } });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
import { IsString, IsOptional, IsBoolean, IsNumber, IsUUID } from 'class-validator';
|
||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||
|
||||
export class CreateHeroBannerDto {
|
||||
@ApiProperty({ description: 'عنوان اصلی بنر' })
|
||||
@IsString()
|
||||
title: string;
|
||||
|
||||
@ApiPropertyOptional({ description: 'زیرعنوان بنر' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
subtitle?: string;
|
||||
|
||||
@ApiProperty({ description: 'آدرس تصویر بنر' })
|
||||
@IsString()
|
||||
imageUrl: string;
|
||||
|
||||
@ApiPropertyOptional({ description: 'متن دکمه' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
buttonText?: string;
|
||||
|
||||
@ApiPropertyOptional({ description: 'لینک دکمه' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
buttonLink?: string;
|
||||
|
||||
@ApiPropertyOptional({ description: 'ترتیب نمایش' })
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
order?: number;
|
||||
|
||||
@ApiPropertyOptional({ description: 'فعال/غیرفعال' })
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
isActive?: boolean;
|
||||
}
|
||||
|
||||
export class CreateVetTestimonialDto {
|
||||
@ApiProperty({ description: 'نام دامپزشک' })
|
||||
@IsString()
|
||||
vetName: string;
|
||||
|
||||
@ApiPropertyOptional({ description: 'نام کلینیک' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
clinicName?: string;
|
||||
|
||||
@ApiPropertyOptional({ description: 'تصویر دامپزشک' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
imageUrl?: string;
|
||||
|
||||
@ApiProperty({ description: 'متن نظر و تجربه دامپزشک' })
|
||||
@IsString()
|
||||
quote: string;
|
||||
|
||||
@ApiPropertyOptional({ description: 'امتیاز (۱ تا ۵)' })
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
rating?: number;
|
||||
|
||||
@ApiPropertyOptional({ description: 'ترتیب نمایش' })
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
order?: number;
|
||||
|
||||
@ApiPropertyOptional({ description: 'فعال/غیرفعال' })
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
isActive?: boolean;
|
||||
}
|
||||
|
||||
export class CreateSmartAdvisorRuleDto {
|
||||
@ApiProperty({ description: 'شرایط انتخاب (علائم یا حالت بالینی)' })
|
||||
@IsString()
|
||||
condition: string;
|
||||
|
||||
@ApiPropertyOptional({ description: 'نوع پت هدف (سگ/گربه/هر دو)' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
targetPetType?: string;
|
||||
|
||||
@ApiProperty({ description: 'شناسه محصول پیشنهادی' })
|
||||
@IsUUID()
|
||||
recommendedProduct: string;
|
||||
|
||||
@ApiProperty({ description: 'علت و منطق پزشکی تجویز' })
|
||||
@IsString()
|
||||
reason: string;
|
||||
}
|
||||
Reference in new issue
Block a user