Browse Source

Fix contest bugs

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

2
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));
}

4
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,

Loading…
Cancel
Save