feat: gateway CRUD routes — conversations, projects, missions, tasks (P1-005/006) (#72)

Co-authored-by: Jason Woltje <jason@diversecanvas.com>
Co-committed-by: Jason Woltje <jason@diversecanvas.com>
This commit was merged in pull request #72.
This commit is contained in:
2026-03-13 02:41:03 +00:00
committed by jason.woltje
parent 38897fe423
commit c54b69f7ce
17 changed files with 417 additions and 3 deletions

View File

@@ -0,0 +1,79 @@
import {
Body,
Controller,
Delete,
Get,
HttpCode,
HttpStatus,
Inject,
NotFoundException,
Param,
Patch,
Post,
Query,
UseGuards,
} from '@nestjs/common';
import type { Brain } from '@mosaic/brain';
import { BRAIN } from '../brain/brain.module.js';
import { AuthGuard } from '../auth/auth.guard.js';
import type { CreateTaskDto, UpdateTaskDto } from './tasks.dto.js';
@Controller('api/tasks')
@UseGuards(AuthGuard)
export class TasksController {
constructor(@Inject(BRAIN) private readonly brain: Brain) {}
@Get()
async list(
@Query('projectId') projectId?: string,
@Query('missionId') missionId?: string,
@Query('status') status?: string,
) {
if (projectId) return this.brain.tasks.findByProject(projectId);
if (missionId) return this.brain.tasks.findByMission(missionId);
if (status)
return this.brain.tasks.findByStatus(
status as Parameters<typeof this.brain.tasks.findByStatus>[0],
);
return this.brain.tasks.findAll();
}
@Get(':id')
async findOne(@Param('id') id: string) {
const task = await this.brain.tasks.findById(id);
if (!task) throw new NotFoundException('Task not found');
return task;
}
@Post()
async create(@Body() dto: CreateTaskDto) {
return this.brain.tasks.create({
title: dto.title,
description: dto.description,
status: dto.status,
priority: dto.priority,
projectId: dto.projectId,
missionId: dto.missionId,
assignee: dto.assignee,
tags: dto.tags,
dueDate: dto.dueDate ? new Date(dto.dueDate) : undefined,
});
}
@Patch(':id')
async update(@Param('id') id: string, @Body() dto: UpdateTaskDto) {
const task = await this.brain.tasks.update(id, {
...dto,
dueDate: dto.dueDate ? new Date(dto.dueDate) : dto.dueDate === null ? null : undefined,
});
if (!task) throw new NotFoundException('Task not found');
return task;
}
@Delete(':id')
@HttpCode(HttpStatus.NO_CONTENT)
async remove(@Param('id') id: string) {
const deleted = await this.brain.tasks.remove(id);
if (!deleted) throw new NotFoundException('Task not found');
}
}