feat(goals): add goals.controller

This commit is contained in:
admin-valentin 2026-07-31 10:44:51 +00:00
parent 160daab7c9
commit 90c4932227

View file

@ -0,0 +1,42 @@
import { BadRequestException, Body, Controller, Delete, Get, Param, ParseUUIDPipe, Patch, Post, Query } from '@nestjs/common';
import { CurrentSession } from '../auth/session.decorator';
import type { AuthenticatedSession } from '../auth/tenant.guard';
import { CreateGoalDto, GOAL_STATUSES, UpdateGoalDto, type GoalStatusValue } from './dto';
import { GoalsService } from './goals.service';
@Controller('goals')
export class GoalsController {
constructor(private readonly goalsService: GoalsService) {}
@Get()
list(@CurrentSession() session: AuthenticatedSession, @Query('status') status?: string) {
if (status && !GOAL_STATUSES.includes(status as GoalStatusValue)) {
throw new BadRequestException(`status must be one of: ${GOAL_STATUSES.join(', ')}`);
}
return this.goalsService.list(session, status as GoalStatusValue | undefined);
}
@Get(':id')
getById(@CurrentSession() session: AuthenticatedSession, @Param('id', ParseUUIDPipe) id: string) {
return this.goalsService.getById(session, id);
}
@Post()
create(@CurrentSession() session: AuthenticatedSession, @Body() dto: CreateGoalDto) {
return this.goalsService.create(session, dto);
}
@Patch(':id')
update(
@CurrentSession() session: AuthenticatedSession,
@Param('id', ParseUUIDPipe) id: string,
@Body() dto: UpdateGoalDto,
) {
return this.goalsService.update(session, id, dto);
}
@Delete(':id')
softDelete(@CurrentSession() session: AuthenticatedSession, @Param('id', ParseUUIDPipe) id: string) {
return this.goalsService.softDelete(session, id);
}
}