Skip to content

Commit

Permalink
feat: allow ranklist manual update runner
Browse files Browse the repository at this point in the history
  • Loading branch information
thezzisu committed Jan 21, 2024
1 parent 259ede1 commit f8820a9
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .yarn/versions/0a49b7c1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
releases:
"@aoi-js/frontend": patch
"@aoi-js/server": patch
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,20 @@
>
{{ t('action.submit-all') }}
</VBtn>

<VBtn
color="red"
variant="elevated"
@click="updateRanklistsTask.execute()"
:loading="updateRanklistsTask.isLoading.value"
:append-icon="resetRunner ? 'mdi-refresh' : 'mdi-pin'"
>
{{ t('action.update-ranklists') }}
</VBtn>
<VBtn color="red" variant="outlined" @click="resetRunner = !resetRunner">
{{ t('reset-runner') }}
</VBtn>

<VBtn color="red" variant="elevated" @click="deleteContest()">
{{ t('action.delete') }}
</VBtn>
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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() {
Expand All @@ -111,11 +124,13 @@ async function deleteContest() {
<i18n>
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: 更新排行榜
Expand Down
40 changes: 26 additions & 14 deletions apps/server/src/routes/contest/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit f8820a9

Please sign in to comment.