core: add contest/[before-]add hook

This commit is contained in:
undefined committed 2021-06-29 16:55:49 +08:00
1 parent 5c388daba6
commit 2638606dae
2 files changed
+13 -4

No files matched your search

+6 -2
View File
@@ -12,6 +12,7 @@ import {
ScoreboardNode, ScoreboardRow, Tdoc,
Udict,
} from '../interface';
import * as bus from '../service/bus';
import * as misc from '../lib/misc';
import ranked from '../lib/rank';
@@ -402,7 +403,7 @@ function _getStatusJournal(tsdoc) {
return tsdoc.journal.sort((a, b) => (a.rid.generationTime - b.rid.generationTime));
}
export function add(
export async function add(
domainId: string, title: string, content: string, owner: number,
rule: string, beginAt = new Date(), endAt = new Date(), pids: ProblemId[] = [],
rated = false, data: Partial<Tdoc> = {}, type: Type = document.TYPE_CONTEST,
@@ -413,9 +414,12 @@ export function add(
content, owner, title, rule, beginAt, endAt, pids, attend: 0,
});
this.RULES[rule].check(data);
return document.add(domainId, content, owner, type, null, null, null, {
await bus.serial('contest/before-add', data);
const res = await document.add(domainId, content, owner, type, null, null, null, {
...data, title, rule, beginAt, endAt, pids, attend: 0, rated,
});
await bus.serial('contest/add', data, res);
return res;
}
export async function edit(