- Enhanced the handling of the `giveawayCreate` job in the bot's job processing for improved consistency. - Clarified the usage of `BOT_TOKEN` in the `.env.example` file for both the bot and WebUI. - Integrated the `bullmq` dependency into the WebUI package to bolster job management capabilities.
47 lines
1.5 KiB
TypeScript
47 lines
1.5 KiB
TypeScript
import { SuggestionConfigDashboardPatchSchema } from '@nexumi/shared';
|
|
import { type NextRequest, NextResponse } from 'next/server';
|
|
import { requireGuildAccess, toApiErrorResponse } from '@/lib/auth';
|
|
import { writeDashboardAudit } from '@/lib/audit';
|
|
import { getSuggestionConfigDashboard, updateSuggestionConfigDashboard } from '@/lib/module-configs/suggestions';
|
|
import { prisma } from '@/lib/prisma';
|
|
|
|
interface RouteParams {
|
|
params: Promise<{ guildId: string }>;
|
|
}
|
|
|
|
export async function GET(_request: NextRequest, { params }: RouteParams) {
|
|
const { guildId } = await params;
|
|
try {
|
|
await requireGuildAccess(guildId);
|
|
const config = await getSuggestionConfigDashboard(guildId);
|
|
return NextResponse.json(config);
|
|
} catch (error) {
|
|
return toApiErrorResponse(error);
|
|
}
|
|
}
|
|
|
|
export async function PATCH(request: NextRequest, { params }: RouteParams) {
|
|
const { guildId } = await params;
|
|
try {
|
|
const session = await requireGuildAccess(guildId);
|
|
const body = await request.json();
|
|
const patch = SuggestionConfigDashboardPatchSchema.parse(body);
|
|
|
|
const before = await getSuggestionConfigDashboard(guildId);
|
|
const after = await updateSuggestionConfigDashboard(guildId, patch);
|
|
|
|
await writeDashboardAudit(prisma, {
|
|
guildId,
|
|
actorUserId: session.user.id,
|
|
action: 'suggestions.update',
|
|
path: `/dashboard/${guildId}/suggestions`,
|
|
before,
|
|
after
|
|
});
|
|
|
|
return NextResponse.json(after);
|
|
} catch (error) {
|
|
return toApiErrorResponse(error);
|
|
}
|
|
}
|