|
| 1 | +import { |
| 2 | + Controller, |
| 3 | + Get, |
| 4 | + Post, |
| 5 | + Delete, |
| 6 | + Query, |
| 7 | + Body, |
| 8 | + Param, |
| 9 | + Req, |
| 10 | + UseGuards, |
| 11 | +} from '@nestjs/common'; |
| 12 | +import { AuthGuard } from '@nestjs/passport'; |
| 13 | +import { ReportsService } from './reports.service'; |
| 14 | + |
| 15 | +@Controller('reports') |
| 16 | +@UseGuards(AuthGuard('jwt')) |
| 17 | +export class ReportsController { |
| 18 | + constructor(private readonly reportsService: ReportsService) {} |
| 19 | + |
| 20 | + @Get('summary') |
| 21 | + getSummary() { |
| 22 | + return this.reportsService.getSummary(); |
| 23 | + } |
| 24 | + |
| 25 | + @Get('warranty-expiring') |
| 26 | + getWarrantyExpiring(@Query('days') days?: string) { |
| 27 | + return this.reportsService.getWarrantyExpiring( |
| 28 | + days ? parseInt(days, 10) : 30, |
| 29 | + ); |
| 30 | + } |
| 31 | + |
| 32 | + @Get('maintenance-costs') |
| 33 | + getMaintenanceCosts() { |
| 34 | + return this.reportsService.getMaintenanceCosts(); |
| 35 | + } |
| 36 | + |
| 37 | + @Get('depreciation') |
| 38 | + getDepreciation() { |
| 39 | + return this.reportsService.getDepreciation(); |
| 40 | + } |
| 41 | + |
| 42 | + @Get('asset-utilisation') |
| 43 | + getAssetUtilisation() { |
| 44 | + return this.reportsService.getAssetUtilisation(); |
| 45 | + } |
| 46 | + |
| 47 | + @Get('schedules') |
| 48 | + getSchedules(@Req() req: any) { |
| 49 | + return this.reportsService.getSchedules(req.user?.id); |
| 50 | + } |
| 51 | + |
| 52 | + @Post('schedules') |
| 53 | + createSchedule( |
| 54 | + @Req() req: any, |
| 55 | + @Body() body: { reportType: string; frequency: string; email: string }, |
| 56 | + ) { |
| 57 | + return this.reportsService.createSchedule( |
| 58 | + req.user?.id, |
| 59 | + body.reportType, |
| 60 | + body.frequency, |
| 61 | + body.email, |
| 62 | + ); |
| 63 | + } |
| 64 | + |
| 65 | + @Delete('schedules/:id') |
| 66 | + deleteSchedule(@Param('id') id: string, @Req() req: any) { |
| 67 | + return this.reportsService.deleteSchedule(id, req.user?.id); |
| 68 | + } |
| 69 | +} |
0 commit comments