Spaces:
Running
Running
| import { | |
| Controller, | |
| Post, | |
| Get, | |
| Put, | |
| Delete, | |
| Param, | |
| Body, | |
| UseGuards, | |
| Query, | |
| } from '@nestjs/common'; | |
| import { AdminService } from './admin.service'; | |
| import { CreateCourseDto } from './dto/create-course.dto'; | |
| import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard'; | |
| import { RolesGuard } from '../auth/guards/roles.guard'; | |
| import { Roles } from '../auth/decorators/roles.decorator'; | |
| import { UserRole } from '../entities/user.entity'; | |
| ('api/admin') | |
| (JwtAuthGuard, RolesGuard) | |
| (UserRole.ADMIN) | |
| export class AdminController { | |
| constructor(private readonly adminService: AdminService) {} | |
| ('courses') | |
| async createCourse(() createCourseDto: CreateCourseDto) { | |
| const data = await this.adminService.createCourse(createCourseDto); | |
| return { success: true, data }; | |
| } | |
| ('courses/:id') | |
| async updateCourse( | |
| ('id') id: string, | |
| () updateData: Partial<CreateCourseDto>, | |
| ) { | |
| const data = await this.adminService.updateCourse(Number(id), updateData); | |
| return { success: true, data }; | |
| } | |
| ('courses/:id') | |
| async deleteCourse(('id') id: string) { | |
| await this.adminService.deleteCourse(Number(id)); | |
| return { success: true }; | |
| } | |
| ('orders') | |
| async getOrders() { | |
| const data = await this.adminService.getOrders(); | |
| return { success: true, data }; | |
| } | |
| ('statistics') | |
| async getStatistics( | |
| ('startDate') startDate?: string, | |
| ('endDate') endDate?: string, | |
| ) { | |
| const data = await this.adminService.getStatistics(startDate, endDate); | |
| return { success: true, data }; | |
| } | |
| ('statistics/details') | |
| async getStatisticsDetails( | |
| ('type') type: string, | |
| ('startDate') startDate?: string, | |
| ('endDate') endDate?: string, | |
| ) { | |
| const data = await this.adminService.getStatisticsDetails(type, startDate, endDate); | |
| return { success: true, data }; | |
| } | |
| } | |