[web] Fix deleting contests with submissions
This commit is contained in:
parent
9ee581c4e3
commit
9bcfec40c9
@ -31,14 +31,15 @@ export const load = (async ({ params }) => {
|
|||||||
|
|
||||||
export const actions = {
|
export const actions = {
|
||||||
delete: async ({ params }) => {
|
delete: async ({ params }) => {
|
||||||
if (!params.contestId) {
|
if (!params.contestId || isNaN(parseInt(params.contestId))) {
|
||||||
return { success: false };
|
return { success: false, message: 'Invalid contest Id' };
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
await db.submission.deleteMany({ where: { contestId: parseInt(params.contestId) } });
|
||||||
await db.contest.delete({ where: { id: parseInt(params.contestId) } });
|
await db.contest.delete({ where: { id: parseInt(params.contestId) } });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
return { success: false };
|
return { success: false, message: `Database error: ${e}` };
|
||||||
}
|
}
|
||||||
redirect(302, '/admin/contests');
|
redirect(302, '/admin/contests');
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user