From fea029f2841221127f172deeb1f7557d717cb2dc Mon Sep 17 00:00:00 2001 From: Menci Date: Sat, 3 Dec 2016 17:23:21 +0800 Subject: [PATCH] Fix contest bugs --- models/contest.js | 2 ++ modules/contest.js | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/models/contest.js b/models/contest.js index f9b96a7..d60fe0f 100644 --- a/models/contest.js +++ b/models/contest.js @@ -69,6 +69,7 @@ class Contest extends Model { static async create(val) { return Contest.fromRecord(Contest.model.build(Object.assign({ title: '', + problems: '', start_time: 0, end_time: 0, holder: 0, @@ -90,6 +91,7 @@ class Contest extends Model { } async getProblems() { + if (this.problems === '') return []; return this.problems.split('|').map(x => parseInt(x)); } diff --git a/modules/contest.js b/modules/contest.js index 92f817f..d54a689 100644 --- a/modules/contest.js +++ b/modules/contest.js @@ -53,9 +53,11 @@ app.get('/contest/:id/edit', async (req, res) => { let contest = await Contest.fromID(contest_id); if (!contest) { contest = await Contest.create(); + contest.id = 0; } - let problems = await contest.problems.split('|').mapAsync(async id => await Problem.fromID(id)); + let problems = []; + if (contest.problems) problems = await contest.problems.split('|').mapAsync(async id => await Problem.fromID(id)); res.render('edit_contest', { contest: contest, @@ -164,7 +166,7 @@ app.get('/contest/:id/ranklist', async (req, res) => { if (!contest) throw 'No such contest.'; if (!await contest.isAllowedSeeResultBy(res.locals.user)) throw 'Permission denied'; - + await contest.loadRelationships(); let players_id = [];