feat: implement advanced reports, pagination for all tables, global settings, and discounts modules

This commit is contained in:
parsa committed 2026-06-12 16:28:06 +03:30
1 parent a7ebb8d792
commit 69502fc380
14 files changed
+1042 -71

No files matched your search

+69 -19
View File
@@ -1,4 +1,4 @@
import { Controller, Get, UseGuards, Param, Put, Body } from '@nestjs/common';
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';
@@ -18,12 +18,14 @@ export class AdminController {
@UseGuards(JwtAuthGuard)
@Get('users')
async getUsers() {
const users = await this.adminService.getUsers();
return {
success: true,
data: users
};
async getUsers(
@Query('page') page?: string,
@Query('limit') limit?: string,
@Query('search') search?: string,
@Query('role') role?: string
) {
const data = await this.adminService.getUsers({ page, limit, search, role });
return { success: true, ...data };
}
@UseGuards(JwtAuthGuard)
@@ -38,12 +40,14 @@ export class AdminController {
@UseGuards(JwtAuthGuard)
@Get('products')
async getProducts() {
const products = await this.adminService.getProducts();
return {
success: true,
data: products
};
async getProducts(
@Query('page') page?: string,
@Query('limit') limit?: string,
@Query('search') search?: string,
@Query('category') category?: string
) {
const data = await this.adminService.getProducts({ page, limit, search, category });
return { success: true, ...data };
}
@UseGuards(JwtAuthGuard)
@@ -68,12 +72,14 @@ export class AdminController {
@UseGuards(JwtAuthGuard)
@Get('orders')
async getOrders() {
const orders = await this.adminService.getOrders();
return {
success: true,
data: orders
};
async getOrders(
@Query('page') page?: string,
@Query('limit') limit?: string,
@Query('search') search?: string,
@Query('status') status?: string
) {
const data = await this.adminService.getOrders({ page, limit, search, status });
return { success: true, ...data };
}
@UseGuards(JwtAuthGuard)
@@ -85,4 +91,48 @@ export class AdminController {
data: order
};
}
// --- Coupons ---
@UseGuards(JwtAuthGuard)
@Get('coupons')
async getCoupons() {
const coupons = await this.adminService.getCoupons();
return { success: true, data: coupons };
}
@UseGuards(JwtAuthGuard)
@Post('coupons')
async createCoupon(@Body() data: { code: string; discountValue: number }) {
const coupon = await this.adminService.createCoupon(data);
return { success: true, data: coupon };
}
@UseGuards(JwtAuthGuard)
@Put('coupons/:id/toggle')
async toggleCoupon(@Param('id') id: string, @Body('isActive') isActive: boolean) {
const coupon = await this.adminService.toggleCoupon(id, isActive);
return { success: true, data: coupon };
}
@UseGuards(JwtAuthGuard)
@Delete('coupons/:id')
async deleteCoupon(@Param('id') id: string) {
await this.adminService.deleteCoupon(id);
return { success: true };
}
// --- Settings ---
@UseGuards(JwtAuthGuard)
@Get('settings')
async getSettings() {
const settings = await this.adminService.getSettings();
return { success: true, data: settings };
}
@UseGuards(JwtAuthGuard)
@Put('settings')
async updateSettings(@Body() data: Record<string, string>) {
const settings = await this.adminService.updateSettings(data);
return { success: true, data: settings };
}
}