Taeglich, woechentlich, alle zwei Wochen oder monatlich. Wandert die Aufgabe nach ERLEDIGT, entsteht die naechste von selbst. Die erledigte bleibt stehen - sonst ginge die Historie verloren. Gerechnet wird vom Faelligkeitsdatum, nicht vom Abhaken: eine woechentliche Aufgabe bleibt auf ihrem Montag, auch wenn sie einmal erst am Mittwoch erledigt wurde. Lange Liegengebliebenes rutscht so weit vor, bis der Termin in der Zukunft liegt; eine Aufgabe, die schon bei ihrer Entstehung ueberfaellig ist, hilft niemandem. Beim Monatsintervall bleibt der Tag im Monat erhalten. setMonth allein rollt ueber: der 31. Januar wuerde zum 3. Maerz statt zum 28. Februar. Ausgeloest wird an beiden Stellen, an denen eine Aufgabe erledigt werden kann - im Dialog und durch Ziehen ins Brett. Nur der Uebergang zaehlt: eine bereits erledigte Aufgabe erneut zu speichern erzeugt keine zweite Fassung. Bewusst grob gehalten. Feinere Regeln wie "jeden zweiten Dienstag im Monat" braucht ein Projektdashboard nicht, und sie waeren ohne Kalenderansicht kaum nachvollziehbar. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
80 lines
2.4 KiB
TypeScript
80 lines
2.4 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
import { recordActivity, shorten } from "@/lib/activity";
|
|
import { requireUserApi } from "@/lib/auth/guard";
|
|
import { prisma } from "@/lib/db";
|
|
import { jsonError, readJsonBody } from "@/lib/security/request";
|
|
import { nextPosition, ownedProject, refreshDerivedProgress } from "@/lib/tasks";
|
|
import { formatZodError, taskCreateSchema } from "@/lib/validation";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
type Params = { params: Promise<{ id: string }> };
|
|
|
|
export async function GET(_request: Request, { params }: Params) {
|
|
const auth = await requireUserApi();
|
|
if (!auth.ok) return auth.response;
|
|
|
|
const { id } = await params;
|
|
if (!(await ownedProject(id, auth.user.id))) {
|
|
return jsonError("Projekt nicht gefunden", 404);
|
|
}
|
|
|
|
const tasks = await prisma.task.findMany({
|
|
where: { projectId: id },
|
|
orderBy: [{ status: "asc" }, { position: "asc" }],
|
|
});
|
|
return NextResponse.json({ tasks });
|
|
}
|
|
|
|
export async function POST(request: Request, { params }: Params) {
|
|
const auth = await requireUserApi();
|
|
if (!auth.ok) return auth.response;
|
|
|
|
const { id } = await params;
|
|
if (!(await ownedProject(id, auth.user.id))) {
|
|
return jsonError("Projekt nicht gefunden", 404);
|
|
}
|
|
|
|
const body = await readJsonBody(request);
|
|
if (!body.ok) return body.response;
|
|
|
|
const parsed = taskCreateSchema.safeParse(body.data);
|
|
if (!parsed.success) {
|
|
return NextResponse.json(
|
|
{ error: "Validierung fehlgeschlagen", fields: formatZodError(parsed.error) },
|
|
{ status: 422 },
|
|
);
|
|
}
|
|
|
|
const { title, description, status, dueDate, labels, recurrence } = parsed.data;
|
|
|
|
const task = await prisma.task.create({
|
|
data: {
|
|
projectId: id,
|
|
title,
|
|
description: description ?? null,
|
|
status,
|
|
// Neue Aufgaben landen unten in ihrer Spalte.
|
|
position: await nextPosition(id, status),
|
|
dueDate: dueDate ? new Date(dueDate) : null,
|
|
labels,
|
|
recurrence: recurrence ?? null,
|
|
doneAt: status === "DONE" ? new Date() : null,
|
|
},
|
|
});
|
|
|
|
await refreshDerivedProgress(id);
|
|
// Damit die Sortierung nach Aktivitaet stimmt.
|
|
await prisma.project.update({ where: { id }, data: { updatedAt: new Date() } });
|
|
|
|
await recordActivity({
|
|
projectId: id,
|
|
userId: auth.user.id,
|
|
kind: "TASK_ADDED",
|
|
summary: `Aufgabe angelegt: ${shorten(task.title, 50)}`,
|
|
meta: { taskId: task.id },
|
|
});
|
|
|
|
return NextResponse.json({ task }, { status: 201 });
|
|
}
|