import { Controller, Get, Post, Query, Param, UseGuards } from '@nestjs/common'; import { CostsService, CostPeriod } from './costs.service'; import { ApiKeyGuard } from '../auth/api-key.guard'; import { SisterNamePipe } from '../common/sister-name.pipe'; import type { SisterName } from '../common/sister-name.pipe'; @Controller('api/admin/costs') @UseGuards(ApiKeyGuard) export class CostsController { constructor(private readonly costsService: CostsService) {} @Get() getCosts(@Query('period') period?: string) { const validPeriods: CostPeriod[] = ['day', 'week', 'month']; const p = validPeriods.includes(period as CostPeriod) ? (period as CostPeriod) : 'week'; return this.costsService.getCosts(p); } @Post('record/:name') recordCosts(@Param('name', SisterNamePipe) name: SisterName) { return this.costsService.recordCosts(name); } }