mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-28 10:10:57 +00:00
Problem: - Frontend calls GET /fuel/purchases (all purchases) - Backend only had GET /fuel/purchases/:vehicleId (specific vehicle) - Result: 404 when loading fuel purchases list Solution: - Added getAllFuelPurchases() to FuelService - Added GET /fuel/purchases route to FuelController - Route placed before parameterized route so it gets matched first - Returns all fuel purchases ordered by date DESC Endpoints: - GET /api/fuel/purchases → all purchases - GET /api/fuel/purchases/:vehicleId → specific vehicle - POST /api/fuel/purchases → record purchase Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
55 lines
1.7 KiB
TypeScript
55 lines
1.7 KiB
TypeScript
import { Controller, Post, Get, Body, Param, Query } from '@nestjs/common';
|
|
import { ApiTags, ApiOperation } from '@nestjs/swagger';
|
|
import { FuelService } from './fuel.service';
|
|
import { CreateFuelPurchaseDto } from './dto/create-fuel-purchase.dto';
|
|
|
|
@ApiTags('Fuel Management')
|
|
@Controller('fuel')
|
|
export class FuelController {
|
|
constructor(private readonly fuelService: FuelService) {}
|
|
|
|
@Post('purchases')
|
|
@ApiOperation({ summary: 'Record fuel purchase' })
|
|
async recordFuelPurchase(@Body() dto: CreateFuelPurchaseDto) {
|
|
return this.fuelService.recordFuelPurchase(dto);
|
|
}
|
|
|
|
@Get('purchases')
|
|
@ApiOperation({ summary: 'Get all fuel purchases' })
|
|
async getAllFuelPurchases() {
|
|
return this.fuelService.getAllFuelPurchases();
|
|
}
|
|
|
|
@Get('purchases/:vehicleId')
|
|
@ApiOperation({ summary: 'Get fuel purchases for vehicle' })
|
|
async getFuelPurchases(
|
|
@Param('vehicleId') vehicleId: string,
|
|
@Query('startDate') startDate: string,
|
|
@Query('endDate') endDate: string,
|
|
) {
|
|
return this.fuelService.getFuelPurchases(
|
|
vehicleId,
|
|
new Date(startDate),
|
|
new Date(endDate),
|
|
);
|
|
}
|
|
|
|
@Get('consumption/:vehicleId/:month')
|
|
@ApiOperation({ summary: 'Get monthly fuel consumption' })
|
|
async getMonthlyConsumption(
|
|
@Param('vehicleId') vehicleId: string,
|
|
@Param('month') month: string,
|
|
) {
|
|
return this.fuelService.getMonthlyConsumption(vehicleId, new Date(month));
|
|
}
|
|
|
|
@Get('stats/:vehicleId')
|
|
@ApiOperation({ summary: 'Get fuel statistics for vehicle' })
|
|
async getVehicleFuelStats(
|
|
@Param('vehicleId') vehicleId: string,
|
|
@Query('months') months: number = 12,
|
|
) {
|
|
return this.fuelService.getVehicleFuelStats(vehicleId, months);
|
|
}
|
|
}
|