rec 记录查询 #45

This commit is contained in:
728
2023-11-18 09:12:36 +08:00
parent e9d2668788
commit cf2bf0d8bc
3 changed files with 21 additions and 2 deletions

View File

@ -1,4 +1,4 @@
import type { Agd, Soc, Usr } from "../eid/typ.ts"
import type { Agd, Rec, Soc, Usr } from "../eid/typ.ts"
import { coll } from "../eid/db.ts"
import { id, idadm, idnam } from "../eid/id.ts"
import { usr_r } from "../eid/usr.ts"
@ -76,3 +76,16 @@ export async function agd(
const [soc] = await idnam(coll.soc, [a.soc])
return { ...a, soc }
}
export async function rec(
q: "cdt" | "dbt" | "ern",
id: { usr: Rec["_id"]["usr"] } | { soc: Rec["_id"]["soc"] },
utc: Rec["_id"]["utc"],
) {
const r = await rec_f(coll[q], id, { to: utc })
const [usr, soc] = await Promise.all([
idnam(coll.usr, r.flatMap(({ _id: { usr }, sec }) => sec ? [usr, sec] : [usr])),
idnam(coll.soc, r.map(r => r._id.soc)),
])
return { rec: r, usr, soc }
}

View File

@ -1,7 +1,7 @@
import type { Agd, Msg, Rec, Soc, Usr } from "../eid/typ.ts"
import { json } from "../ont/json.ts"
import { Ret } from "./can.ts"
import { adm, agd, soc, usr } from "./doc.ts"
import { adm, agd, rec, soc, usr } from "./doc.ts"
export type Que = {
que: "adm",
@ -35,6 +35,9 @@ export type QueRet = {
usr: Ret<typeof usr>,
soc: Ret<typeof soc>,
agd: Ret<typeof agd>,
cdt: Ret<typeof rec>,
dbt: Ret<typeof rec>,
ern: Ret<typeof rec>,
}
export function que(
@ -47,6 +50,8 @@ export function que(
case "usr": return usr("nam" in q ? { nam: q.nam } : { _id: q.usr })
case "soc": return soc(q.soc)
case "agd": return agd(q.agd)
case "cdt": case "dbt": case "ern":
return rec(q.que, "usr" in q ? { usr: q.usr } : { soc: q.soc }, q.utc)
}
return null

View File

@ -53,4 +53,5 @@ Deno.test("que", async () => {
assertEquals(usr, { ...await que(`?que="usr"&nam="用户"`) as QueRet["usr"], utc: now })
assertEquals(soc, { ...await que(`?que="soc"&soc=1`) as QueRet["soc"], utc: now })
assertEquals(agd, { ...await que(`?que="agd"&agd=1`) as QueRet["agd"], utc: now })
assertEquals(cdt, (await que(`?que="cdt"&usr=2&utc=0`) as QueRet["cdt"])?.rec.reverse())
})