refactor(契约): 前端 60 个写请求的请求体接上契约类型,前后端对不上编译期就报
Deploy / deploy (push) Canceled after 0s

- 前端 oj/api.ts、admin/api.ts、shared/api.ts 的 post / put 请求体一律 `satisfies XxxRequest`,
  只在编译期检查,不加运行时校验(和「只在三处挂运行时闸门」的规矩一致)
- 契约里的 XxxRequest 从 z.infer 改成 z.input:请求类型描述的是「客户端可以发什么」,
  带默认值的字段可以不传。后端从不用这些类型(它用 parse 出来的 data),不受影响
- 补了四个漏导出的请求类型(比赛题目排序、题单题目排序、标签分类、检查用户名)
- 接上之后对不上的几处:编辑用户的角色和题目权限经 toAdminType / toProblemPermission
  收窄,导入用户的行改成四元组,练习题数据改成 Record,格式化的语言只收后端认的四种
  (isFormatLanguage)。出题页和成就的请求体是「表单校验兜底、出站补默认值」,
  用 Partial<…> 只核键名和值的类型

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
xuyueandClaude Opus 5.5 committed 2026-10-16 15:03:58 +08:00
1 parent 309ca0ece2
commit 4dfd14f95b
18 files changed
+251 -131

No files matched your search

+2 -2
View File
@@ -1,6 +1,6 @@
import { defineStore } from "pinia"
import { errorCode, errorMessage } from "utils/api"
import { formatCode, submitCode } from "oj/api"
import { formatCode, isFormatLanguage, submitCode } from "oj/api"
import { useCodeStore } from "oj/store/code"
import { useProblemStore } from "oj/store/problem"
import { useSubmissionMonitor } from "oj/problem/composables/useSubmissionMonitor"
@@ -106,7 +106,7 @@ export const useSubmissionStore = defineStore("submission", () => {
// Python 在格式化之前先由服务端的 CPython 查一遍语法,有错就不提交;
// C / C++ 先在判题机上编一遍,编不过就原样交(格式化会把错的几行并成一行)
const formatLang = LANGUAGE_FORMAT_VALUE[codeStore.code.language]
if (["python", "c", "cpp", "sql"].includes(formatLang)) {
if (isFormatLanguage(formatLang)) {
isFormatting.value = true
try {
const res = await formatCode({