feat(backend): implement Phase A database models and controllers for cross-boundary dependencies
Deploy Canina / deploy (push) Failing after 28s
Deploy Canina / deploy (push) Failing after 28s
This commit is contained in:
1 parent
74fcaa6a4e
commit
1ae4c99ffc
26 files changed
+1205
-345
No files matched your search
@@ -0,0 +1,54 @@
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Patch,
|
||||
Delete,
|
||||
Body,
|
||||
Param,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { TestimonialsService } from './testimonials.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('Testimonials - نظرات و رضایتنامهها')
|
||||
@Controller('testimonials')
|
||||
export class TestimonialsController {
|
||||
constructor(private readonly testimonialsService: TestimonialsService) {}
|
||||
|
||||
@Get()
|
||||
@ApiOperation({ summary: 'دریافت لیست نظرات و رضایتنامهها' })
|
||||
findAll() {
|
||||
return this.testimonialsService.findAll();
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles('Admin')
|
||||
@ApiBearerAuth()
|
||||
@Post()
|
||||
@ApiOperation({ summary: 'ایجاد نظر جدید (نیازمند ادمین)' })
|
||||
create(@Body() body: any) {
|
||||
return this.testimonialsService.create(body);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles('Admin')
|
||||
@ApiBearerAuth()
|
||||
@Patch(':id')
|
||||
@ApiOperation({ summary: 'ویرایش نظر (نیازمند ادمین)' })
|
||||
update(@Param('id') id: string, @Body() body: any) {
|
||||
return this.testimonialsService.update(id, body);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles('Admin')
|
||||
@ApiBearerAuth()
|
||||
@Delete(':id')
|
||||
@ApiOperation({ summary: 'حذف نظر (نیازمند ادمین)' })
|
||||
remove(@Param('id') id: string) {
|
||||
return this.testimonialsService.remove(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TestimonialsController } from './testimonials.controller';
|
||||
import { TestimonialsService } from './testimonials.service';
|
||||
import { PrismaModule } from '../prisma/prisma.module';
|
||||
|
||||
@Module({
|
||||
imports: [PrismaModule],
|
||||
controllers: [TestimonialsController],
|
||||
providers: [TestimonialsService],
|
||||
exports: [TestimonialsService],
|
||||
})
|
||||
export class TestimonialsModule {}
|
||||
@@ -0,0 +1,39 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { Prisma } from '@prisma/client';
|
||||
|
||||
@Injectable()
|
||||
export class TestimonialsService {
|
||||
constructor(private prisma: PrismaService) {}
|
||||
|
||||
async findAll() {
|
||||
return this.prisma.testimonial.findMany({
|
||||
orderBy: { order: 'asc' },
|
||||
});
|
||||
}
|
||||
|
||||
async create(data: Prisma.TestimonialCreateInput) {
|
||||
return this.prisma.testimonial.create({
|
||||
data,
|
||||
});
|
||||
}
|
||||
|
||||
async update(id: string, data: Prisma.TestimonialUpdateInput) {
|
||||
const item = await this.prisma.testimonial.findUnique({ where: { id } });
|
||||
if (!item) {
|
||||
throw new NotFoundException(`Testimonial with ID ${id} not found`);
|
||||
}
|
||||
return this.prisma.testimonial.update({
|
||||
where: { id },
|
||||
data,
|
||||
});
|
||||
}
|
||||
|
||||
async remove(id: string) {
|
||||
const item = await this.prisma.testimonial.findUnique({ where: { id } });
|
||||
if (!item) {
|
||||
throw new NotFoundException(`Testimonial with ID ${id} not found`);
|
||||
}
|
||||
return this.prisma.testimonial.delete({ where: { id } });
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user