Refactor giveaway job processing and enhance environment documentation
- Improved handling of the `giveawayCreate` job in the bot's job processing for better consistency. - Updated `.env.example` to clarify the usage of `BOT_TOKEN` for both the bot and WebUI. - Added `bullmq` dependency to the WebUI package for enhanced job management capabilities.
This commit is contained in:
46
apps/webui/src/app/api/guilds/[guildId]/birthdays/route.ts
Normal file
46
apps/webui/src/app/api/guilds/[guildId]/birthdays/route.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { BirthdayConfigDashboardPatchSchema } from '@nexumi/shared';
|
||||
import { type NextRequest, NextResponse } from 'next/server';
|
||||
import { requireGuildAccess, toApiErrorResponse } from '@/lib/auth';
|
||||
import { writeDashboardAudit } from '@/lib/audit';
|
||||
import { getBirthdayDashboard, updateBirthdayDashboard } from '@/lib/module-configs/birthdays';
|
||||
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 getBirthdayDashboard(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 = BirthdayConfigDashboardPatchSchema.parse(body);
|
||||
|
||||
const before = await getBirthdayDashboard(guildId);
|
||||
const after = await updateBirthdayDashboard(guildId, patch);
|
||||
|
||||
await writeDashboardAudit(prisma, {
|
||||
guildId,
|
||||
actorUserId: session.user.id,
|
||||
action: 'birthdays.update',
|
||||
path: `/dashboard/${guildId}/birthdays`,
|
||||
before,
|
||||
after
|
||||
});
|
||||
|
||||
return NextResponse.json(after);
|
||||
} catch (error) {
|
||||
return toApiErrorResponse(error);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import { GiveawayActionSchema } from '@nexumi/shared';
|
||||
import { type NextRequest, NextResponse } from 'next/server';
|
||||
import { requireGuildAccess, toApiErrorResponse } from '@/lib/auth';
|
||||
import { writeDashboardAudit } from '@/lib/audit';
|
||||
import { endGiveawayDashboard, setGiveawayPaused } from '@/lib/module-configs/giveaways';
|
||||
import { prisma } from '@/lib/prisma';
|
||||
|
||||
interface RouteParams {
|
||||
params: Promise<{ guildId: string; giveawayId: string }>;
|
||||
}
|
||||
|
||||
export async function POST(request: NextRequest, { params }: RouteParams) {
|
||||
const { guildId, giveawayId } = await params;
|
||||
try {
|
||||
const session = await requireGuildAccess(guildId);
|
||||
const body = await request.json();
|
||||
const action = GiveawayActionSchema.parse(body.action);
|
||||
|
||||
let giveaway;
|
||||
if (action === 'end') {
|
||||
giveaway = await endGiveawayDashboard(guildId, giveawayId);
|
||||
} else if (action === 'pause') {
|
||||
giveaway = await setGiveawayPaused(guildId, giveawayId, true);
|
||||
} else {
|
||||
giveaway = await setGiveawayPaused(guildId, giveawayId, false);
|
||||
}
|
||||
|
||||
if (!giveaway) {
|
||||
return NextResponse.json({ error: 'Giveaway not found or already ended' }, { status: 404 });
|
||||
}
|
||||
|
||||
await writeDashboardAudit(prisma, {
|
||||
guildId,
|
||||
actorUserId: session.user.id,
|
||||
action: `giveaways.${action}`,
|
||||
path: `/dashboard/${guildId}/giveaways`,
|
||||
after: giveaway
|
||||
});
|
||||
|
||||
return NextResponse.json(giveaway);
|
||||
} catch (error) {
|
||||
return toApiErrorResponse(error);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import { type NextRequest, NextResponse } from 'next/server';
|
||||
import { requireGuildAccess, toApiErrorResponse } from '@/lib/auth';
|
||||
import { writeDashboardAudit } from '@/lib/audit';
|
||||
import { deleteGiveawayDashboard } from '@/lib/module-configs/giveaways';
|
||||
import { prisma } from '@/lib/prisma';
|
||||
|
||||
interface RouteParams {
|
||||
params: Promise<{ guildId: string; giveawayId: string }>;
|
||||
}
|
||||
|
||||
export async function DELETE(_request: NextRequest, { params }: RouteParams) {
|
||||
const { guildId, giveawayId } = await params;
|
||||
try {
|
||||
const session = await requireGuildAccess(guildId);
|
||||
const deleted = await deleteGiveawayDashboard(guildId, giveawayId);
|
||||
if (!deleted) {
|
||||
return NextResponse.json({ error: 'Giveaway not found' }, { status: 404 });
|
||||
}
|
||||
|
||||
await writeDashboardAudit(prisma, {
|
||||
guildId,
|
||||
actorUserId: session.user.id,
|
||||
action: 'giveaways.delete',
|
||||
path: `/dashboard/${guildId}/giveaways`,
|
||||
before: { giveawayId }
|
||||
});
|
||||
|
||||
return NextResponse.json({ ok: true });
|
||||
} catch (error) {
|
||||
return toApiErrorResponse(error);
|
||||
}
|
||||
}
|
||||
47
apps/webui/src/app/api/guilds/[guildId]/giveaways/route.ts
Normal file
47
apps/webui/src/app/api/guilds/[guildId]/giveaways/route.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { GiveawayCreateDashboardSchema } from '@nexumi/shared';
|
||||
import { type NextRequest, NextResponse } from 'next/server';
|
||||
import { requireGuildAccess, toApiErrorResponse } from '@/lib/auth';
|
||||
import { writeDashboardAudit } from '@/lib/audit';
|
||||
import { createGiveawayDashboard, GiveawayCreateTimeoutError, listGiveaways } from '@/lib/module-configs/giveaways';
|
||||
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 giveaways = await listGiveaways(guildId);
|
||||
return NextResponse.json({ giveaways });
|
||||
} 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 = GiveawayCreateDashboardSchema.parse(body);
|
||||
|
||||
const giveaway = await createGiveawayDashboard(guildId, session.user.id, input);
|
||||
|
||||
await writeDashboardAudit(prisma, {
|
||||
guildId,
|
||||
actorUserId: session.user.id,
|
||||
action: 'giveaways.create',
|
||||
path: `/dashboard/${guildId}/giveaways`,
|
||||
after: giveaway
|
||||
});
|
||||
|
||||
return NextResponse.json(giveaway, { status: 201 });
|
||||
} catch (error) {
|
||||
if (error instanceof GiveawayCreateTimeoutError) {
|
||||
return NextResponse.json({ error: error.message }, { status: 504 });
|
||||
}
|
||||
return toApiErrorResponse(error);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
import { SelfRolePanelDashboardUpdateSchema } from '@nexumi/shared';
|
||||
import { type NextRequest, NextResponse } from 'next/server';
|
||||
import { requireGuildAccess, toApiErrorResponse } from '@/lib/auth';
|
||||
import { writeDashboardAudit } from '@/lib/audit';
|
||||
import { deleteSelfRolePanel, updateSelfRolePanel } from '@/lib/module-configs/selfroles';
|
||||
import { prisma } from '@/lib/prisma';
|
||||
|
||||
interface RouteParams {
|
||||
params: Promise<{ guildId: string; panelId: string }>;
|
||||
}
|
||||
|
||||
export async function PATCH(request: NextRequest, { params }: RouteParams) {
|
||||
const { guildId, panelId } = await params;
|
||||
try {
|
||||
const session = await requireGuildAccess(guildId);
|
||||
const body = await request.json();
|
||||
const patch = SelfRolePanelDashboardUpdateSchema.parse(body);
|
||||
|
||||
const updated = await updateSelfRolePanel(guildId, panelId, patch);
|
||||
if (!updated) {
|
||||
return NextResponse.json({ error: 'Panel not found' }, { status: 404 });
|
||||
}
|
||||
|
||||
await writeDashboardAudit(prisma, {
|
||||
guildId,
|
||||
actorUserId: session.user.id,
|
||||
action: 'selfroles.update',
|
||||
path: `/dashboard/${guildId}/selfroles`,
|
||||
after: updated
|
||||
});
|
||||
|
||||
return NextResponse.json(updated);
|
||||
} catch (error) {
|
||||
return toApiErrorResponse(error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function DELETE(_request: NextRequest, { params }: RouteParams) {
|
||||
const { guildId, panelId } = await params;
|
||||
try {
|
||||
const session = await requireGuildAccess(guildId);
|
||||
const deleted = await deleteSelfRolePanel(guildId, panelId);
|
||||
if (!deleted) {
|
||||
return NextResponse.json({ error: 'Panel not found' }, { status: 404 });
|
||||
}
|
||||
|
||||
await writeDashboardAudit(prisma, {
|
||||
guildId,
|
||||
actorUserId: session.user.id,
|
||||
action: 'selfroles.delete',
|
||||
path: `/dashboard/${guildId}/selfroles`,
|
||||
before: { panelId }
|
||||
});
|
||||
|
||||
return NextResponse.json({ ok: true });
|
||||
} catch (error) {
|
||||
return toApiErrorResponse(error);
|
||||
}
|
||||
}
|
||||
44
apps/webui/src/app/api/guilds/[guildId]/selfroles/route.ts
Normal file
44
apps/webui/src/app/api/guilds/[guildId]/selfroles/route.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { SelfRolePanelDashboardCreateSchema } from '@nexumi/shared';
|
||||
import { type NextRequest, NextResponse } from 'next/server';
|
||||
import { requireGuildAccess, toApiErrorResponse } from '@/lib/auth';
|
||||
import { writeDashboardAudit } from '@/lib/audit';
|
||||
import { createSelfRolePanel, listSelfRolePanels } from '@/lib/module-configs/selfroles';
|
||||
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 panels = await listSelfRolePanels(guildId);
|
||||
return NextResponse.json({ panels });
|
||||
} 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 = SelfRolePanelDashboardCreateSchema.parse(body);
|
||||
|
||||
const panel = await createSelfRolePanel(guildId, input);
|
||||
|
||||
await writeDashboardAudit(prisma, {
|
||||
guildId,
|
||||
actorUserId: session.user.id,
|
||||
action: 'selfroles.create',
|
||||
path: `/dashboard/${guildId}/selfroles`,
|
||||
after: panel
|
||||
});
|
||||
|
||||
return NextResponse.json(panel, { status: 201 });
|
||||
} catch (error) {
|
||||
return toApiErrorResponse(error);
|
||||
}
|
||||
}
|
||||
46
apps/webui/src/app/api/guilds/[guildId]/starboard/route.ts
Normal file
46
apps/webui/src/app/api/guilds/[guildId]/starboard/route.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { StarboardConfigDashboardPatchSchema } from '@nexumi/shared';
|
||||
import { type NextRequest, NextResponse } from 'next/server';
|
||||
import { requireGuildAccess, toApiErrorResponse } from '@/lib/auth';
|
||||
import { writeDashboardAudit } from '@/lib/audit';
|
||||
import { getStarboardDashboard, updateStarboardDashboard } from '@/lib/module-configs/starboard';
|
||||
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 getStarboardDashboard(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 = StarboardConfigDashboardPatchSchema.parse(body);
|
||||
|
||||
const before = await getStarboardDashboard(guildId);
|
||||
const after = await updateStarboardDashboard(guildId, patch);
|
||||
|
||||
await writeDashboardAudit(prisma, {
|
||||
guildId,
|
||||
actorUserId: session.user.id,
|
||||
action: 'starboard.update',
|
||||
path: `/dashboard/${guildId}/starboard`,
|
||||
before,
|
||||
after
|
||||
});
|
||||
|
||||
return NextResponse.json(after);
|
||||
} catch (error) {
|
||||
return toApiErrorResponse(error);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
import { TagDashboardUpdateSchema } from '@nexumi/shared';
|
||||
import { type NextRequest, NextResponse } from 'next/server';
|
||||
import { requireGuildAccess, toApiErrorResponse } from '@/lib/auth';
|
||||
import { writeDashboardAudit } from '@/lib/audit';
|
||||
import { deleteTag, TagConflictError, updateTag } from '@/lib/module-configs/tags';
|
||||
import { prisma } from '@/lib/prisma';
|
||||
|
||||
interface RouteParams {
|
||||
params: Promise<{ guildId: string; tagId: string }>;
|
||||
}
|
||||
|
||||
export async function PATCH(request: NextRequest, { params }: RouteParams) {
|
||||
const { guildId, tagId } = await params;
|
||||
try {
|
||||
const session = await requireGuildAccess(guildId);
|
||||
const body = await request.json();
|
||||
const patch = TagDashboardUpdateSchema.parse(body);
|
||||
|
||||
const updated = await updateTag(guildId, tagId, patch);
|
||||
if (!updated) {
|
||||
return NextResponse.json({ error: 'Tag not found' }, { status: 404 });
|
||||
}
|
||||
|
||||
await writeDashboardAudit(prisma, {
|
||||
guildId,
|
||||
actorUserId: session.user.id,
|
||||
action: 'tags.update',
|
||||
path: `/dashboard/${guildId}/tags`,
|
||||
after: updated
|
||||
});
|
||||
|
||||
return NextResponse.json(updated);
|
||||
} catch (error) {
|
||||
if (error instanceof TagConflictError) {
|
||||
return NextResponse.json({ error: error.message }, { status: 409 });
|
||||
}
|
||||
return toApiErrorResponse(error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function DELETE(_request: NextRequest, { params }: RouteParams) {
|
||||
const { guildId, tagId } = await params;
|
||||
try {
|
||||
const session = await requireGuildAccess(guildId);
|
||||
const deleted = await deleteTag(guildId, tagId);
|
||||
if (!deleted) {
|
||||
return NextResponse.json({ error: 'Tag not found' }, { status: 404 });
|
||||
}
|
||||
|
||||
await writeDashboardAudit(prisma, {
|
||||
guildId,
|
||||
actorUserId: session.user.id,
|
||||
action: 'tags.delete',
|
||||
path: `/dashboard/${guildId}/tags`,
|
||||
before: { tagId }
|
||||
});
|
||||
|
||||
return NextResponse.json({ ok: true });
|
||||
} catch (error) {
|
||||
return toApiErrorResponse(error);
|
||||
}
|
||||
}
|
||||
47
apps/webui/src/app/api/guilds/[guildId]/tags/route.ts
Normal file
47
apps/webui/src/app/api/guilds/[guildId]/tags/route.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { TagDashboardCreateSchema } from '@nexumi/shared';
|
||||
import { type NextRequest, NextResponse } from 'next/server';
|
||||
import { requireGuildAccess, toApiErrorResponse } from '@/lib/auth';
|
||||
import { writeDashboardAudit } from '@/lib/audit';
|
||||
import { createTag, listTags, TagConflictError } from '@/lib/module-configs/tags';
|
||||
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 tags = await listTags(guildId);
|
||||
return NextResponse.json({ tags });
|
||||
} 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 = TagDashboardCreateSchema.parse(body);
|
||||
|
||||
const tag = await createTag(guildId, session.user.id, input);
|
||||
|
||||
await writeDashboardAudit(prisma, {
|
||||
guildId,
|
||||
actorUserId: session.user.id,
|
||||
action: 'tags.create',
|
||||
path: `/dashboard/${guildId}/tags`,
|
||||
after: tag
|
||||
});
|
||||
|
||||
return NextResponse.json(tag, { status: 201 });
|
||||
} catch (error) {
|
||||
if (error instanceof TagConflictError) {
|
||||
return NextResponse.json({ error: error.message }, { status: 409 });
|
||||
}
|
||||
return toApiErrorResponse(error);
|
||||
}
|
||||
}
|
||||
46
apps/webui/src/app/api/guilds/[guildId]/tempvoice/route.ts
Normal file
46
apps/webui/src/app/api/guilds/[guildId]/tempvoice/route.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { TempVoiceConfigDashboardPatchSchema } from '@nexumi/shared';
|
||||
import { type NextRequest, NextResponse } from 'next/server';
|
||||
import { requireGuildAccess, toApiErrorResponse } from '@/lib/auth';
|
||||
import { writeDashboardAudit } from '@/lib/audit';
|
||||
import { getTempVoiceDashboard, updateTempVoiceDashboard } from '@/lib/module-configs/tempvoice';
|
||||
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 getTempVoiceDashboard(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 = TempVoiceConfigDashboardPatchSchema.parse(body);
|
||||
|
||||
const before = await getTempVoiceDashboard(guildId);
|
||||
const after = await updateTempVoiceDashboard(guildId, patch);
|
||||
|
||||
await writeDashboardAudit(prisma, {
|
||||
guildId,
|
||||
actorUserId: session.user.id,
|
||||
action: 'tempvoice.update',
|
||||
path: `/dashboard/${guildId}/tempvoice`,
|
||||
before,
|
||||
after
|
||||
});
|
||||
|
||||
return NextResponse.json(after);
|
||||
} catch (error) {
|
||||
return toApiErrorResponse(error);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
import { TicketCategoryDashboardUpdateSchema } from '@nexumi/shared';
|
||||
import { type NextRequest, NextResponse } from 'next/server';
|
||||
import { requireGuildAccess, toApiErrorResponse } from '@/lib/auth';
|
||||
import { writeDashboardAudit } from '@/lib/audit';
|
||||
import {
|
||||
deleteTicketCategory,
|
||||
TicketCategoryConflictError,
|
||||
updateTicketCategory
|
||||
} from '@/lib/module-configs/tickets';
|
||||
import { prisma } from '@/lib/prisma';
|
||||
|
||||
interface RouteParams {
|
||||
params: Promise<{ guildId: string; categoryId: string }>;
|
||||
}
|
||||
|
||||
export async function PATCH(request: NextRequest, { params }: RouteParams) {
|
||||
const { guildId, categoryId } = await params;
|
||||
try {
|
||||
const session = await requireGuildAccess(guildId);
|
||||
const body = await request.json();
|
||||
const patch = TicketCategoryDashboardUpdateSchema.parse(body);
|
||||
|
||||
const updated = await updateTicketCategory(guildId, categoryId, patch);
|
||||
if (!updated) {
|
||||
return NextResponse.json({ error: 'Category not found' }, { status: 404 });
|
||||
}
|
||||
|
||||
await writeDashboardAudit(prisma, {
|
||||
guildId,
|
||||
actorUserId: session.user.id,
|
||||
action: 'tickets.category.update',
|
||||
path: `/dashboard/${guildId}/tickets`,
|
||||
after: updated
|
||||
});
|
||||
|
||||
return NextResponse.json(updated);
|
||||
} catch (error) {
|
||||
if (error instanceof TicketCategoryConflictError) {
|
||||
return NextResponse.json({ error: error.message }, { status: 409 });
|
||||
}
|
||||
return toApiErrorResponse(error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function DELETE(_request: NextRequest, { params }: RouteParams) {
|
||||
const { guildId, categoryId } = await params;
|
||||
try {
|
||||
const session = await requireGuildAccess(guildId);
|
||||
const deleted = await deleteTicketCategory(guildId, categoryId);
|
||||
if (!deleted) {
|
||||
return NextResponse.json({ error: 'Category not found' }, { status: 404 });
|
||||
}
|
||||
|
||||
await writeDashboardAudit(prisma, {
|
||||
guildId,
|
||||
actorUserId: session.user.id,
|
||||
action: 'tickets.category.delete',
|
||||
path: `/dashboard/${guildId}/tickets`,
|
||||
before: { categoryId }
|
||||
});
|
||||
|
||||
return NextResponse.json({ ok: true });
|
||||
} catch (error) {
|
||||
return toApiErrorResponse(error);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import { TicketCategoryDashboardCreateSchema } from '@nexumi/shared';
|
||||
import { type NextRequest, NextResponse } from 'next/server';
|
||||
import { requireGuildAccess, toApiErrorResponse } from '@/lib/auth';
|
||||
import { writeDashboardAudit } from '@/lib/audit';
|
||||
import { createTicketCategory, listTicketCategories, TicketCategoryConflictError } from '@/lib/module-configs/tickets';
|
||||
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 categories = await listTicketCategories(guildId);
|
||||
return NextResponse.json({ categories });
|
||||
} 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 = TicketCategoryDashboardCreateSchema.parse(body);
|
||||
|
||||
const category = await createTicketCategory(guildId, input);
|
||||
|
||||
await writeDashboardAudit(prisma, {
|
||||
guildId,
|
||||
actorUserId: session.user.id,
|
||||
action: 'tickets.category.create',
|
||||
path: `/dashboard/${guildId}/tickets`,
|
||||
after: category
|
||||
});
|
||||
|
||||
return NextResponse.json(category, { status: 201 });
|
||||
} catch (error) {
|
||||
if (error instanceof TicketCategoryConflictError) {
|
||||
return NextResponse.json({ error: error.message }, { status: 409 });
|
||||
}
|
||||
return toApiErrorResponse(error);
|
||||
}
|
||||
}
|
||||
46
apps/webui/src/app/api/guilds/[guildId]/tickets/route.ts
Normal file
46
apps/webui/src/app/api/guilds/[guildId]/tickets/route.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { TicketConfigDashboardPatchSchema } from '@nexumi/shared';
|
||||
import { type NextRequest, NextResponse } from 'next/server';
|
||||
import { requireGuildAccess, toApiErrorResponse } from '@/lib/auth';
|
||||
import { writeDashboardAudit } from '@/lib/audit';
|
||||
import { getTicketConfigDashboard, updateTicketConfigDashboard } from '@/lib/module-configs/tickets';
|
||||
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 getTicketConfigDashboard(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 = TicketConfigDashboardPatchSchema.parse(body);
|
||||
|
||||
const before = await getTicketConfigDashboard(guildId);
|
||||
const after = await updateTicketConfigDashboard(guildId, patch);
|
||||
|
||||
await writeDashboardAudit(prisma, {
|
||||
guildId,
|
||||
actorUserId: session.user.id,
|
||||
action: 'tickets.update',
|
||||
path: `/dashboard/${guildId}/tickets`,
|
||||
before,
|
||||
after
|
||||
});
|
||||
|
||||
return NextResponse.json(after);
|
||||
} catch (error) {
|
||||
return toApiErrorResponse(error);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user