feat: streamline group dispatch reminders
This commit is contained in:
@@ -24,6 +24,7 @@ export async function POST(
|
||||
|
||||
const body = (await request.json().catch(() => ({}))) as {
|
||||
approvedTargetProjectIds?: string[];
|
||||
rememberLightReminder?: boolean;
|
||||
};
|
||||
const { projectId, planId } = await context.params;
|
||||
|
||||
@@ -37,6 +38,7 @@ export async function POST(
|
||||
(item): item is string => typeof item === "string" && item.trim().length > 0,
|
||||
)
|
||||
: [],
|
||||
rememberLightReminder: body.rememberLightReminder === true,
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { requireRequestSession } from "@/lib/boss-auth";
|
||||
import {
|
||||
buildCollaborationGate,
|
||||
getProject,
|
||||
updateProjectLightDispatchReminder,
|
||||
} from "@/lib/boss-data";
|
||||
|
||||
export async function PATCH(
|
||||
request: NextRequest,
|
||||
context: { params: Promise<{ projectId: string }> },
|
||||
) {
|
||||
const session = await requireRequestSession(request);
|
||||
if (!session) {
|
||||
return NextResponse.json({ ok: false, message: "UNAUTHORIZED" }, { status: 401 });
|
||||
}
|
||||
|
||||
const { projectId } = await context.params;
|
||||
const body = (await request.json().catch(() => ({}))) as {
|
||||
lightDispatchReminderEnabled?: unknown;
|
||||
};
|
||||
if (typeof body.lightDispatchReminderEnabled !== "boolean") {
|
||||
return NextResponse.json(
|
||||
{ ok: false, message: "INVALID_DISPATCH_REMINDER_PAYLOAD" },
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
await updateProjectLightDispatchReminder({
|
||||
projectId,
|
||||
requestedBy: session.account,
|
||||
lightDispatchReminderEnabled: body.lightDispatchReminderEnabled,
|
||||
});
|
||||
const project = await getProject(projectId);
|
||||
if (!project) {
|
||||
return NextResponse.json({ ok: false, message: "PROJECT_NOT_FOUND" }, { status: 404 });
|
||||
}
|
||||
return NextResponse.json({
|
||||
ok: true,
|
||||
project,
|
||||
collaborationGate: buildCollaborationGate(project),
|
||||
});
|
||||
} catch (error) {
|
||||
const reason = error instanceof Error ? error.message : "UNKNOWN_ERROR";
|
||||
return NextResponse.json({ ok: false, message: reason }, { status: 400 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user