Browse Source

Fix contest bugs

master
Menci 8 years ago
parent
commit
fea029f284
  1. 2
      models/contest.js
  2. 6
      modules/contest.js

2
models/contest.js

@ -69,6 +69,7 @@ class Contest extends Model {
static async create(val) { static async create(val) {
return Contest.fromRecord(Contest.model.build(Object.assign({ return Contest.fromRecord(Contest.model.build(Object.assign({
title: '', title: '',
problems: '',
start_time: 0, start_time: 0,
end_time: 0, end_time: 0,
holder: 0, holder: 0,
@ -90,6 +91,7 @@ class Contest extends Model {
} }
async getProblems() { async getProblems() {
if (this.problems === '') return [];
return this.problems.split('|').map(x => parseInt(x)); return this.problems.split('|').map(x => parseInt(x));
} }

6
modules/contest.js

@ -53,9 +53,11 @@ app.get('/contest/:id/edit', async (req, res) => {
let contest = await Contest.fromID(contest_id); let contest = await Contest.fromID(contest_id);
if (!contest) { if (!contest) {
contest = await Contest.create(); 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', { res.render('edit_contest', {
contest: contest, contest: contest,
@ -164,7 +166,7 @@ app.get('/contest/:id/ranklist', async (req, res) => {
if (!contest) throw 'No such contest.'; if (!contest) throw 'No such contest.';
if (!await contest.isAllowedSeeResultBy(res.locals.user)) throw 'Permission denied'; if (!await contest.isAllowedSeeResultBy(res.locals.user)) throw 'Permission denied';
await contest.loadRelationships(); await contest.loadRelationships();
let players_id = []; let players_id = [];

Loading…
Cancel
Save