diff --git a/src/pra/doc.ts b/src/pra/doc.ts index a0f0e45..c30380b 100644 --- a/src/pra/doc.ts +++ b/src/pra/doc.ts @@ -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 } +} diff --git a/src/pra/que.ts b/src/pra/que.ts index 26173fd..352cace 100644 --- a/src/pra/que.ts +++ b/src/pra/que.ts @@ -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, soc: Ret, agd: Ret, + cdt: Ret, + dbt: Ret, + ern: Ret, } 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 diff --git a/tst/que.test.ts b/tst/que.test.ts index 745d0fa..ef55736 100644 --- a/tst/que.test.ts +++ b/tst/que.test.ts @@ -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()) })