mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
core: add contest/[before-]add hook
This commit is contained in:
1 parent
5c388daba6
commit
2638606dae
2 files changed
+13
-4
No files matched your search
@@ -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(
|
||||
|
||||
@@ -2,13 +2,15 @@
|
||||
import cluster from 'cluster';
|
||||
import serialize from 'serialize-javascript';
|
||||
import cac from 'cac';
|
||||
import type { Db, FilterQuery, OnlyFieldsOfType } from 'mongodb';
|
||||
import type {
|
||||
Db, FilterQuery, ObjectID, OnlyFieldsOfType,
|
||||
} from 'mongodb';
|
||||
import type { Handler } from './server';
|
||||
import { Logger } from '../logger';
|
||||
import type {
|
||||
MessageDoc, ProblemDoc, RecordDoc,
|
||||
TrainingDoc, User, DiscussionDoc,
|
||||
DomainDoc, FileInfo,
|
||||
DomainDoc, FileInfo, Tdoc,
|
||||
} from '../interface';
|
||||
import type { DocType } from '../model/document';
|
||||
import type { ProblemSolutionHandler } from '../handler/problem';
|
||||
@@ -89,6 +91,9 @@ export interface EventMap extends Record<string, any> {
|
||||
'problem/addAdditionalFile': (domainId: string, docId: number, name: string, payload: Omit<FileInfo, '_id'>) => VoidReturn
|
||||
'problem/delAdditionalFile': (domainId: string, docId: number, name: string[]) => VoidReturn
|
||||
|
||||
'contest/before-add': (payload: Partial<Tdoc>) => VoidReturn
|
||||
'contest/add': (payload: Partial<Tdoc>, id: ObjectID) => VoidReturn
|
||||
|
||||
'training/list': (query: FilterQuery<TrainingDoc>, handler: any) => VoidReturn
|
||||
'training/get': (tdoc: TrainingDoc, handler: any) => VoidReturn
|
||||
|
||||
|
||||
Reference in new issue
Block a user