From f8820a9008b0b2c65cab309ec9422570726aa70f Mon Sep 17 00:00:00 2001 From: thezzisu Date: Sun, 21 Jan 2024 15:09:48 +0800 Subject: [PATCH] feat: allow ranklist manual update runner --- .yarn/versions/0a49b7c1.yml | 3 ++ .../contest/[contestId]/admin/index.vue | 17 +++++++- apps/server/src/routes/contest/admin.ts | 40 ++++++++++++------- 3 files changed, 45 insertions(+), 15 deletions(-) create mode 100644 .yarn/versions/0a49b7c1.yml diff --git a/.yarn/versions/0a49b7c1.yml b/.yarn/versions/0a49b7c1.yml new file mode 100644 index 0000000..85ee0e5 --- /dev/null +++ b/.yarn/versions/0a49b7c1.yml @@ -0,0 +1,3 @@ +releases: + "@aoi-js/frontend": patch + "@aoi-js/server": patch diff --git a/apps/frontend/src/pages/org/[orgId]/contest/[contestId]/admin/index.vue b/apps/frontend/src/pages/org/[orgId]/contest/[contestId]/admin/index.vue index ca89e21..423cef9 100644 --- a/apps/frontend/src/pages/org/[orgId]/contest/[contestId]/admin/index.vue +++ b/apps/frontend/src/pages/org/[orgId]/contest/[contestId]/admin/index.vue @@ -19,14 +19,20 @@ > {{ t('action.submit-all') }} + {{ t('action.update-ranklists') }} + + {{ t('reset-runner') }} + + {{ t('action.delete') }} @@ -58,6 +64,7 @@ import AccessLevelEditor from '@/components/utils/AccessLevelEditor.vue' import { useAsyncTask } from '@/utils/async' import { http } from '@/utils/http' import { useAsyncState } from '@vueuse/core' +import { ref } from 'vue' import { useI18n } from 'vue-i18n' import { useRouter } from 'vue-router' @@ -97,8 +104,14 @@ const ranklistInfo = useAsyncState( { immediate: true } ) +const resetRunner = ref(false) + const updateRanklistsTask = useAsyncTask(() => - http.post(`contest/${props.contestId}/admin/update-ranklists`) + http + .post(`contest/${props.contestId}/admin/update-ranklists`, { + json: { resetRunner: resetRunner.value } + }) + .then(() => ranklistInfo.execute()) ) async function deleteContest() { @@ -111,11 +124,13 @@ async function deleteContest() { en: ranklist-state: Ranklist State is {state} + reset-runner: Switch Reset Runner action: submit-all: Submit all solutions update-ranklists: Update ranklists zh-Hans: ranklist-state: '排行榜状态: {state}' + reset-runner: 切换重置运行器 action: submit-all: 提交所有解答 update-ranklists: 更新排行榜 diff --git a/apps/server/src/routes/contest/admin.ts b/apps/server/src/routes/contest/admin.ts index 1e0a00e..90a47e3 100644 --- a/apps/server/src/routes/contest/admin.ts +++ b/apps/server/src/routes/contest/admin.ts @@ -105,21 +105,33 @@ export const contestAdminRoutes = defineRoutes(async (s) => { } ) - s.post('/update-ranklists', async (req) => { - await contests.updateOne( - { - _id: req.inject(kContestContext)._contestId, - ranklists: { $exists: true, $ne: [] } - }, - { - $set: { - ranklistUpdatedAt: req._now, - ranklistState: ContestRanklistState.INVALID - } + s.post( + '/update-ranklists', + { + schema: { + body: Type.Object({ + resetRunner: Type.Optional(Type.Boolean()) + }) } - ) - return 0 - }) + }, + async (req) => { + await contests.updateOne( + { + _id: req.inject(kContestContext)._contestId, + ranklists: { $exists: true, $ne: [] } + }, + { + $set: { + ranklistUpdatedAt: req._now, + ranklistState: ContestRanklistState.INVALID + }, + $unset: req.body.resetRunner ? { ranklistRunnerId: 1 } : {} + }, + { ignoreUndefined: true } + ) + return 0 + } + ) s.get( '/stages',