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,13 +1,17 @@
|
||||
import { Controller, Get, UseGuards, Param, Put, Post, Body, Delete, Query } from '@nestjs/common';
|
||||
import { AdminService } from './admin.service';
|
||||
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
||||
import { ApiTags, ApiBearerAuth, ApiOperation, ApiQuery } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('Admin - پنل مدیریت')
|
||||
@ApiBearerAuth()
|
||||
@Controller('admin')
|
||||
export class AdminController {
|
||||
constructor(private readonly adminService: AdminService) {}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('dashboard/stats')
|
||||
@ApiOperation({ summary: 'دریافت آمار کلی داشبورد' })
|
||||
async getDashboardStats() {
|
||||
const stats = await this.adminService.getDashboardStats();
|
||||
return {
|
||||
@@ -18,6 +22,11 @@ export class AdminController {
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('users')
|
||||
@ApiOperation({ summary: 'لیست کاربران' })
|
||||
@ApiQuery({ name: 'page', required: false, description: 'شماره صفحه' })
|
||||
@ApiQuery({ name: 'limit', required: false, description: 'تعداد آیتمها' })
|
||||
@ApiQuery({ name: 'search', required: false, description: 'جستجو در نام یا ایمیل' })
|
||||
@ApiQuery({ name: 'role', required: false, description: 'فیلتر بر اساس نقش کاربر' })
|
||||
async getUsers(
|
||||
@Query('page') page?: string,
|
||||
@Query('limit') limit?: string,
|
||||
@@ -30,6 +39,7 @@ export class AdminController {
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Put('users/:id/role')
|
||||
@ApiOperation({ summary: 'تغییر نقش کاربر' })
|
||||
async updateUserRole(@Param('id') id: string, @Body('role') role: string) {
|
||||
const user = await this.adminService.updateUserRole(id, role);
|
||||
return {
|
||||
@@ -40,6 +50,11 @@ export class AdminController {
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('products')
|
||||
@ApiOperation({ summary: 'لیست محصولات (مدیریت)' })
|
||||
@ApiQuery({ name: 'page', required: false, description: 'شماره صفحه' })
|
||||
@ApiQuery({ name: 'limit', required: false, description: 'تعداد آیتمها' })
|
||||
@ApiQuery({ name: 'search', required: false, description: 'جستجو' })
|
||||
@ApiQuery({ name: 'categoryId', required: false, description: 'شناسه دستهبندی' })
|
||||
async getProducts(
|
||||
@Query('page') page?: string,
|
||||
@Query('limit') limit?: string,
|
||||
@@ -52,6 +67,7 @@ export class AdminController {
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post('products')
|
||||
@ApiOperation({ summary: 'ایجاد محصول جدید' })
|
||||
async createProduct(@Body() data: any) {
|
||||
const product = await this.adminService.createProduct(data);
|
||||
return { success: true, data: product };
|
||||
@@ -59,6 +75,7 @@ export class AdminController {
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Put('products/:id')
|
||||
@ApiOperation({ summary: 'ویرایش محصول' })
|
||||
async updateProduct(@Param('id') id: string, @Body() data: any) {
|
||||
const product = await this.adminService.updateProduct(id, data);
|
||||
return {
|
||||
@@ -69,6 +86,7 @@ export class AdminController {
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Delete('products/:id')
|
||||
@ApiOperation({ summary: 'حذف محصول' })
|
||||
async deleteProduct(@Param('id') id: string) {
|
||||
await this.adminService.deleteProduct(id);
|
||||
return {
|
||||
@@ -79,6 +97,11 @@ export class AdminController {
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('orders')
|
||||
@ApiOperation({ summary: 'لیست سفارشها' })
|
||||
@ApiQuery({ name: 'page', required: false, description: 'شماره صفحه' })
|
||||
@ApiQuery({ name: 'limit', required: false, description: 'تعداد آیتمها' })
|
||||
@ApiQuery({ name: 'search', required: false, description: 'جستجو' })
|
||||
@ApiQuery({ name: 'status', required: false, description: 'وضعیت سفارش' })
|
||||
async getOrders(
|
||||
@Query('page') page?: string,
|
||||
@Query('limit') limit?: string,
|
||||
@@ -91,6 +114,7 @@ export class AdminController {
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Put('orders/:id/status')
|
||||
@ApiOperation({ summary: 'تغییر وضعیت سفارش' })
|
||||
async updateOrderStatus(@Param('id') id: string, @Body('status') status: string) {
|
||||
const order = await this.adminService.updateOrderStatus(id, status);
|
||||
return {
|
||||
@@ -102,6 +126,10 @@ export class AdminController {
|
||||
// --- Coupons ---
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('coupons')
|
||||
@ApiOperation({ summary: 'لیست کد تخفیفها' })
|
||||
@ApiQuery({ name: 'page', required: false, description: 'شماره صفحه' })
|
||||
@ApiQuery({ name: 'limit', required: false, description: 'تعداد آیتمها' })
|
||||
@ApiQuery({ name: 'search', required: false, description: 'جستجو' })
|
||||
async getCoupons(@Query() query: any) {
|
||||
const coupons = await this.adminService.getCoupons(query);
|
||||
return { success: true, ...coupons };
|
||||
@@ -109,6 +137,7 @@ export class AdminController {
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post('coupons')
|
||||
@ApiOperation({ summary: 'ایجاد کد تخفیف جدید' })
|
||||
async createCoupon(@Body() data: any) {
|
||||
const coupon = await this.adminService.createCoupon(data);
|
||||
return { success: true, data: coupon };
|
||||
@@ -116,6 +145,7 @@ export class AdminController {
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Put('coupons/:id')
|
||||
@ApiOperation({ summary: 'ویرایش کد تخفیف' })
|
||||
async updateCoupon(@Param('id') id: string, @Body() data: any) {
|
||||
const coupon = await this.adminService.updateCoupon(id, data);
|
||||
return { success: true, data: coupon };
|
||||
@@ -123,6 +153,7 @@ export class AdminController {
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Put('coupons/:id/toggle')
|
||||
@ApiOperation({ summary: 'فعال/غیرفعال کردن کد تخفیف' })
|
||||
async toggleCoupon(@Param('id') id: string, @Body('isActive') isActive: boolean) {
|
||||
const coupon = await this.adminService.toggleCoupon(id, isActive);
|
||||
return { success: true, data: coupon };
|
||||
@@ -130,6 +161,7 @@ export class AdminController {
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Delete('coupons/:id')
|
||||
@ApiOperation({ summary: 'حذف کد تخفیف' })
|
||||
async deleteCoupon(@Param('id') id: string) {
|
||||
await this.adminService.deleteCoupon(id);
|
||||
return { success: true };
|
||||
@@ -138,6 +170,7 @@ export class AdminController {
|
||||
// --- Settings ---
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('settings')
|
||||
@ApiOperation({ summary: 'دریافت تنظیمات' })
|
||||
async getSettings() {
|
||||
const settings = await this.adminService.getSettings();
|
||||
return { success: true, data: settings };
|
||||
@@ -145,6 +178,7 @@ export class AdminController {
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Put('settings')
|
||||
@ApiOperation({ summary: 'ذخیره تنظیمات' })
|
||||
async updateSettings(@Body() data: Record<string, string>) {
|
||||
const settings = await this.adminService.updateSettings(data);
|
||||
return { success: true, data: settings };
|
||||
|
||||
@@ -57,7 +57,7 @@ export class AdminService {
|
||||
this.prisma.user.count({ where })
|
||||
]);
|
||||
|
||||
return { data, meta: { total, page, limit, totalPages: Math.ceil(total / limit) } };
|
||||
return { data, meta: { total, page, limit, lastPage: Math.ceil(total / limit) } };
|
||||
}
|
||||
|
||||
async updateUserRole(id: string, role: string) {
|
||||
@@ -92,7 +92,7 @@ export class AdminService {
|
||||
this.prisma.product.count({ where })
|
||||
]);
|
||||
|
||||
return { data, meta: { total, page, limit, totalPages: Math.ceil(total / limit) } };
|
||||
return { data, meta: { total, page, limit, lastPage: Math.ceil(total / limit) } };
|
||||
} catch (error) {
|
||||
console.error("[AdminService] getProducts error:", error);
|
||||
throw new HttpException(error.message || 'Error fetching products', 500);
|
||||
@@ -179,7 +179,7 @@ export class AdminService {
|
||||
this.prisma.order.count({ where })
|
||||
]);
|
||||
|
||||
return { data, meta: { total, page, limit, totalPages: Math.ceil(total / limit) } };
|
||||
return { data, meta: { total, page, limit, lastPage: Math.ceil(total / limit) } };
|
||||
}
|
||||
|
||||
async updateOrderStatus(id: string, status: string) {
|
||||
@@ -209,7 +209,7 @@ export class AdminService {
|
||||
|
||||
return {
|
||||
data,
|
||||
meta: { total, page: Number(page), limit: Number(limit), totalPages: Math.ceil(total / Number(limit)) }
|
||||
meta: { total, page: Number(page), limit: Number(limit), lastPage: Math.ceil(total / Number(limit)) }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,30 +1,40 @@
|
||||
import { Controller, Get, Post, Put, Delete, Body, Param, Query, UseGuards, Request } from '@nestjs/common';
|
||||
import { BlogsService } from './blogs.service';
|
||||
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
||||
import { ApiTags, ApiBearerAuth, ApiOperation, ApiQuery } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('Admin - مدیریت مقالات (بلاگ)')
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Controller('admin/blogs')
|
||||
export class BlogsController {
|
||||
constructor(private readonly blogsService: BlogsService) {}
|
||||
|
||||
@Get()
|
||||
@ApiOperation({ summary: 'لیست مقالات' })
|
||||
@ApiQuery({ name: 'page', required: false, description: 'شماره صفحه' })
|
||||
@ApiQuery({ name: 'limit', required: false, description: 'تعداد آیتمها' })
|
||||
@ApiQuery({ name: 'search', required: false, description: 'جستجو' })
|
||||
async getBlogs(@Query() query: any) {
|
||||
return this.blogsService.getBlogs(query);
|
||||
}
|
||||
|
||||
@Post()
|
||||
@ApiOperation({ summary: 'ایجاد مقاله جدید' })
|
||||
async createBlog(@Body() body: any, @Request() req: any) {
|
||||
const data = await this.blogsService.createBlog(body, req.user.id);
|
||||
return { success: true, data };
|
||||
}
|
||||
|
||||
@Put(':id')
|
||||
@ApiOperation({ summary: 'ویرایش مقاله' })
|
||||
async updateBlog(@Param('id') id: string, @Body() body: any) {
|
||||
const data = await this.blogsService.updateBlog(id, body);
|
||||
return { success: true, data };
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@ApiOperation({ summary: 'حذف مقاله' })
|
||||
async deleteBlog(@Param('id') id: string) {
|
||||
await this.blogsService.deleteBlog(id);
|
||||
return { success: true };
|
||||
|
||||
@@ -24,7 +24,7 @@ export class BlogsService {
|
||||
|
||||
return {
|
||||
data,
|
||||
meta: { total, page: Number(page), limit: Number(limit), totalPages: Math.ceil(total / Number(limit)) }
|
||||
meta: { total, page: Number(page), limit: Number(limit), lastPage: Math.ceil(total / Number(limit)) }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,36 +1,47 @@
|
||||
import { Controller, Get, Post, Put, Delete, Body, Param, Query, UseGuards } from '@nestjs/common';
|
||||
import { CategoriesService } from './categories.service';
|
||||
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
||||
import { ApiTags, ApiBearerAuth, ApiOperation, ApiQuery } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('Admin - مدیریت دستهبندیها')
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Controller('admin/categories')
|
||||
export class CategoriesController {
|
||||
constructor(private readonly categoriesService: CategoriesService) {}
|
||||
|
||||
@Get()
|
||||
@ApiOperation({ summary: 'لیست دستهبندیها (با صفحهبندی)' })
|
||||
@ApiQuery({ name: 'page', required: false, description: 'شماره صفحه' })
|
||||
@ApiQuery({ name: 'limit', required: false, description: 'تعداد آیتمها' })
|
||||
@ApiQuery({ name: 'search', required: false, description: 'جستجو در نام' })
|
||||
async getCategories(@Query() query: any) {
|
||||
return this.categoriesService.getCategories(query);
|
||||
}
|
||||
|
||||
@Get('all')
|
||||
@ApiOperation({ summary: 'لیست تمام دستهبندیها (بدون صفحهبندی)' })
|
||||
async getAllCategoriesRaw() {
|
||||
const data = await this.categoriesService.getAllCategoriesRaw();
|
||||
return { success: true, data };
|
||||
}
|
||||
|
||||
@Post()
|
||||
@ApiOperation({ summary: 'ایجاد دستهبندی جدید' })
|
||||
async createCategory(@Body() body: any) {
|
||||
const data = await this.categoriesService.createCategory(body);
|
||||
return { success: true, data };
|
||||
}
|
||||
|
||||
@Put(':id')
|
||||
@ApiOperation({ summary: 'ویرایش دستهبندی' })
|
||||
async updateCategory(@Param('id') id: string, @Body() body: any) {
|
||||
const data = await this.categoriesService.updateCategory(id, body);
|
||||
return { success: true, data };
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@ApiOperation({ summary: 'حذف دستهبندی' })
|
||||
async deleteCategory(@Param('id') id: string) {
|
||||
await this.categoriesService.deleteCategory(id);
|
||||
return { success: true };
|
||||
|
||||
@@ -23,7 +23,7 @@ export class CategoriesService {
|
||||
|
||||
return {
|
||||
data,
|
||||
meta: { total, page: Number(page), limit: Number(limit), totalPages: Math.ceil(total / Number(limit)) }
|
||||
meta: { total, page: Number(page), limit: Number(limit), lastPage: Math.ceil(total / Number(limit)) }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -2,13 +2,17 @@ import { Controller, Get, Post, Delete, Param, UseGuards, UseInterceptors, Uploa
|
||||
import { FileInterceptor } from '@nestjs/platform-express';
|
||||
import { MediaService } from './media.service';
|
||||
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
||||
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('Admin - مدیریت رسانه (تصاویر)')
|
||||
@ApiBearerAuth()
|
||||
@Controller('admin/media')
|
||||
export class MediaController {
|
||||
constructor(private readonly mediaService: MediaService) {}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get()
|
||||
@ApiOperation({ summary: 'لیست فایلهای رسانه' })
|
||||
async getAllMedia() {
|
||||
const data = await this.mediaService.getAllMedia();
|
||||
return { success: true, data };
|
||||
@@ -16,6 +20,7 @@ export class MediaController {
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post('upload')
|
||||
@ApiOperation({ summary: 'آپلود فایل جدید' })
|
||||
@UseInterceptors(FileInterceptor('file'))
|
||||
async uploadFile(@UploadedFile() file: Express.Multer.File) {
|
||||
if (!file) throw new BadRequestException('File is missing');
|
||||
@@ -25,6 +30,7 @@ export class MediaController {
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Delete(':id')
|
||||
@ApiOperation({ summary: 'حذف فایل' })
|
||||
async deleteMedia(@Param('id') id: string) {
|
||||
const data = await this.mediaService.deleteMedia(id);
|
||||
return { success: true, data };
|
||||
|
||||
@@ -1,18 +1,26 @@
|
||||
import { Controller, Get, Delete, Param, Query, UseGuards } from '@nestjs/common';
|
||||
import { PetsService } from './pets.service';
|
||||
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
||||
import { ApiTags, ApiBearerAuth, ApiOperation, ApiQuery } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('Admin - مدیریت حیوانات خانگی')
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Controller('admin/pets')
|
||||
export class PetsController {
|
||||
constructor(private readonly petsService: PetsService) {}
|
||||
|
||||
@Get()
|
||||
@ApiOperation({ summary: 'لیست حیوانات خانگی' })
|
||||
@ApiQuery({ name: 'page', required: false, description: 'شماره صفحه' })
|
||||
@ApiQuery({ name: 'limit', required: false, description: 'تعداد آیتمها' })
|
||||
@ApiQuery({ name: 'search', required: false, description: 'جستجو' })
|
||||
async getPets(@Query() query: any) {
|
||||
return this.petsService.getPets(query);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@ApiOperation({ summary: 'حذف حیوان خانگی' })
|
||||
async deletePet(@Param('id') id: string) {
|
||||
await this.petsService.deletePet(id);
|
||||
return { success: true };
|
||||
|
||||
@@ -24,7 +24,7 @@ export class PetsService {
|
||||
|
||||
return {
|
||||
data,
|
||||
meta: { total, page: Number(page), limit: Number(limit), totalPages: Math.ceil(total / Number(limit)) }
|
||||
meta: { total, page: Number(page), limit: Number(limit), lastPage: Math.ceil(total / Number(limit)) }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
import { Controller, Get, UseGuards } from '@nestjs/common';
|
||||
import { ReportsService } from './reports.service';
|
||||
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
||||
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('Admin - گزارشات')
|
||||
@ApiBearerAuth()
|
||||
@Controller('admin/reports')
|
||||
export class ReportsController {
|
||||
constructor(private readonly reportsService: ReportsService) {}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get()
|
||||
@ApiOperation({ summary: 'دریافت گزارشات داشبورد' })
|
||||
async getReports() {
|
||||
const data = await this.reportsService.getDashboardReports();
|
||||
return { success: true, data };
|
||||
|
||||
@@ -1,30 +1,40 @@
|
||||
import { Controller, Get, Post, Put, Delete, Body, Param, Query, UseGuards } from '@nestjs/common';
|
||||
import { WikiService } from './wiki.service';
|
||||
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
||||
import { ApiTags, ApiBearerAuth, ApiOperation, ApiQuery } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('Admin - مدیریت دانشنامه (اصطلاحات علمی)')
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Controller('admin/wiki')
|
||||
export class WikiController {
|
||||
constructor(private readonly wikiService: WikiService) {}
|
||||
|
||||
@Get()
|
||||
@ApiOperation({ summary: 'لیست اصطلاحات دانشنامه' })
|
||||
@ApiQuery({ name: 'page', required: false, description: 'شماره صفحه' })
|
||||
@ApiQuery({ name: 'limit', required: false, description: 'تعداد آیتمها' })
|
||||
@ApiQuery({ name: 'search', required: false, description: 'جستجو' })
|
||||
async getTerms(@Query() query: any) {
|
||||
return this.wikiService.getTerms(query);
|
||||
}
|
||||
|
||||
@Post()
|
||||
@ApiOperation({ summary: 'ایجاد اصطلاح جدید' })
|
||||
async createTerm(@Body() body: any) {
|
||||
const data = await this.wikiService.createTerm(body);
|
||||
return { success: true, data };
|
||||
}
|
||||
|
||||
@Put(':key')
|
||||
@ApiOperation({ summary: 'ویرایش اصطلاح' })
|
||||
async updateTerm(@Param('key') key: string, @Body() body: any) {
|
||||
const data = await this.wikiService.updateTerm(key, body);
|
||||
return { success: true, data };
|
||||
}
|
||||
|
||||
@Delete(':key')
|
||||
@ApiOperation({ summary: 'حذف اصطلاح' })
|
||||
async deleteTerm(@Param('key') key: string) {
|
||||
await this.wikiService.deleteTerm(key);
|
||||
return { success: true };
|
||||
|
||||
@@ -23,7 +23,7 @@ export class WikiService {
|
||||
|
||||
return {
|
||||
data,
|
||||
meta: { total, page: Number(page), limit: Number(limit), totalPages: Math.ceil(total / Number(limit)) }
|
||||
meta: { total, page: Number(page), limit: Number(limit), lastPage: Math.ceil(total / Number(limit)) }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user