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,8 +1,9 @@
|
||||
import { Controller, Get, Post, Body, Param, UseGuards, Req, HttpStatus } from '@nestjs/common';
|
||||
import { Controller, Get, Post, Body, Param, UseGuards, Req, HttpStatus, Query } from '@nestjs/common';
|
||||
import { OrdersService } from './orders.service';
|
||||
import { CreateOrderDto } from './dto/create-order.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('Orders - مدیریت سفارشها')
|
||||
@ApiBearerAuth()
|
||||
@@ -58,22 +59,30 @@ export class OrdersController {
|
||||
@Get()
|
||||
@ApiOperation({ summary: 'لیست سفارشهای کاربر فعلی' })
|
||||
@ApiOkResponse({
|
||||
description: 'آرایهای از سفارشهای ثبت شده کاربر',
|
||||
description: 'آرایهای از سفارشهای ثبت شده کاربر (صفحهبندی شده)',
|
||||
schema: {
|
||||
example: [
|
||||
{
|
||||
id: 'e1d2c3b4-1234-5678-abcd-ef1234567890',
|
||||
userId: 'd8c4e428-cd2f-4c55-bfa3-dfa312bb6480',
|
||||
totalAmount: '3500000.00',
|
||||
charityDonation: '10000.00',
|
||||
status: 'processing',
|
||||
createdAt: '2026-05-26T18:10:00.000Z'
|
||||
example: {
|
||||
data: [
|
||||
{
|
||||
id: 'e1d2c3b4-1234-5678-abcd-ef1234567890',
|
||||
userId: 'd8c4e428-cd2f-4c55-bfa3-dfa312bb6480',
|
||||
totalAmount: '3500000.00',
|
||||
charityDonation: '10000.00',
|
||||
status: 'processing',
|
||||
createdAt: '2026-05-26T18:10:00.000Z'
|
||||
}
|
||||
],
|
||||
meta: {
|
||||
total: 1,
|
||||
page: 1,
|
||||
lastPage: 1,
|
||||
limit: 10
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
})
|
||||
findAll(@Req() req: any) {
|
||||
return this.ordersService.findAllByUser(req.user.id);
|
||||
findAll(@Req() req: any, @Query() query: PaginationDto) {
|
||||
return this.ordersService.findAllByUser(req.user.id, query);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Injectable, NotFoundException, BadRequestException } from '@nestjs/common';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { PaginationDto } from '../common/dto/pagination.dto';
|
||||
import { CreateOrderDto } from './dto/create-order.dto';
|
||||
|
||||
@Injectable()
|
||||
@@ -43,14 +44,32 @@ export class OrdersService {
|
||||
});
|
||||
}
|
||||
|
||||
async findAllByUser(userId: string) {
|
||||
return this.prisma.order.findMany({
|
||||
where: { userId },
|
||||
include: {
|
||||
orderItems: { include: { product: true } },
|
||||
},
|
||||
orderBy: { createdAt: 'desc' },
|
||||
});
|
||||
async findAllByUser(userId: string, filters: PaginationDto) {
|
||||
const { page = 1, limit = 10, sortBy = 'createdAt', sortOrder = 'desc' } = filters;
|
||||
const skip = (page - 1) * limit;
|
||||
|
||||
const [data, total] = await Promise.all([
|
||||
this.prisma.order.findMany({
|
||||
where: { userId },
|
||||
skip,
|
||||
take: limit,
|
||||
orderBy: { [sortBy]: sortOrder },
|
||||
include: {
|
||||
orderItems: { include: { product: true } },
|
||||
},
|
||||
}),
|
||||
this.prisma.order.count({ where: { userId } })
|
||||
]);
|
||||
|
||||
return {
|
||||
data,
|
||||
meta: {
|
||||
total,
|
||||
page,
|
||||
lastPage: Math.ceil(total / limit),
|
||||
limit,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
async findOne(id: string, userId: string) {
|
||||
|
||||
Reference in new issue
Block a user