班级号 3~4 位并存,按用户名前缀/包含匹配时 ks251 会捞到 ks2510~ks2519。 新增 classPrefixCondition:ks + 3 位以上数字按具体班级匹配(后面不能再跟数字), 1~2 位仍是年级前缀。后台首页的用户排名、随机抽签,以及题单的学生进度筛选 (只填数字时补上 ks)都改用它。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
41cd141769
commit
23844ae301
4 files changed
+46
-9
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { ADMIN_ROLES, TEACHER_ROLES, type SampleUser } from "@oj2/contract"
|
||||
|
||||
import { and, count, eq, ilike, notInArray } from "drizzle-orm"
|
||||
import { and, count, eq, ilike, notInArray, sql } from "drizzle-orm"
|
||||
|
||||
import type { AuthUser } from "../auth/session"
|
||||
import { db, schema } from "../db"
|
||||
@@ -44,6 +44,22 @@ export function stripClassPrefix(
|
||||
return username.startsWith(prefix) ? username.slice(prefix.length) : username
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户名按「班级前缀」匹配:`ks251` 只匹配 251 班,**不能**把 `ks2511张三` 也捞进来。
|
||||
*
|
||||
* 班级号 3~4 位并存(见 admin/account.ts 的 classNameOf),裸 `ilike 'ks251%'` 会把
|
||||
* 2510~2519 班全算进 251 班。所以输入是 `ks` + 3 位以上数字时,要求紧跟着的不是数字;
|
||||
* 1~2 位(`ks25`)是年级前缀,照旧宽松匹配。输入不是 `ks+数字` 形状时返回 undefined,
|
||||
* 由调用方决定退回什么匹配方式。
|
||||
*/
|
||||
export function classPrefixCondition(input: string) {
|
||||
const matched = /^ks(\d+)$/i.exec(input)
|
||||
if (!matched) return undefined
|
||||
const prefix = ilike(schema.user.username, `${input}%`)
|
||||
if (matched[1]!.length < 3) return prefix
|
||||
return and(prefix, sql`${schema.user.username} !~* ${`^${input}[0-9]`}`)
|
||||
}
|
||||
|
||||
/**
|
||||
* 拿 query 里的筛选值去比对 `$type` 收窄过的列(`submission.result`、`problem.difficulty` 这些)。
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user