fix admin.

This commit is contained in:
2023-03-14 12:25:48 +08:00
parent b3ec4ef63e
commit 477cece1e7
9 changed files with 153 additions and 79 deletions

47
src/admin/api.ts Normal file
View File

@@ -0,0 +1,47 @@
import http from "utils/http"
import { DIFFICULTY } from "~/utils/constants"
import { getACRate } from "~/utils/functions"
import { Problem } from "~/utils/types"
function filterResult(result: Problem) {
const newResult = {
id: result.id,
_id: result._id,
title: result.title,
difficulty: DIFFICULTY[result.difficulty],
tags: result.tags,
submission: result.submission_number,
rate: getACRate(result.accepted_number, result.submission_number),
status: "",
}
if (result.my_status === null || result.my_status === undefined) {
newResult.status = "not_test"
} else if (result.my_status === 0) {
newResult.status = "passed"
} else {
newResult.status = "failed"
}
return newResult
}
export async function getProblemList(
offset = 0,
limit = 10,
searchParams: any = {}
) {
let params: any = {
paging: true,
offset,
limit,
}
Object.keys(searchParams).forEach((element) => {
if (searchParams[element]) {
params[element] = searchParams[element]
}
})
const res = await http.get("admin/problem", { params })
return {
results: res.data.results.map(filterResult),
total: res.data.total,
}
}