fix: Giveaway bugs
This commit is contained in:
@@ -83,9 +83,18 @@ export function GiveawaysManager({ guildId, initialGiveaways }: GiveawaysManager
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ action })
|
||||
});
|
||||
const body = (await response.json().catch(() => null)) as (GiveawayDashboard & { error?: string }) | null;
|
||||
if (!response.ok || !body) {
|
||||
toast.error(body?.error ?? t('common.saveError'));
|
||||
const body = (await response.json().catch(() => null)) as
|
||||
| (GiveawayDashboard & { error?: string })
|
||||
| { error?: string }
|
||||
| null;
|
||||
if (!response.ok || !body || !('id' in body)) {
|
||||
toast.error(
|
||||
(body && 'error' in body && body.error) || t('common.saveError')
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (action === 'end' && !body.endedAt) {
|
||||
toast.error(t('common.saveError'));
|
||||
return;
|
||||
}
|
||||
setGiveaways((prev) => prev.map((entry) => (entry.id === giveaway.id ? body : entry)));
|
||||
|
||||
@@ -115,16 +115,24 @@ export async function endGiveawayDashboard(guildId: string, giveawayId: string):
|
||||
const existingJob = await getGiveawayQueue().getJob(`giveaway-end-${giveawayId}`);
|
||||
await existingJob?.remove();
|
||||
|
||||
await addJobAndAwait(
|
||||
const { confirmed } = await addJobAndAwait(
|
||||
getGiveawayQueue(),
|
||||
getGiveawayQueueEvents(),
|
||||
'giveawayEnd',
|
||||
{ giveawayId },
|
||||
{ jobId: `giveaway-end-${giveawayId}`, removeOnComplete: true, removeOnFail: 50, delay: 0 }
|
||||
{ jobId: `giveaway-end-${giveawayId}`, removeOnComplete: true, removeOnFail: 50, delay: 0 },
|
||||
30_000
|
||||
);
|
||||
|
||||
const updated = await prisma.giveaway.findUnique({ where: { id: giveawayId } });
|
||||
return updated ? toDashboard(updated) : null;
|
||||
if (!updated?.endedAt) {
|
||||
throw new Error(
|
||||
confirmed
|
||||
? 'Giveaway end job finished without marking the giveaway as ended'
|
||||
: 'Giveaway end timed out – the bot may still be processing; refresh and retry'
|
||||
);
|
||||
}
|
||||
return toDashboard(updated);
|
||||
}
|
||||
|
||||
export async function deleteGiveawayDashboard(guildId: string, giveawayId: string): Promise<boolean> {
|
||||
|
||||
Reference in New Issue
Block a user