core: allow user to manually end contest early (#1147)

This commit is contained in:
Baoshuo authored and GitHub committed 2026-04-28 04:26:02 +08:00
1 parent d8a5716a22
commit 125c4b2388
9 files changed
+99 -40

No files matched your search

+4 -2
View File
@@ -62,12 +62,14 @@ export function isNotStarted(tdoc: Tdoc) {
export function isOngoing(tdoc: Tdoc, tsdoc?: any) {
const now = new Date();
if (tsdoc?.endAt && tsdoc.endAt <= now) return false;
if (tsdoc && tdoc.duration && tsdoc.startAt <= new Date(Date.now() - Math.floor(tdoc.duration * Time.hour))) return false;
return (tdoc.beginAt <= now && now < tdoc.endAt);
}
export function isDone(tdoc: Tdoc, tsdoc?: any) {
if (tdoc.endAt <= new Date()) return true;
if (tsdoc?.endAt && tsdoc.endAt <= new Date()) return true;
if (tsdoc && tdoc.duration && tsdoc.startAt <= new Date(Date.now() - Math.floor(tdoc.duration * Time.hour))) return true;
return false;
}
@@ -940,8 +942,8 @@ export function getMultiStatus(domainId: string, query: any) {
return document.getMultiStatus(domainId, document.TYPE_CONTEST, query);
}
export function setStatus(domainId: string, tid: ObjectId, uid: number, $set: any) {
return document.setStatus(domainId, document.TYPE_CONTEST, tid, uid, $set);
export function setStatus(domainId: string, tid: ObjectId, uid: number, $set?: any, $unset?: any) {
return document.setStatus(domainId, document.TYPE_CONTEST, tid, uid, $set, $unset);
}
export function count(domainId: string, query: any) {
+7 -2
View File
@@ -295,11 +295,16 @@ export function getMultiStatusWithoutDomain<K extends keyof DocStatusType>(
export async function setStatus<K extends keyof DocStatusType>(
domainId: string, docType: K, docId: DocStatusType[K]['docId'], uid: number,
args: UpdateFilter<DocStatusType[K]>['$set'], returnDocument: 'before' | 'after' = 'after',
$set: UpdateFilter<DocStatusType[K]>['$set'] | null,
$unset?: UpdateFilter<DocStatusType[K]>['$unset'] | null,
returnDocument: 'before' | 'after' = 'after',
): Promise<DocStatusType[K]> {
const op: UpdateFilter<DocStatusType[K]> = {};
if ($set && Object.keys($set).length) op.$set = $set;
if ($unset && Object.keys($unset).length) op.$unset = $unset;
return await collStatus.findOneAndUpdate(
{ domainId, docType, docId, uid },
{ $set: args },
op,
{
upsert: true,
returnDocument,
+1 -1
View File
@@ -74,7 +74,7 @@ class SolutionModel {
if (!doc) throw new SolutionNotFoundError(domainId, psid);
const before = await document.setStatus(
domainId, document.TYPE_PROBLEM_SOLUTION, psid, uid,
{ vote: value }, 'before',
{ vote: value }, null, 'before',
);
let inc = value;
if (before?.vote) inc -= before.vote;