feat: 8 条功能 + 身份口径改为号码布为准(含批量退赛/移出、基础数据导入导出、登录有效期)
用户给出的 8 条功能 + 一条口径变更,全部带真机/真浏览器验证:
① 录入页姓名后直接显示号码布(原「号码」列保留)
② 录入页批次进度条:`第 2 批 已录 5/8 · 3 条有错`,录完变绿;已录判据复用
entryGuards.judgeEntryRow(与发布防呆同源,不会出现"进度条说录完、发布说缺 8 条")
⑦ 小项列表双击 → 跳到该小项的组别(编辑/删除按钮不误触)
③ 赛事开关 `standings.live_on_publish`(默认开=保持原行为):关闭后分批发布只上屏成绩,
名次/流水/榜单一起等该组录完再结算 —— 代理实读代码后纠正了我的前提:
奖牌榜读的是 results.rank(buildRanked)而非流水汇总,只延迟流水会出现
「有金牌但 0 分」。另提供 POST /api/results/settle 人工兜底 + GET /api/results/settlement 未结算清单
④ 组别「就地更新」PUT /api/events/{id}/categories/{categoryId}:有报名数据时也能改名/改年龄/
改性别/改权重(旧路径是整表替换,一改就被 409 拦下);改名不动报名/成绩/流水(真机逐字节比对);
权重真的变了才触发该组重算(容差 1e-9)
④辅 运动员列表多选+全选,POST /api/athletes/batch 一次请求完成整批停用/彻底删除(逐条回报,
dryRun 预览走同一段 SQL 但不提交、不写审计)——这才是绕开限流的正解
新增 报名项批量:POST /api/entries/batch(scratch/restore/remove)。退赛只动 registered、
跳过 dq/dns 并说明原因;移出是物理删除,必须显式清 score_ledger(该表 entry_id 是
ON DELETE SET NULL,不显式删会留下"人没了分还在"的孤儿流水,验证基线 orphan=0);
退赛同时清 results.rank(否则出现"0 分还挂着金牌")
⑤ GET /api/export/entries.xlsx 报名名单导出(13 列含批次,状态中文与录入页逐字一致)
⑥ 基础数据包:GET /api/export/basedata.xlsx + POST /api/export/basedata/import
(四张表、表头只有一份定义、表头行自动定位、列缺席≠写空、按编码 upsert、绝不删除、
行级中文错误带真实 Excel 行号、枚举走既有校验、新增单位一定是启用)
⑧ 登录有效期面板可配:系统设置新页签,1–720 小时,默认 12h → 24h;滑动续期 +
Cookie 同步刷新(只服务端续期是假的,浏览器侧的 Max-Age 到点仍会丢 Cookie)
身份口径:号码布为唯一标识、证件号退出匹配(号码布不同=同名的两个人,新建并单独报告);
同一份表重复证件号不再报错;两个不同的人共用证件号仍报行级错误(唯一索引保留)
其它对齐:分项成绩表草稿行不再消失(成绩列「分数未录入」、名次/积分 `—`,没成绩的行同占位);
大屏实时赛况单栏铺满(留白 370→78px)、字号上限 56→96px、≥7 行自动拆左右两块;
删除报名项/退赛/权重等改动都会重算并推榜单。
测试:服务端 13 包(连跑两遍)、前端 335 例、vue-tsc + build、Console 18 文件 —— 全绿。
文档:README、docs/ 四份(含 debug/使用说明 副本)、devdocs 05/08/04/13。
版本号 dev_0.1.5 → dev_0.1.6。
This commit is contained in:
1 parent
8dd599bd97
commit
631c8dd8e1
80 files changed
+12468
-519
No files matched your search
@@ -0,0 +1,149 @@
|
||||
import { test } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { ApiError } from '@/shared'
|
||||
import { ENTRY_BATCH_PATH, submitEntryBatch } from '../pages/entryBatch'
|
||||
|
||||
/**
|
||||
* 报名项批量操作的请求契约:方法 / 路径 / 请求体字段必须与服务端
|
||||
* internal/httpapi/entries_batch.go 的 entryBatchPayload 一致;
|
||||
* 写请求漏掉 X-CSRF-Token 会被中间件 403,现场只会看到「删不掉」。
|
||||
*/
|
||||
|
||||
interface Captured {
|
||||
url?: string
|
||||
method?: string
|
||||
headers?: Record<string, string>
|
||||
body?: unknown
|
||||
credentials?: string
|
||||
}
|
||||
|
||||
let lastRequest: Captured = {}
|
||||
let reply: () => Response = () => jsonResponse({ ok: true, data: { items: [], summary: emptySummary() } })
|
||||
|
||||
function jsonResponse(body: unknown, status = 200): Response {
|
||||
return new Response(JSON.stringify(body), {
|
||||
status,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
})
|
||||
}
|
||||
|
||||
function emptySummary() {
|
||||
return {
|
||||
ok: 0,
|
||||
failed: 0,
|
||||
skipped: 0,
|
||||
changed: 0,
|
||||
removedEntries: 0,
|
||||
removedResults: 0,
|
||||
removedLedger: 0,
|
||||
removedBreaks: 0,
|
||||
recomputedEvents: [],
|
||||
}
|
||||
}
|
||||
|
||||
globalThis.fetch = (async (input: unknown, init?: RequestInit) => {
|
||||
lastRequest = {
|
||||
url: String(input),
|
||||
method: init?.method ?? 'GET',
|
||||
headers: (init?.headers ?? {}) as Record<string, string>,
|
||||
body: init?.body === undefined ? undefined : JSON.parse(String(init.body)),
|
||||
credentials: init?.credentials,
|
||||
}
|
||||
return reply()
|
||||
}) as typeof fetch
|
||||
|
||||
function respondWith(response: () => Response): void {
|
||||
lastRequest = {}
|
||||
reply = response
|
||||
}
|
||||
|
||||
test('批量操作走 POST /api/entries/batch,body 带 action + ids', async () => {
|
||||
respondWith(() =>
|
||||
jsonResponse({
|
||||
ok: true,
|
||||
data: {
|
||||
items: [{ id: 1, ok: true }],
|
||||
summary: { ...emptySummary(), ok: 1, changed: 1, recomputedEvents: [3] },
|
||||
},
|
||||
}),
|
||||
)
|
||||
|
||||
const result = await submitEntryBatch({ action: 'scratch', ids: [1, 1, 2] })
|
||||
|
||||
assert.equal(lastRequest.url, ENTRY_BATCH_PATH)
|
||||
assert.equal(lastRequest.method, 'POST')
|
||||
assert.equal(lastRequest.credentials, 'include')
|
||||
assert.equal((lastRequest.body as { action: string }).action, 'scratch')
|
||||
assert.deepEqual((lastRequest.body as { ids: number[] }).ids, [1, 1, 2])
|
||||
// 写请求必须有 requestId(幂等)与 JSON 内容类型。
|
||||
assert.equal(typeof (lastRequest.body as { requestId?: unknown }).requestId, 'string')
|
||||
assert.equal(lastRequest.headers?.['Content-Type'], 'application/json; charset=utf-8')
|
||||
assert.deepEqual(result.summary.recomputedEvents, [3])
|
||||
})
|
||||
|
||||
// 已登录写请求必须带 CSRF:漏掉就是 403,退赛 / 移出都不会生效。
|
||||
test('带 csrf_token Cookie 时补上 X-CSRF-Token', async () => {
|
||||
const original = (globalThis as { document?: unknown }).document
|
||||
;(globalThis as { document?: unknown }).document = { cookie: 'a=1; csrf_token=tok-123; b=2' }
|
||||
try {
|
||||
respondWith(() => jsonResponse({ ok: true, data: { items: [], summary: emptySummary() } }))
|
||||
await submitEntryBatch({ action: 'restore', ids: [2] })
|
||||
assert.equal(lastRequest.headers?.['X-CSRF-Token'], 'tok-123')
|
||||
} finally {
|
||||
if (original === undefined) delete (globalThis as { document?: unknown }).document
|
||||
else (globalThis as { document?: unknown }).document = original
|
||||
}
|
||||
})
|
||||
|
||||
test('没有 document(非浏览器环境)时不带 CSRF,也不报错', async () => {
|
||||
respondWith(() => jsonResponse({ ok: true, data: { items: [], summary: emptySummary() } }))
|
||||
await submitEntryBatch({ action: 'remove', ids: [3] })
|
||||
assert.equal(lastRequest.headers?.['X-CSRF-Token'], undefined)
|
||||
})
|
||||
|
||||
// 服务端的中文原文要原样传给页面;批量里的逐条失败也在 data 里,不能被当成请求失败。
|
||||
test('服务端报错时原样抛出 code 与中文 message', async () => {
|
||||
respondWith(() => jsonResponse({ ok: false, error: { code: 'VALIDATION_FAILED', message: '一次最多处理 500 条报名项,请分批提交' } }, 400))
|
||||
await assert.rejects(
|
||||
() => submitEntryBatch({ action: 'remove', ids: [1] }),
|
||||
(error: unknown) => {
|
||||
assert.ok(error instanceof ApiError)
|
||||
assert.equal(error.code, 'VALIDATION_FAILED')
|
||||
assert.match(error.message, /分批提交/)
|
||||
return true
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
test('逐条失败(ok:false)仍算成功响应,由页面逐条提示', async () => {
|
||||
respondWith(() =>
|
||||
jsonResponse({
|
||||
ok: true,
|
||||
data: {
|
||||
items: [
|
||||
{ id: 1, ok: true },
|
||||
{ id: 999999, ok: false, error: '报名项不存在' },
|
||||
],
|
||||
summary: { ...emptySummary(), ok: 1, failed: 1 },
|
||||
},
|
||||
}),
|
||||
)
|
||||
const result = await submitEntryBatch({ action: 'remove', ids: [1, 999999] })
|
||||
assert.equal(result.summary.failed, 1)
|
||||
assert.equal(result.items[1]?.error, '报名项不存在')
|
||||
})
|
||||
|
||||
test('网络不可达时报「没有生效」,不能让操作员以为已经删掉了', async () => {
|
||||
respondWith(() => {
|
||||
throw new TypeError('fetch failed')
|
||||
})
|
||||
await assert.rejects(
|
||||
() => submitEntryBatch({ action: 'remove', ids: [1] }),
|
||||
(error: unknown) => {
|
||||
assert.ok(error instanceof ApiError)
|
||||
assert.equal(error.code, 'NETWORK')
|
||||
assert.match(error.message, /没有生效/)
|
||||
return true
|
||||
},
|
||||
)
|
||||
})
|
||||
Reference in new issue
Block a user