Add suggestion status update job and queue integration

- Introduced a new `SuggestionStatusUpdateJob` type and corresponding worker to handle suggestion status updates in the bot's job processing.
- Added `suggestionsQueue` and `suggestionsQueueEvents` for managing suggestion-related jobs in both the bot and WebUI.
- Implemented `runSuggestionStatusUpdateJob` to facilitate staff actions on suggestions via the WebUI, ensuring consistent behavior with existing commands.
- Enhanced error handling for suggestion actions to improve user experience and reliability.
This commit is contained in:
smueller
2026-07-22 15:39:31 +02:00
parent 0ac69ee840
commit 47b6cfabbc
16 changed files with 773 additions and 23 deletions

View File

@@ -0,0 +1,59 @@
import { SocialFeedDashboardUpdateSchema } from '@nexumi/shared';
import { type NextRequest, NextResponse } from 'next/server';
import { requireGuildAccess, toApiErrorResponse } from '@/lib/auth';
import { writeDashboardAudit } from '@/lib/audit';
import { deleteFeed, updateFeed } from '@/lib/module-configs/feeds';
import { prisma } from '@/lib/prisma';
interface RouteParams {
params: Promise<{ guildId: string; feedId: string }>;
}
export async function PATCH(request: NextRequest, { params }: RouteParams) {
const { guildId, feedId } = await params;
try {
const session = await requireGuildAccess(guildId);
const body = await request.json();
const patch = SocialFeedDashboardUpdateSchema.parse(body);
const updated = await updateFeed(guildId, feedId, patch);
if (!updated) {
return NextResponse.json({ error: 'Feed not found' }, { status: 404 });
}
await writeDashboardAudit(prisma, {
guildId,
actorUserId: session.user.id,
action: 'feeds.update',
path: `/dashboard/${guildId}/feeds`,
after: updated
});
return NextResponse.json(updated);
} catch (error) {
return toApiErrorResponse(error);
}
}
export async function DELETE(_request: NextRequest, { params }: RouteParams) {
const { guildId, feedId } = await params;
try {
const session = await requireGuildAccess(guildId);
const deleted = await deleteFeed(guildId, feedId);
if (!deleted) {
return NextResponse.json({ error: 'Feed not found' }, { status: 404 });
}
await writeDashboardAudit(prisma, {
guildId,
actorUserId: session.user.id,
action: 'feeds.delete',
path: `/dashboard/${guildId}/feeds`,
before: { id: feedId }
});
return NextResponse.json({ ok: true });
} catch (error) {
return toApiErrorResponse(error);
}
}

View File

@@ -0,0 +1,44 @@
import { SocialFeedDashboardCreateSchema } from '@nexumi/shared';
import { type NextRequest, NextResponse } from 'next/server';
import { requireGuildAccess, toApiErrorResponse } from '@/lib/auth';
import { writeDashboardAudit } from '@/lib/audit';
import { createFeed, listFeeds } from '@/lib/module-configs/feeds';
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 feeds = await listFeeds(guildId);
return NextResponse.json({ feeds });
} catch (error) {
return toApiErrorResponse(error);
}
}
export async function POST(request: NextRequest, { params }: RouteParams) {
const { guildId } = await params;
try {
const session = await requireGuildAccess(guildId);
const body = await request.json();
const input = SocialFeedDashboardCreateSchema.parse(body);
const feed = await createFeed(guildId, input);
await writeDashboardAudit(prisma, {
guildId,
actorUserId: session.user.id,
action: 'feeds.create',
path: `/dashboard/${guildId}/feeds`,
after: feed
});
return NextResponse.json(feed, { status: 201 });
} catch (error) {
return toApiErrorResponse(error);
}
}

View File

@@ -2,7 +2,7 @@ import { SuggestionActionSchema } from '@nexumi/shared';
import { type NextRequest, NextResponse } from 'next/server';
import { requireGuildAccess, toApiErrorResponse } from '@/lib/auth';
import { writeDashboardAudit } from '@/lib/audit';
import { applySuggestionAction } from '@/lib/module-configs/suggestions';
import { applySuggestionAction, SuggestionActionTimeoutError } from '@/lib/module-configs/suggestions';
import { prisma } from '@/lib/prisma';
interface RouteParams {
@@ -29,6 +29,9 @@ export async function POST(request: NextRequest, { params }: RouteParams) {
return NextResponse.json(after);
} catch (error) {
if (error instanceof SuggestionActionTimeoutError) {
return NextResponse.json({ error: error.message }, { status: 504 });
}
return toApiErrorResponse(error);
}
}

View File

@@ -0,0 +1,22 @@
import { FeedsManager } from '@/components/modules/feeds-manager';
import { getLocale, t } from '@/lib/i18n';
import { listFeeds } from '@/lib/module-configs/feeds';
interface FeedsPageProps {
params: Promise<{ guildId: string }>;
}
export default async function FeedsPage({ params }: FeedsPageProps) {
const { guildId } = await params;
const [locale, feeds] = await Promise.all([getLocale(), listFeeds(guildId)]);
return (
<div className="space-y-6">
<div>
<h1 className="text-2xl font-semibold">{t(locale, 'modules.feeds.label')}</h1>
<p className="text-sm text-muted-foreground">{t(locale, 'modules.feeds.description')}</p>
</div>
<FeedsManager guildId={guildId} initialFeeds={feeds} />
</div>
);
}

View File

@@ -0,0 +1,14 @@
import { Skeleton } from '@/components/ui/skeleton';
export default function SuggestionsLoading() {
return (
<div className="space-y-6">
<div className="space-y-2">
<Skeleton className="h-8 w-48" />
<Skeleton className="h-4 w-80" />
</div>
<Skeleton className="h-64 rounded-lg" />
<Skeleton className="h-96 rounded-lg" />
</div>
);
}

View File

@@ -0,0 +1,28 @@
import { SuggestionsConfigForm } from '@/components/modules/suggestions-config-form';
import { SuggestionsListManager } from '@/components/modules/suggestions-list-manager';
import { getLocale, t } from '@/lib/i18n';
import { getSuggestionConfigDashboard, listSuggestions } from '@/lib/module-configs/suggestions';
interface SuggestionsPageProps {
params: Promise<{ guildId: string }>;
}
export default async function SuggestionsPage({ params }: SuggestionsPageProps) {
const { guildId } = await params;
const [locale, config, suggestions] = await Promise.all([
getLocale(),
getSuggestionConfigDashboard(guildId),
listSuggestions(guildId, { limit: 25 })
]);
return (
<div className="space-y-6">
<div>
<h1 className="text-2xl font-semibold">{t(locale, 'modules.suggestions.label')}</h1>
<p className="text-sm text-muted-foreground">{t(locale, 'modules.suggestions.description')}</p>
</div>
<SuggestionsConfigForm guildId={guildId} initialValue={config} />
<SuggestionsListManager guildId={guildId} initialSuggestions={suggestions} />
</div>
);
}