- DirectorAppointmentTab: table + 'Acceptance Letter' modal with company/director dropdowns - GET/POST /api/appointments: create record, generate HTML letter, convert to PDF via LibreOffice, email to director via himalaya SMTP - PATCH /api/appointments/[id]: save signature PNG, embed in signed letter PDF, mail to all company directors - GET /api/appointments/sign/[token]: public token lookup - /sign/[token]/page.tsx: public signature canvas (mouse + touch) - ysterbaard_director_appointments PB collection (requires manual schema setup) - Section 3 'Director Appointment' now active in ResolutionExplorer - NEXT_PUBLIC_APP_URL added to .env.local
41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
// app/api/tasks/[id]/cancel/route.ts
|
|
// POST /api/tasks/[id]/cancel
|
|
// Hard-stop an in-progress task. Atomically moves to "failed" with
|
|
// error="cancelled by user". No auto-retry.
|
|
|
|
import { NextRequest, NextResponse } from "next/server";
|
|
import { BASE_URL, PBRecord } from "@/lib/pb";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
const COLLECTION = "tasks";
|
|
|
|
export async function POST(_req: NextRequest, { params }: { params: { id: string } }) {
|
|
const url = `${BASE_URL}/api/collections/${COLLECTION}/records/${encodeURIComponent(params.id)}?filter=status="in_progress"`;
|
|
const res = await fetch(url, {
|
|
method: "PATCH",
|
|
headers: {
|
|
Authorization: process.env.PB_TOKEN as string,
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify({
|
|
status: "failed",
|
|
error: "cancelled by user",
|
|
completed_at: new Date().toISOString().replace("T", " ").replace("Z", ""),
|
|
}),
|
|
cache: "no-store",
|
|
});
|
|
|
|
if (res.status === 404) {
|
|
return NextResponse.json(
|
|
{ ok: false, error: "task not found or not in progress" },
|
|
{ status: 409 },
|
|
);
|
|
}
|
|
if (!res.ok) {
|
|
const text = await res.text();
|
|
return NextResponse.json({ ok: false, error: `PB ${res.status}: ${text.slice(0, 200)}` }, { status: 500 });
|
|
}
|
|
const data: PBRecord = await res.json();
|
|
return NextResponse.json({ ok: true, task: data });
|
|
}
|