Files
CASAN/packages/casan-control-panel/backend/src/goals/goals.controller.ts
T

35 lines
1.4 KiB
TypeScript

import { Body, Controller, Get, Headers, Inject, Param, Post, Query } from '@nestjs/common';
import { ok } from '../common/api-response.js';
import { actorFromHeaders } from '../common/auth-context.js';
import { GoalsService, type GoalProjectCreateInput, type GoalStartInput } from './goals.service.js';
@Controller('api/v1/goals')
export class GoalsController {
constructor(@Inject(GoalsService) private readonly service: GoalsService) {}
@Post()
async start(@Body() body: GoalStartInput, @Headers() headers: Record<string, string | string[] | undefined>) {
return ok(await this.service.start(body, actorFromHeaders(headers)));
}
@Get('projects')
projects(@Headers() headers: Record<string, string | string[] | undefined>) {
return ok(this.service.projects(actorFromHeaders(headers)));
}
@Post('projects')
createProject(@Body() body: GoalProjectCreateInput, @Headers() headers: Record<string, string | string[] | undefined>) {
return ok(this.service.createProject(body, actorFromHeaders(headers)));
}
@Get()
list(@Headers() headers: Record<string, string | string[] | undefined>, @Query('limit') limit?: string) {
return ok(this.service.list(actorFromHeaders(headers), Number(limit) || 20));
}
@Get(':id')
get(@Param('id') id: string, @Headers() headers: Record<string, string | string[] | undefined>) {
return ok(this.service.get(id, actorFromHeaders(headers)));
}
}