feat(backend): Aufgaben-Modul (Modul 6)

TasksModule mit CRUD, Status-/Prioritätsfilter und
Erledigen-Endpunkt für polymorph verknüpfte Aufgaben.
This commit is contained in:
Nick Szaunig committed 2026-08-21 23:43:47 +02:00
1 parent 829753ec90
commit 7bba168bd6
9 files changed
+408 -1

No files matched your search

@@ -0,0 +1,93 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { PrismaService } from '../prisma/prisma.service';
import { AuditLogService } from '../audit/audit-log.service';
import { Task, TaskPriority, TaskStatus } from '../../generated/prisma';
import { CreateTaskDto } from './dto/create-task.dto';
import { UpdateTaskDto } from './dto/update-task.dto';
export interface TaskFilter {
status?: TaskStatus;
priority?: TaskPriority;
}
@Injectable()
export class TasksService {
constructor(
private readonly prisma: PrismaService,
private readonly auditLog: AuditLogService,
) {}
async findAll(filter: TaskFilter): Promise<Task[]> {
return this.prisma.task.findMany({
where: filter,
orderBy: [{ dueDate: 'asc' }, { createdAt: 'desc' }],
});
}
async findById(id: string): Promise<Task> {
const task = await this.prisma.task.findUnique({ where: { id } });
if (!task) {
throw new NotFoundException('Task not found');
}
return task;
}
async create(dto: CreateTaskDto, actingUserId: string): Promise<Task> {
const task = await this.prisma.task.create({
data: {
...dto,
dueDate: dto.dueDate ? new Date(dto.dueDate) : undefined,
createdByUserId: actingUserId,
},
});
await this.auditLog.record({
entityType: 'Task',
entityId: task.id,
action: 'CREATE',
userId: actingUserId,
afterData: task,
});
return task;
}
async update(
id: string,
dto: UpdateTaskDto,
actingUserId: string,
): Promise<Task> {
const before = await this.findById(id);
const task = await this.prisma.task.update({
where: { id },
data: {
...dto,
dueDate: dto.dueDate ? new Date(dto.dueDate) : undefined,
},
});
await this.auditLog.record({
entityType: 'Task',
entityId: id,
action: 'UPDATE',
userId: actingUserId,
beforeData: before,
afterData: task,
});
return task;
}
async complete(id: string, actingUserId: string): Promise<Task> {
const before = await this.findById(id);
const task = await this.prisma.task.update({
where: { id },
data: { status: 'DONE', completedAt: new Date() },
});
await this.auditLog.record({
entityType: 'Task',
entityId: id,
action: 'UPDATE',
userId: actingUserId,
beforeData: before,
afterData: task,
});
return task;
}
}