feat: complete backend swagger annotations, admin pages pagination, and frontend application fixes
This commit is contained in:
1 parent
24137beb32
commit
2851ef8a25
41 files changed
+478
-128
No files matched your search
@@ -1,9 +1,10 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards, Req, HttpStatus } from '@nestjs/common';
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards, Req, HttpStatus, Query } from '@nestjs/common';
|
||||
import { PetsService } from './pets.service';
|
||||
import { CreatePetDto } from './dto/create-pet.dto';
|
||||
import { UpdatePetDto } from './dto/update-pet.dto';
|
||||
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
||||
import { ApiTags, ApiBearerAuth, ApiOperation, ApiResponse, ApiOkResponse, ApiCreatedResponse, ApiBadRequestResponse, ApiNotFoundResponse } from '@nestjs/swagger';
|
||||
import { PaginationDto } from '../common/dto/pagination.dto';
|
||||
|
||||
@ApiTags('Pets - مدیریت حیوانات خانگی')
|
||||
@ApiBearerAuth()
|
||||
@@ -61,26 +62,34 @@ export class PetsController {
|
||||
@Get()
|
||||
@ApiOperation({ summary: 'لیست حیوانات خانگی کاربر فعلی' })
|
||||
@ApiOkResponse({
|
||||
description: 'آرایهای از حیوانات خانگی ثبت شده کاربر',
|
||||
description: 'آرایهای از حیوانات خانگی ثبت شده کاربر (صفحهبندی شده)',
|
||||
schema: {
|
||||
example: [
|
||||
{
|
||||
id: 'c7b8d9e0-1234-5678-abcd-ef1234567890',
|
||||
userId: 'd8c4e428-cd2f-4c55-bfa3-dfa312bb6480',
|
||||
name: 'بادی',
|
||||
type: 'سگ',
|
||||
breed: 'ژرمن شپرد',
|
||||
age: 3,
|
||||
weight: '25.50',
|
||||
activityLevel: 'متوسط',
|
||||
imageUrl: null,
|
||||
createdAt: '2026-05-26T18:10:00.000Z'
|
||||
example: {
|
||||
data: [
|
||||
{
|
||||
id: 'c7b8d9e0-1234-5678-abcd-ef1234567890',
|
||||
userId: 'd8c4e428-cd2f-4c55-bfa3-dfa312bb6480',
|
||||
name: 'بادی',
|
||||
type: 'سگ',
|
||||
breed: 'ژرمن شپرد',
|
||||
age: 3,
|
||||
weight: '25.50',
|
||||
activityLevel: 'متوسط',
|
||||
imageUrl: null,
|
||||
createdAt: '2026-05-26T18:10:00.000Z'
|
||||
}
|
||||
],
|
||||
meta: {
|
||||
total: 1,
|
||||
page: 1,
|
||||
lastPage: 1,
|
||||
limit: 10
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
})
|
||||
findAll(@Req() req: any) {
|
||||
return this.petsService.findAllByUser(req.user.id);
|
||||
findAll(@Req() req: any, @Query() query: PaginationDto) {
|
||||
return this.petsService.findAllByUser(req.user.id, query);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { PaginationDto } from '../common/dto/pagination.dto';
|
||||
import { CreatePetDto } from './dto/create-pet.dto';
|
||||
import { UpdatePetDto } from './dto/update-pet.dto';
|
||||
|
||||
@@ -27,11 +28,38 @@ export class PetsService {
|
||||
});
|
||||
}
|
||||
|
||||
async findAllByUser(userId: string) {
|
||||
return this.prisma.pet.findMany({
|
||||
where: { userId },
|
||||
orderBy: { createdAt: 'desc' },
|
||||
});
|
||||
async findAllByUser(userId: string, filters: PaginationDto) {
|
||||
const { search, page = 1, limit = 10, sortBy = 'createdAt', sortOrder = 'desc' } = filters;
|
||||
|
||||
const whereClause: any = { userId };
|
||||
if (search) {
|
||||
whereClause.OR = [
|
||||
{ name: { contains: search, mode: 'insensitive' } },
|
||||
{ breed: { contains: search, mode: 'insensitive' } },
|
||||
];
|
||||
}
|
||||
|
||||
const skip = (page - 1) * limit;
|
||||
|
||||
const [data, total] = await Promise.all([
|
||||
this.prisma.pet.findMany({
|
||||
where: whereClause,
|
||||
skip,
|
||||
take: limit,
|
||||
orderBy: { [sortBy]: sortOrder },
|
||||
}),
|
||||
this.prisma.pet.count({ where: whereClause })
|
||||
]);
|
||||
|
||||
return {
|
||||
data,
|
||||
meta: {
|
||||
total,
|
||||
page,
|
||||
lastPage: Math.ceil(total / limit),
|
||||
limit,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
async findOne(id: string, userId: string) {
|
||||
|
||||
Reference in new issue
Block a user