Refactor giveaway job processing and update environment documentation
- 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.
This commit is contained in:
46
apps/webui/src/app/api/guilds/[guildId]/stats/route.ts
Normal file
46
apps/webui/src/app/api/guilds/[guildId]/stats/route.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { StatsConfigDashboardPatchSchema } from '@nexumi/shared';
|
||||
import { type NextRequest, NextResponse } from 'next/server';
|
||||
import { requireGuildAccess, toApiErrorResponse } from '@/lib/auth';
|
||||
import { writeDashboardAudit } from '@/lib/audit';
|
||||
import { getStatsDashboard, updateStatsDashboard } from '@/lib/module-configs/stats';
|
||||
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 getStatsDashboard(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 = StatsConfigDashboardPatchSchema.parse(body);
|
||||
|
||||
const before = await getStatsDashboard(guildId);
|
||||
const after = await updateStatsDashboard(guildId, patch);
|
||||
|
||||
await writeDashboardAudit(prisma, {
|
||||
guildId,
|
||||
actorUserId: session.user.id,
|
||||
action: 'stats.update',
|
||||
path: `/dashboard/${guildId}/stats`,
|
||||
before,
|
||||
after
|
||||
});
|
||||
|
||||
return NextResponse.json(after);
|
||||
} catch (error) {
|
||||
return toApiErrorResponse(error);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
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 { prisma } from '@/lib/prisma';
|
||||
|
||||
interface RouteParams {
|
||||
params: Promise<{ guildId: string; suggestionId: string }>;
|
||||
}
|
||||
|
||||
export async function POST(request: NextRequest, { params }: RouteParams) {
|
||||
const { guildId, suggestionId } = await params;
|
||||
try {
|
||||
const session = await requireGuildAccess(guildId);
|
||||
const body = await request.json();
|
||||
const action = SuggestionActionSchema.parse(body);
|
||||
|
||||
const after = await applySuggestionAction(guildId, suggestionId, action, session.user.id);
|
||||
|
||||
await writeDashboardAudit(prisma, {
|
||||
guildId,
|
||||
actorUserId: session.user.id,
|
||||
action: `suggestions.${action.status}`,
|
||||
path: `/dashboard/${guildId}/suggestions`,
|
||||
before: null,
|
||||
after
|
||||
});
|
||||
|
||||
return NextResponse.json(after);
|
||||
} catch (error) {
|
||||
return toApiErrorResponse(error);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { SuggestionListQuerySchema } from '@nexumi/shared';
|
||||
import { type NextRequest, NextResponse } from 'next/server';
|
||||
import { requireGuildAccess, toApiErrorResponse } from '@/lib/auth';
|
||||
import { listSuggestions } from '@/lib/module-configs/suggestions';
|
||||
|
||||
interface RouteParams {
|
||||
params: Promise<{ guildId: string }>;
|
||||
}
|
||||
|
||||
export async function GET(request: NextRequest, { params }: RouteParams) {
|
||||
const { guildId } = await params;
|
||||
try {
|
||||
await requireGuildAccess(guildId);
|
||||
const searchParams = request.nextUrl.searchParams;
|
||||
const query = SuggestionListQuerySchema.parse({
|
||||
status: searchParams.get('status') ?? undefined,
|
||||
limit: searchParams.get('limit') ?? undefined
|
||||
});
|
||||
const suggestions = await listSuggestions(guildId, query);
|
||||
return NextResponse.json({ suggestions });
|
||||
} catch (error) {
|
||||
return toApiErrorResponse(error);
|
||||
}
|
||||
}
|
||||
46
apps/webui/src/app/api/guilds/[guildId]/suggestions/route.ts
Normal file
46
apps/webui/src/app/api/guilds/[guildId]/suggestions/route.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
13
apps/webui/src/app/dashboard/[guildId]/birthdays/loading.tsx
Normal file
13
apps/webui/src/app/dashboard/[guildId]/birthdays/loading.tsx
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
|
||||
export default function BirthdaysLoading() {
|
||||
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" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
22
apps/webui/src/app/dashboard/[guildId]/birthdays/page.tsx
Normal file
22
apps/webui/src/app/dashboard/[guildId]/birthdays/page.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
import { BirthdaysForm } from '@/components/modules/birthdays-form';
|
||||
import { getLocale, t } from '@/lib/i18n';
|
||||
import { getBirthdayDashboard } from '@/lib/module-configs/birthdays';
|
||||
|
||||
interface BirthdaysPageProps {
|
||||
params: Promise<{ guildId: string }>;
|
||||
}
|
||||
|
||||
export default async function BirthdaysPage({ params }: BirthdaysPageProps) {
|
||||
const { guildId } = await params;
|
||||
const [locale, config] = await Promise.all([getLocale(), getBirthdayDashboard(guildId)]);
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<h1 className="text-2xl font-semibold">{t(locale, 'modules.birthdays.label')}</h1>
|
||||
<p className="text-sm text-muted-foreground">{t(locale, 'modules.birthdays.description')}</p>
|
||||
</div>
|
||||
<BirthdaysForm guildId={guildId} initialValue={config} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
13
apps/webui/src/app/dashboard/[guildId]/starboard/loading.tsx
Normal file
13
apps/webui/src/app/dashboard/[guildId]/starboard/loading.tsx
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
|
||||
export default function StarboardLoading() {
|
||||
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" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
22
apps/webui/src/app/dashboard/[guildId]/starboard/page.tsx
Normal file
22
apps/webui/src/app/dashboard/[guildId]/starboard/page.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
import { StarboardForm } from '@/components/modules/starboard-form';
|
||||
import { getLocale, t } from '@/lib/i18n';
|
||||
import { getStarboardDashboard } from '@/lib/module-configs/starboard';
|
||||
|
||||
interface StarboardPageProps {
|
||||
params: Promise<{ guildId: string }>;
|
||||
}
|
||||
|
||||
export default async function StarboardPage({ params }: StarboardPageProps) {
|
||||
const { guildId } = await params;
|
||||
const [locale, config] = await Promise.all([getLocale(), getStarboardDashboard(guildId)]);
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<h1 className="text-2xl font-semibold">{t(locale, 'modules.starboard.label')}</h1>
|
||||
<p className="text-sm text-muted-foreground">{t(locale, 'modules.starboard.description')}</p>
|
||||
</div>
|
||||
<StarboardForm guildId={guildId} initialValue={config} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
13
apps/webui/src/app/dashboard/[guildId]/stats/loading.tsx
Normal file
13
apps/webui/src/app/dashboard/[guildId]/stats/loading.tsx
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
|
||||
export default function StatsLoading() {
|
||||
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" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
22
apps/webui/src/app/dashboard/[guildId]/stats/page.tsx
Normal file
22
apps/webui/src/app/dashboard/[guildId]/stats/page.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
import { StatsForm } from '@/components/modules/stats-form';
|
||||
import { getLocale, t } from '@/lib/i18n';
|
||||
import { getStatsDashboard } from '@/lib/module-configs/stats';
|
||||
|
||||
interface StatsPageProps {
|
||||
params: Promise<{ guildId: string }>;
|
||||
}
|
||||
|
||||
export default async function StatsPage({ params }: StatsPageProps) {
|
||||
const { guildId } = await params;
|
||||
const [locale, config] = await Promise.all([getLocale(), getStatsDashboard(guildId)]);
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<h1 className="text-2xl font-semibold">{t(locale, 'modules.stats.label')}</h1>
|
||||
<p className="text-sm text-muted-foreground">{t(locale, 'modules.stats.description')}</p>
|
||||
</div>
|
||||
<StatsForm guildId={guildId} initialValue={config} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
13
apps/webui/src/app/dashboard/[guildId]/tempvoice/loading.tsx
Normal file
13
apps/webui/src/app/dashboard/[guildId]/tempvoice/loading.tsx
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
|
||||
export default function TempVoiceLoading() {
|
||||
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" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
22
apps/webui/src/app/dashboard/[guildId]/tempvoice/page.tsx
Normal file
22
apps/webui/src/app/dashboard/[guildId]/tempvoice/page.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
import { TempVoiceForm } from '@/components/modules/tempvoice-form';
|
||||
import { getLocale, t } from '@/lib/i18n';
|
||||
import { getTempVoiceDashboard } from '@/lib/module-configs/tempvoice';
|
||||
|
||||
interface TempVoicePageProps {
|
||||
params: Promise<{ guildId: string }>;
|
||||
}
|
||||
|
||||
export default async function TempVoicePage({ params }: TempVoicePageProps) {
|
||||
const { guildId } = await params;
|
||||
const [locale, config] = await Promise.all([getLocale(), getTempVoiceDashboard(guildId)]);
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<h1 className="text-2xl font-semibold">{t(locale, 'modules.tempvoice.label')}</h1>
|
||||
<p className="text-sm text-muted-foreground">{t(locale, 'modules.tempvoice.description')}</p>
|
||||
</div>
|
||||
<TempVoiceForm guildId={guildId} initialValue={config} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user