[web] Fix deleting contests with submissions

This commit is contained in:
orosmatthew 2024-01-22 21:43:37 -05:00
parent 9ee581c4e3
commit 9bcfec40c9

View File

@ -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');
},