Browse Source

Add check for empty title, fix tag filter paginate

pull/6/head
Menci 8 years ago
parent
commit
7a78bafa93
  1. 1
      modules/contest.js
  2. 4
      modules/problem.js
  3. 6
      utility.js

1
modules/contest.js

@ -87,6 +87,7 @@ app.post('/contest/:id/edit', async (req, res) => {
contest.ranklist_id = ranklist.id;
}
if (!req.body.trim()) throw new ErrorMessage('比赛名不能为空。');
contest.title = req.body.title;
if (!Array.isArray(req.body.problems)) req.body.problems = [req.body.problems];
contest.problems = req.body.problems.join('|');

4
modules/problem.js

@ -107,7 +107,7 @@ app.get('/problems/tag/:tagIDs', async (req, res) => {
}
let paginate = syzoj.utils.paginate(await Problem.count(sql), req.query.page, syzoj.config.page.problem);
let problems = await Problem.query(sql);
let problems = await Problem.query(sql + paginate.toSQL());
await problems.forEachAsync(async problem => {
problem.allowedEdit = await problem.isAllowedEditBy(res.locals.user);
@ -256,6 +256,7 @@ app.post('/problem/:id/edit', async (req, res) => {
}
}
if (!req.body.trim()) throw new ErrorMessage('题目名不能为空。');
problem.title = req.body.title;
problem.description = req.body.description;
problem.input_format = req.body.input_format;
@ -344,6 +345,7 @@ app.post('/problem/:id/import', async (req, res) => {
if (!json.success) throw new ErrorMessage('题目加载失败。', null, json.error);
if (!json.obj.trim()) throw new ErrorMessage('题目名不能为空。');
problem.title = json.obj.title;
problem.description = json.obj.description;
problem.input_format = json.obj.input_format;

6
utility.js

@ -270,7 +270,11 @@ module.exports = {
return {
currPage: currPage,
perPage: perPage,
pageCnt: pageCnt
pageCnt: pageCnt,
toSQL: () => {
if (!pageCnt) return '';
else return ` LIMIT ${(currPage - 1) * perPage},${perPage}`
}
};
},
removeTitleTag(s) {

Loading…
Cancel
Save