refactor(题目): 新建 / 复制题目收成 validateProblem、insertProblem、copyProblem
admin/problem.ts 里四处 insert(schema.problem) 其实是两对重复: - 新建公开题 / 新建比赛题:公共校验 + SQL 展示数据 + 插入 + 写标签,逐行一样, 只差 contestId。编辑题目那条也抄了同一段校验。收成 validateProblem(校验 + 展示数据)和 insertProblem(插入 + 标签,一个事务)。比赛题当初就是抄漏了 sqlDisplay,现在三条路径只有一份 - 比赛题转公开 / 从公开题库拉进比赛:复制整行 + 统计清零 + 复制标签,收成 copyProblem 顺带 db/index.ts 加 DbOrTx 类型,四处 `tx as unknown as typeof db` 去掉。 唯一的行为差异:编辑题目时 SQL 展示数据的生成挪到了题号查重之前(和新建一致), 两项同时出错时报的是前一个。 实跑核过:新建公开题、编辑、重复题号 409、新建比赛题、比赛题转公开(不可见、 标签跟过去)、从公开题库拉进比赛(可见、标签跟过去),SQL 题测试点缺失时照样拦下。 测试数据已删。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f2ca34fd4b
commit
925cecb389
3 files changed
+139
-153
No files matched your search
@@ -10,6 +10,14 @@ const client = postgres(config.databaseUrl)
|
||||
|
||||
export const db = drizzle(client, { schema })
|
||||
|
||||
/**
|
||||
* 「库或事务」都能接的参数类型。辅助函数既要能单独调、又要能在事务里调时用它,
|
||||
* 别再写 `tx as unknown as typeof db` —— 那个断言把两者的差异(事务上没有
|
||||
* `$client`、`batch` 等)一并抹掉了。
|
||||
*/
|
||||
export type DbOrTx =
|
||||
typeof db | Parameters<Parameters<typeof db.transaction>[0]>[0]
|
||||
|
||||
/**
|
||||
* 读出来的时刻统一成 ISO 8601 UTC,和写侧的 `new Date().toISOString()` 同形状。
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user