mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 09:46:28 +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,
|
ScoreboardNode, ScoreboardRow, Tdoc,
|
||||||
Udict,
|
Udict,
|
||||||
} from '../interface';
|
} from '../interface';
|
||||||
|
import * as bus from '../service/bus';
|
||||||
import * as misc from '../lib/misc';
|
import * as misc from '../lib/misc';
|
||||||
import ranked from '../lib/rank';
|
import ranked from '../lib/rank';
|
||||||
|
|
||||||
@@ -402,7 +403,7 @@ function _getStatusJournal(tsdoc) {
|
|||||||
return tsdoc.journal.sort((a, b) => (a.rid.generationTime - b.rid.generationTime));
|
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,
|
domainId: string, title: string, content: string, owner: number,
|
||||||
rule: string, beginAt = new Date(), endAt = new Date(), pids: ProblemId[] = [],
|
rule: string, beginAt = new Date(), endAt = new Date(), pids: ProblemId[] = [],
|
||||||
rated = false, data: Partial<Tdoc> = {}, type: Type = document.TYPE_CONTEST,
|
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,
|
content, owner, title, rule, beginAt, endAt, pids, attend: 0,
|
||||||
});
|
});
|
||||||
this.RULES[rule].check(data);
|
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,
|
...data, title, rule, beginAt, endAt, pids, attend: 0, rated,
|
||||||
});
|
});
|
||||||
|
await bus.serial('contest/add', data, res);
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function edit(
|
export async function edit(
|
||||||
|
|||||||
@@ -2,13 +2,15 @@
|
|||||||
import cluster from 'cluster';
|
import cluster from 'cluster';
|
||||||
import serialize from 'serialize-javascript';
|
import serialize from 'serialize-javascript';
|
||||||
import cac from 'cac';
|
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 type { Handler } from './server';
|
||||||
import { Logger } from '../logger';
|
import { Logger } from '../logger';
|
||||||
import type {
|
import type {
|
||||||
MessageDoc, ProblemDoc, RecordDoc,
|
MessageDoc, ProblemDoc, RecordDoc,
|
||||||
TrainingDoc, User, DiscussionDoc,
|
TrainingDoc, User, DiscussionDoc,
|
||||||
DomainDoc, FileInfo,
|
DomainDoc, FileInfo, Tdoc,
|
||||||
} from '../interface';
|
} from '../interface';
|
||||||
import type { DocType } from '../model/document';
|
import type { DocType } from '../model/document';
|
||||||
import type { ProblemSolutionHandler } from '../handler/problem';
|
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/addAdditionalFile': (domainId: string, docId: number, name: string, payload: Omit<FileInfo, '_id'>) => VoidReturn
|
||||||
'problem/delAdditionalFile': (domainId: string, docId: number, name: string[]) => 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/list': (query: FilterQuery<TrainingDoc>, handler: any) => VoidReturn
|
||||||
'training/get': (tdoc: TrainingDoc, handler: any) => VoidReturn
|
'training/get': (tdoc: TrainingDoc, handler: any) => VoidReturn
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user