Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { getCurrentUser } from "@/lib/auth";
import { actorLine, postDiscordEmbed } from "@/lib/discord-webhook";
import { canManageForms } from "@/lib/guild";
import { getDict } from "@/i18n";
import { validationMessage } from "@/lib/validation-error";

export const runtime = "nodejs";
export const dynamic = "force-dynamic";
Expand Down Expand Up @@ -41,7 +42,7 @@ export async function PATCH(request: NextRequest, { params }: Params) {
const parsed = auditWebhookUpdateSchema.safeParse(await request.json().catch(() => null));
if (!parsed.success) {
return NextResponse.json(
{ error: parsed.error.issues[0]?.message ?? "Invalid request." },
{ error: (await validationMessage(parsed.error)) ?? "Invalid request." },
{ status: 422 },
);
}
Expand Down
3 changes: 2 additions & 1 deletion apps/web/src/app/api/guilds/[guildId]/audit-log/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { getCurrentUser } from "@/lib/auth";
import { checkDiscordWebhook } from "@/lib/discord-webhook";
import { canManageForms } from "@/lib/guild";
import { rateLimit } from "@/lib/rate-limit";
import { validationMessage } from "@/lib/validation-error";

export const runtime = "nodejs";
export const dynamic = "force-dynamic";
Expand Down Expand Up @@ -46,7 +47,7 @@ export async function POST(
const parsed = auditWebhookInputSchema.safeParse(await request.json().catch(() => null));
if (!parsed.success) {
return NextResponse.json(
{ error: parsed.error.issues[0]?.message ?? "Invalid webhook.", code: "invalid" },
{ error: (await validationMessage(parsed.error)) ?? "Invalid webhook.", code: "invalid" },
{ status: 422 },
);
}
Expand Down
3 changes: 2 additions & 1 deletion apps/web/src/app/api/guilds/[guildId]/bot-config/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { NextResponse, type NextRequest } from "next/server";
import { actor } from "@/lib/audit";
import { getCurrentUser } from "@/lib/auth";
import { canManageForms } from "@/lib/guild";
import { validationMessage } from "@/lib/validation-error";

export const runtime = "nodejs";
export const dynamic = "force-dynamic";
Expand All @@ -25,7 +26,7 @@ export async function PATCH(
const parsed = botConfigSchema.safeParse(await request.json().catch(() => null));
if (!parsed.success) {
return NextResponse.json(
{ error: parsed.error.issues[0]?.message ?? "Invalid configuration." },
{ error: (await validationMessage(parsed.error)) ?? "Invalid configuration." },
{ status: 422 },
);
}
Expand Down
3 changes: 2 additions & 1 deletion apps/web/src/app/api/guilds/[guildId]/branding/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { getCurrentUser } from "@/lib/auth";
import { parseBranding } from "@/lib/branding";
import { canManageForms } from "@/lib/guild";
import { isGuildPro } from "@/lib/plan";
import { validationMessage } from "@/lib/validation-error";

export const runtime = "nodejs";
export const dynamic = "force-dynamic";
Expand All @@ -27,7 +28,7 @@ export async function PATCH(
const parsed = brandingColorSchema.safeParse(await request.json().catch(() => null));
if (!parsed.success) {
return NextResponse.json(
{ error: parsed.error.issues[0]?.message ?? "Invalid branding." },
{ error: (await validationMessage(parsed.error)) ?? "Invalid branding." },
{ status: 422 },
);
}
Expand Down
7 changes: 5 additions & 2 deletions apps/web/src/app/api/guilds/[guildId]/categories/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { NextResponse, type NextRequest } from "next/server";
import { actor } from "@/lib/audit";
import { getCurrentUser } from "@/lib/auth";
import { canManageForms } from "@/lib/guild";
import { validationMessage } from "@/lib/validation-error";

export const runtime = "nodejs";
export const dynamic = "force-dynamic";
Expand Down Expand Up @@ -51,7 +52,7 @@ export async function PUT(
const parsed = categoriesSchema.safeParse(await request.json().catch(() => null));
if (!parsed.success) {
return NextResponse.json(
{ error: parsed.error.issues[0]?.message ?? "Invalid categories." },
{ error: (await validationMessage(parsed.error)) ?? "Invalid categories." },
{ status: 422 },
);
}
Expand Down Expand Up @@ -85,7 +86,9 @@ export async function PUT(
await logGuildActivitySafe(guildId, {
action: "categories_updated",
...actor(user),
detail: parsed.data.length ? parsed.data.map((c) => c.name).join(", ") : "All categories removed",
detail: parsed.data.length
? parsed.data.map((c) => c.name).join(", ")
: "All categories removed",
});

// Return the saved set so the client can pick up new ids (avoids re-creating
Expand Down
8 changes: 6 additions & 2 deletions apps/web/src/app/api/guilds/[guildId]/domain/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { primaryHostname } from "@/lib/custom-domain";
import { requestDomainSync } from "@/lib/domain-sync";
import { canManageForms } from "@/lib/guild";
import { isGuildPro } from "@/lib/plan";
import { validationMessage } from "@/lib/validation-error";

export const runtime = "nodejs";
export const dynamic = "force-dynamic";
Expand All @@ -27,13 +28,16 @@ export async function PATCH(
return NextResponse.json({ error: "Forbidden." }, { status: 403 });
}
if (!(await isGuildPro(guildId))) {
return NextResponse.json({ error: "Pro plan required.", code: "pro_required" }, { status: 402 });
return NextResponse.json(
{ error: "Pro plan required.", code: "pro_required" },
{ status: 402 },
);
}

const parsed = customDomainSchema.safeParse(await request.json().catch(() => null));
if (!parsed.success) {
return NextResponse.json(
{ error: parsed.error.issues[0]?.message ?? "Invalid domain." },
{ error: (await validationMessage(parsed.error)) ?? "Invalid domain." },
{ status: 422 },
);
}
Expand Down
10 changes: 8 additions & 2 deletions apps/web/src/app/api/guilds/[guildId]/forms/[formId]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { resolveGuildCategoryId } from "@/lib/forms";
import { canDeleteForms, canManageForm } from "@/lib/guild";
import { isGuildPro } from "@/lib/plan";
import { deleteObject } from "@/lib/s3";
import { validationMessage } from "@/lib/validation-error";

export const runtime = "nodejs";
export const dynamic = "force-dynamic";
Expand Down Expand Up @@ -36,7 +37,7 @@ export async function PATCH(
const parsed = formInputSchema.safeParse(await request.json().catch(() => null));
if (!parsed.success) {
return NextResponse.json(
{ error: parsed.error.issues[0]?.message ?? "Invalid form." },
{ error: (await validationMessage(parsed.error)) ?? "Invalid form." },
{ status: 422 },
);
}
Expand Down Expand Up @@ -105,7 +106,12 @@ export async function DELETE(

const existing = await prisma.form.findUnique({
where: { id: formId },
select: { guildId: true, title: true, archivedAt: true, _count: { select: { submissions: true } } },
select: {
guildId: true,
title: true,
archivedAt: true,
_count: { select: { submissions: true } },
},
});
if (!existing || existing.guildId !== guildId) {
return NextResponse.json({ error: "Form not found." }, { status: 404 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { getCurrentUser } from "@/lib/auth";
import { resolveOrCreateCategoryByName } from "@/lib/forms";
import { canManageForms } from "@/lib/guild";
import { isGuildPro } from "@/lib/plan";
import { validationMessage } from "@/lib/validation-error";

export const runtime = "nodejs";
export const dynamic = "force-dynamic";
Expand Down Expand Up @@ -52,7 +53,7 @@ export async function POST(
const parsed = importBodySchema.safeParse(await request.json().catch(() => null));
if (!parsed.success) {
return NextResponse.json(
{ error: parsed.error.issues[0]?.message ?? "Invalid form file." },
{ error: (await validationMessage(parsed.error)) ?? "Invalid form file." },
{ status: 422 },
);
}
Expand Down
3 changes: 2 additions & 1 deletion apps/web/src/app/api/guilds/[guildId]/forms/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { formInputSchema } from "@/lib/form-input";
import { resolveGuildCategoryId } from "@/lib/forms";
import { canManageForms } from "@/lib/guild";
import { isGuildPro } from "@/lib/plan";
import { validationMessage } from "@/lib/validation-error";

export const runtime = "nodejs";
export const dynamic = "force-dynamic";
Expand All @@ -28,7 +29,7 @@ export async function POST(
const parsed = formInputSchema.safeParse(await request.json().catch(() => null));
if (!parsed.success) {
return NextResponse.json(
{ error: parsed.error.issues[0]?.message ?? "Invalid form." },
{ error: (await validationMessage(parsed.error)) ?? "Invalid form." },
{ status: 422 },
);
}
Expand Down
9 changes: 7 additions & 2 deletions apps/web/src/app/api/guilds/[guildId]/handle/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { NextResponse, type NextRequest } from "next/server";
import { actor } from "@/lib/audit";
import { getCurrentUser } from "@/lib/auth";
import { canManageForms } from "@/lib/guild";
import { validationMessage } from "@/lib/validation-error";

export const runtime = "nodejs";
export const dynamic = "force-dynamic";
Expand All @@ -31,7 +32,11 @@ export async function PATCH(
// Empty/null clears the handle.
if (raw == null || (typeof raw === "string" && raw.trim() === "")) {
await prisma.guild.update({ where: { id: guildId }, data: { handle: null } });
await logGuildActivitySafe(guildId, { action: "handle_updated", ...actor(user), detail: "Removed" });
await logGuildActivitySafe(guildId, {
action: "handle_updated",
...actor(user),
detail: "Removed",
});
return NextResponse.json({ handle: null });
}
if (typeof raw !== "string") {
Expand All @@ -41,7 +46,7 @@ export async function PATCH(
const parsed = handleSchema.safeParse(normalizeHandle(raw));
if (!parsed.success) {
return NextResponse.json(
{ error: parsed.error.issues[0]?.message ?? "Invalid handle." },
{ error: (await validationMessage(parsed.error)) ?? "Invalid handle." },
{ status: 422 },
);
}
Expand Down
7 changes: 5 additions & 2 deletions apps/web/src/app/api/guilds/[guildId]/statuses/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { NextResponse, type NextRequest } from "next/server";
import { actor } from "@/lib/audit";
import { getCurrentUser } from "@/lib/auth";
import { canManageForms } from "@/lib/guild";
import { validationMessage } from "@/lib/validation-error";

export const runtime = "nodejs";
export const dynamic = "force-dynamic";
Expand Down Expand Up @@ -47,7 +48,7 @@ export async function PUT(
const parsed = statusDefsSchema.safeParse(body?.statuses);
if (!parsed.success) {
return NextResponse.json(
{ error: parsed.error.issues[0]?.message ?? "Invalid statuses." },
{ error: (await validationMessage(parsed.error)) ?? "Invalid statuses." },
{ status: 422 },
);
}
Expand All @@ -70,7 +71,9 @@ export async function PUT(
await logGuildActivitySafe(guildId, {
action: "statuses_updated",
...actor(user),
detail: parsed.data.length ? parsed.data.map((d) => d.label).join(", ") : "Custom statuses removed",
detail: parsed.data.length
? parsed.data.map((d) => d.label).join(", ")
: "Custom statuses removed",
});
return NextResponse.json({ ok: true });
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { resolveStatus } from "@/lib/forms";
import { canReviewForm } from "@/lib/guild";
import { submissionActionSchema } from "@/lib/submission-action";
import { getDict } from "@/i18n";
import { validationMessage } from "@/lib/validation-error";

export const runtime = "nodejs";
export const dynamic = "force-dynamic";
Expand Down Expand Up @@ -57,7 +58,7 @@ export async function POST(
const parsed = submissionActionSchema.safeParse(await request.json().catch(() => null));
if (!parsed.success) {
return NextResponse.json(
{ error: parsed.error.issues[0]?.message ?? "Invalid action." },
{ error: (await validationMessage(parsed.error)) ?? "Invalid action." },
{ status: 422 },
);
}
Expand Down
8 changes: 6 additions & 2 deletions apps/web/src/app/api/guilds/[guildId]/webhooks/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { actor } from "@/lib/audit";
import { getCurrentUser } from "@/lib/auth";
import { canManageForms } from "@/lib/guild";
import { isGuildPro } from "@/lib/plan";
import { validationMessage } from "@/lib/validation-error";

export const runtime = "nodejs";
export const dynamic = "force-dynamic";
Expand Down Expand Up @@ -58,13 +59,16 @@ export async function POST(
return NextResponse.json({ error: "Forbidden." }, { status: 403 });
}
if (!(await isGuildPro(guildId))) {
return NextResponse.json({ error: "Pro plan required.", code: "pro_required" }, { status: 402 });
return NextResponse.json(
{ error: "Pro plan required.", code: "pro_required" },
{ status: 402 },
);
}

const parsed = webhookInputSchema.safeParse(await request.json().catch(() => null));
if (!parsed.success) {
return NextResponse.json(
{ error: parsed.error.issues[0]?.message ?? "Invalid webhook." },
{ error: (await validationMessage(parsed.error)) ?? "Invalid webhook." },
{ status: 422 },
);
}
Expand Down
Loading
Loading