Spaces:
Sleeping
Sleeping
File size: 1,943 Bytes
8268e91 f45e448 8268e91 426f2a4 8268e91 73746a8 8268e91 73746a8 f45e448 73746a8 426f2a4 73746a8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | 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';
@Controller('api/admin')
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles(UserRole.ADMIN)
export class AdminController {
constructor(private readonly adminService: AdminService) {}
@Post('courses')
async createCourse(@Body() createCourseDto: CreateCourseDto) {
const data = await this.adminService.createCourse(createCourseDto);
return { success: true, data };
}
@Put('courses/:id')
async updateCourse(
@Param('id') id: string,
@Body() updateData: Partial<CreateCourseDto>,
) {
const data = await this.adminService.updateCourse(Number(id), updateData);
return { success: true, data };
}
@Delete('courses/:id')
async deleteCourse(@Param('id') id: string) {
await this.adminService.deleteCourse(Number(id));
return { success: true };
}
@Get('orders')
async getOrders() {
const data = await this.adminService.getOrders();
return { success: true, data };
}
@Get('statistics')
async getStatistics(
@Query('startDate') startDate?: string,
@Query('endDate') endDate?: string,
) {
const data = await this.adminService.getStatistics(startDate, endDate);
return { success: true, data };
}
@Get('statistics/details')
async getStatisticsDetails(
@Query('type') type: string,
@Query('startDate') startDate?: string,
@Query('endDate') endDate?: string,
) {
const data = await this.adminService.getStatisticsDetails(type, startDate, endDate);
return { success: true, data };
}
}
|