From 9bcfec40c95ce8e5125a5810dbe6ea0ebbee2f7d Mon Sep 17 00:00:00 2001 From: orosmatthew Date: Mon, 22 Jan 2024 21:43:37 -0500 Subject: [PATCH] [web] Fix deleting contests with submissions --- web/src/routes/admin/contests/[contestId]/+page.server.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/web/src/routes/admin/contests/[contestId]/+page.server.ts b/web/src/routes/admin/contests/[contestId]/+page.server.ts index e2b63ea..4bfacde 100644 --- a/web/src/routes/admin/contests/[contestId]/+page.server.ts +++ b/web/src/routes/admin/contests/[contestId]/+page.server.ts @@ -31,14 +31,15 @@ export const load = (async ({ params }) => { export const actions = { delete: async ({ params }) => { - if (!params.contestId) { - return { success: false }; + if (!params.contestId || isNaN(parseInt(params.contestId))) { + return { success: false, message: 'Invalid contest Id' }; } try { + await db.submission.deleteMany({ where: { contestId: parseInt(params.contestId) } }); await db.contest.delete({ where: { id: parseInt(params.contestId) } }); } catch (e) { console.error(e); - return { success: false }; + return { success: false, message: `Database error: ${e}` }; } redirect(302, '/admin/contests'); },