246 lines
7.7 KiB
TypeScript
246 lines
7.7 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
Put,
|
|
Delete,
|
|
Body,
|
|
Param,
|
|
Query,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import {
|
|
AdminService,
|
|
PaginationQuery,
|
|
ProductInput,
|
|
CouponInput,
|
|
} from './admin.service';
|
|
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
|
import {
|
|
ApiTags,
|
|
ApiBearerAuth,
|
|
ApiOperation,
|
|
ApiQuery,
|
|
} from '@nestjs/swagger';
|
|
|
|
@ApiTags('Admin - مدیریت سیستم')
|
|
@ApiBearerAuth()
|
|
@UseGuards(JwtAuthGuard)
|
|
@Controller('admin')
|
|
export class AdminController {
|
|
constructor(private readonly adminService: AdminService) {}
|
|
|
|
@Get('dashboard/stats')
|
|
@ApiOperation({ summary: 'داشبورد مدیریت و آمار کلیدی سیستم' })
|
|
async getDashboardStats() {
|
|
const data = await this.adminService.getDashboardStats();
|
|
return { success: true, data };
|
|
}
|
|
|
|
@Get('users')
|
|
@ApiOperation({ summary: 'لیست کاربران سیستم (با صفحهبندی)' })
|
|
@ApiQuery({ name: 'page', required: false, description: 'شماره صفحه' })
|
|
@ApiQuery({ name: 'limit', required: false, description: 'تعداد آیتمها' })
|
|
@ApiQuery({ name: 'search', required: false, description: 'جستجو' })
|
|
async getUsers(@Query() query: PaginationQuery) {
|
|
const result = await this.adminService.getUsers(query);
|
|
return { success: true, ...result };
|
|
}
|
|
|
|
@Get('users/:id')
|
|
@ApiOperation({ summary: 'جزئیات کاربر' })
|
|
async getUserDetails(@Param('id') id: string) {
|
|
const data = await this.adminService.getUserDetails(id);
|
|
return { success: true, data };
|
|
}
|
|
|
|
@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 { success: true, data: user };
|
|
}
|
|
|
|
@Post('users/:id/wallet-adjust')
|
|
@ApiOperation({ summary: 'شارژ یا کسر مستقیم کیف پول کاربر توسط ادمین' })
|
|
async adjustWallet(
|
|
@Param('id') id: string,
|
|
@Body('amount') amount: number,
|
|
@Body('type') type: 'deposit' | 'withdrawal' | 'refund',
|
|
@Body('description') description?: string,
|
|
) {
|
|
const result = await this.adminService.adjustUserWallet(
|
|
id,
|
|
Number(amount),
|
|
type,
|
|
description,
|
|
);
|
|
return {
|
|
success: true,
|
|
message: 'موجود کیف پول با موفقیت بروزرسانی شد',
|
|
data: result,
|
|
};
|
|
}
|
|
|
|
@Get('products')
|
|
@ApiOperation({ summary: 'لیست محصولات (مدیریت)' })
|
|
@ApiQuery({ name: 'page', required: false, description: 'شماره صفحه' })
|
|
@ApiQuery({ name: 'limit', required: false, description: 'تعداد آیتمها' })
|
|
@ApiQuery({ name: 'search', required: false, description: 'جستجو' })
|
|
async getProducts(@Query() query: PaginationQuery) {
|
|
const result = await this.adminService.getProducts(query);
|
|
return { success: true, ...result };
|
|
}
|
|
|
|
@Post('products')
|
|
@ApiOperation({ summary: 'ایجاد محصول جدید' })
|
|
async createProduct(@Body() data: ProductInput) {
|
|
const product = await this.adminService.createProduct(data);
|
|
return { success: true, data: product };
|
|
}
|
|
|
|
@Put('products/:id')
|
|
@ApiOperation({ summary: 'ویرایش محصول' })
|
|
async updateProduct(@Param('id') id: string, @Body() data: ProductInput) {
|
|
const product = await this.adminService.updateProduct(id, data);
|
|
return {
|
|
success: true,
|
|
data: product,
|
|
};
|
|
}
|
|
|
|
@Delete('products/:id')
|
|
@ApiOperation({ summary: 'حذف محصول' })
|
|
async deleteProduct(@Param('id') id: string) {
|
|
await this.adminService.deleteProduct(id);
|
|
return { success: true };
|
|
}
|
|
|
|
@Get('orders')
|
|
@ApiOperation({ summary: 'لیست سفارشها (مدیریت)' })
|
|
@ApiQuery({ name: 'page', required: false, description: 'شماره صفحه' })
|
|
@ApiQuery({ name: 'limit', required: false, description: 'تعداد آیتمها' })
|
|
@ApiQuery({ name: 'status', required: false, description: 'فیلتر وضعیت' })
|
|
async getOrders(@Query() query: PaginationQuery) {
|
|
const result = await this.adminService.getOrders(query);
|
|
return { success: true, ...result };
|
|
}
|
|
|
|
@Put('orders/:id/status')
|
|
@ApiOperation({ summary: 'بروزرسانی وضعیت سفارش' })
|
|
async updateOrderStatus(
|
|
@Param('id') id: string,
|
|
@Body('status') status: string,
|
|
@Body('trackingCode') trackingCode?: string,
|
|
) {
|
|
const order = await this.adminService.updateOrderStatus(
|
|
id,
|
|
status,
|
|
trackingCode,
|
|
);
|
|
return { success: true, data: order };
|
|
}
|
|
|
|
@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: PaginationQuery) {
|
|
const coupons = await this.adminService.getCoupons(query);
|
|
return { success: true, ...coupons };
|
|
}
|
|
|
|
@Post('coupons')
|
|
@ApiOperation({ summary: 'ایجاد کد تخفیف جدید' })
|
|
async createCoupon(@Body() data: CouponInput) {
|
|
const coupon = await this.adminService.createCoupon(data);
|
|
return { success: true, data: coupon };
|
|
}
|
|
|
|
@Put('coupons/:id')
|
|
@ApiOperation({ summary: 'ویرایش کد تخفیف' })
|
|
async updateCoupon(@Param('id') id: string, @Body() data: CouponInput) {
|
|
const coupon = await this.adminService.updateCoupon(id, data);
|
|
return { success: true, data: coupon };
|
|
}
|
|
|
|
@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 };
|
|
}
|
|
|
|
@Delete('coupons/:id')
|
|
@ApiOperation({ summary: 'حذف کد تخفیف' })
|
|
async deleteCoupon(@Param('id') id: string) {
|
|
await this.adminService.deleteCoupon(id);
|
|
return { success: true };
|
|
}
|
|
|
|
@Get('doctors')
|
|
@ApiOperation({ summary: 'لیست پزشکان و متخصصین' })
|
|
async getDoctors() {
|
|
const data = await this.adminService.getDoctors();
|
|
return { success: true, data };
|
|
}
|
|
|
|
@Post('doctors')
|
|
@ApiOperation({ summary: 'افزودن پزشک جدید' })
|
|
async createDoctor(
|
|
@Body()
|
|
body: {
|
|
name: string;
|
|
title: string;
|
|
avatarUrl?: string;
|
|
bio?: string;
|
|
clinic?: string;
|
|
},
|
|
) {
|
|
const data = await this.adminService.createDoctor(body);
|
|
return { success: true, data };
|
|
}
|
|
|
|
@Put('doctors/:id')
|
|
@ApiOperation({ summary: 'ویرایش پزشک' })
|
|
async updateDoctor(
|
|
@Param('id') id: string,
|
|
@Body()
|
|
body: {
|
|
name?: string;
|
|
title?: string;
|
|
avatarUrl?: string;
|
|
bio?: string;
|
|
clinic?: string;
|
|
},
|
|
) {
|
|
const data = await this.adminService.updateDoctor(id, body);
|
|
return { success: true, data };
|
|
}
|
|
|
|
@Delete('doctors/:id')
|
|
@ApiOperation({ summary: 'حذف پزشک' })
|
|
async deleteDoctor(@Param('id') id: string) {
|
|
await this.adminService.deleteDoctor(id);
|
|
return { success: true };
|
|
}
|
|
|
|
@Get('settings')
|
|
@ApiOperation({ summary: 'دریافت تنظیمات کلی سیستم' })
|
|
async getSettings() {
|
|
const data = await this.adminService.getSettings();
|
|
return { success: true, data };
|
|
}
|
|
|
|
@Put('settings')
|
|
@ApiOperation({ summary: 'بروزرسانی تنظیمات کلی سیستم' })
|
|
async updateSettings(@Body() body: Record<string, string>) {
|
|
const data = await this.adminService.updateSettings(body);
|
|
return { success: true, data };
|
|
}
|
|
}
|