core: fix problem_edit returns null

This commit is contained in:
undefined committed 2021-03-08 19:29:04 +08:00
1 parent b240a46057
commit 391eb96b22
3 files changed
+10 -4

No files matched your search

+3 -3
View File
@@ -323,14 +323,14 @@ export class ProblemEditHandler extends ProblemManageHandler {
@post('tag', Types.String, true, null, parseCategory)
async post(
domainId: string, pid: string | number, title: string, content: string,
newPid: string = '', hidden = false, tag: string[],
newPid: string = '', hidden = false, tag: string[] = [],
) {
try {
content = JSON.parse(content);
} catch { /* Ignore */ }
if (newPid !== this.pdoc.pid && await problem.get(domainId, newPid)) throw new BadRequestError('new pid exists');
const $update: Partial<Pdoc> = {
title, content, pid: newPid, hidden, tag,
title, content, pid: newPid, hidden, tag: tag ?? [],
};
let pdoc = await problem.get(domainId, pid);
await bus.serial('problem/before-edit', $update);
@@ -560,7 +560,7 @@ export class ProblemCreateHandler extends Handler {
content = JSON.parse(content);
} catch { /* Ignore */ }
if (pid && await problem.get(domainId, pid)) throw new BadRequestError('invalid pid');
const docId = await problem.add(domainId, pid, title, content, this.user._id, tag, hidden);
const docId = await problem.add(domainId, pid, title, content, this.user._id, tag ?? [], hidden);
this.response.body = { pid: pid || docId };
this.response.redirect = this.url('problem_files', { pid: pid || docId });
}