que dst
This commit is contained in:
@ -123,7 +123,7 @@ export function is_dstid(
|
||||
): dstid is Dst["_id"] {
|
||||
const l = Object.keys(dstid).length
|
||||
return 1 <= l && l <= 3 && is_lim(dstid.rd, lim_rd)
|
||||
&& (l === 2 && is_id(dstid.aid!) || l === 3 && is_id(dstid.uid!))
|
||||
&& (l === 1 || l === 2 && is_id(dstid.aid!) || l === 3 && is_id(dstid.uid!))
|
||||
}
|
||||
|
||||
export function is_aut(
|
||||
|
@ -9,6 +9,8 @@ import { id, idnam, nid_of_adm } from "../eid/id.ts"
|
||||
import { aut_g, aut_r } from "../eid/aut.ts"
|
||||
import { md_f, md_r } from "../eid/md.ts"
|
||||
import { ord_a, ord_f } from "../eid/ord.ts"
|
||||
import { dst_f, dst_n, dst_r } from "../eid/dst.ts"
|
||||
import { lim_rd } from "../eid/is.ts"
|
||||
|
||||
export async function nid(
|
||||
) {
|
||||
@ -119,6 +121,19 @@ export async function live(
|
||||
return { live: l, unam, anam }
|
||||
}
|
||||
|
||||
export async function dst(
|
||||
) {
|
||||
const [rd, rdaid] = await Promise.all([
|
||||
dst_r({ rd: lim_rd }), dst_f({ rd: lim_rd })
|
||||
])
|
||||
if (rd === null || rdaid === null) return null
|
||||
const aid = rdaid.map(r => r._id.aid!)
|
||||
const ndst = await Promise.all(aid.map(a => dst_n({ rd: lim_rd, aid: a })))
|
||||
const dst = aid.map((aid, n) => ({ aid, ndst: ndst[n] ?? 0 })).sort((a, b) => b.ndst - a.ndst)
|
||||
const anam = await idnam(coll.agd, aid)
|
||||
return { rd: rd.json, dst, anam }
|
||||
}
|
||||
|
||||
export async function aut(
|
||||
) {
|
||||
const a = await aut_g()
|
||||
|
@ -1,7 +1,7 @@
|
||||
import type { Ret } from "./can.ts"
|
||||
import { is_id, is_nbr } from "../eid/is.ts"
|
||||
import { coll } from "../db.ts"
|
||||
import { agd, aut, live, md, nid, ord, rec, soc, usr } from "./doc.ts"
|
||||
import { agd, aut, dst, live, md, nid, ord, rec, soc, usr } from "./doc.ts"
|
||||
import { id, idnam } from "../eid/id.ts"
|
||||
import { nord_f } from "../eid/ord.ts"
|
||||
|
||||
@ -12,6 +12,7 @@ export type Agd = Ret<typeof agd>
|
||||
export type Ord = Ret<typeof ord>
|
||||
export type Rec = Ret<typeof rec>
|
||||
export type Live = Ret<typeof live>
|
||||
export type Dst = Ret<typeof dst>
|
||||
export type Aut = Ret<typeof aut>
|
||||
export type Md = Ret<typeof md>
|
||||
|
||||
@ -53,6 +54,8 @@ export async function que(
|
||||
} break
|
||||
} case "live": {
|
||||
return await live()
|
||||
} case "dst": {
|
||||
return await dst()
|
||||
} case "aut": {
|
||||
return await aut()
|
||||
} case "md": {
|
||||
|
@ -10,7 +10,7 @@ import { md_c, md_f, md_r, md_u } from "../src/eid/md.ts"
|
||||
import { aut_c, aut_d, aut_g } from "../src/eid/aut.ts"
|
||||
import { utc_h } from "../src/ont/utc.ts"
|
||||
import { ord_c, ord_d, ord_f, ord_r, ord_u } from "../src/eid/ord.ts"
|
||||
import { dst_c, dst_f, dst_n } from "../src/eid/dst.ts"
|
||||
import { dst_c, dst_f, dst_n, dst_r } from "../src/eid/dst.ts"
|
||||
import { lim_rd } from "../src/eid/is.ts"
|
||||
|
||||
await db("tst", true)
|
||||
@ -158,14 +158,16 @@ Deno.test("rec", async () => {
|
||||
|
||||
Deno.test("dst", async () => {
|
||||
assertEquals(0, await dst_n({ rd: lim_rd, aid: 1 }))
|
||||
const rd = { _id: { rd: lim_rd }, json: JSON.stringify({ nam: "nam", c: 32 }) }
|
||||
await Promise.all([
|
||||
dst_c({ _id: { rd: lim_rd }, json: JSON.stringify({ nam: "nam", c: 32 }) }),
|
||||
dst_c(rd),
|
||||
dst_c({ _id: { rd: lim_rd, aid: 1 } }),
|
||||
dst_c({ _id: { rd: lim_rd, aid: 2 } }),
|
||||
dst_c({ _id: { rd: lim_rd, aid: 1, uid: 1 } }),
|
||||
dst_c({ _id: { rd: lim_rd, aid: 1, uid: 2 } }),
|
||||
dst_c({ _id: { rd: lim_rd, aid: 2, uid: 2 } }),
|
||||
])
|
||||
]) // deno-lint-ignore no-explicit-any
|
||||
assertEquals(rd as any, await dst_r({ rd: lim_rd }))
|
||||
assertEquals(2, await dst_n({ rd: lim_rd, aid: 1 }))
|
||||
assertEquals(1, await dst_n({ rd: lim_rd, uid: 1 }))
|
||||
assertEquals([{ _id: { rd: lim_rd, aid: 1 } }, { _id: { rd: lim_rd, aid: 2 } }], await dst_f({ rd: lim_rd }))
|
||||
|
@ -5,8 +5,10 @@ import { rec_c } from "../src/eid/rec.ts"
|
||||
import { md_c } from "../src/eid/md.ts"
|
||||
import { soc_c, soc_u } from "../src/eid/soc.ts"
|
||||
import { usr_c } from "../src/eid/usr.ts"
|
||||
import { Agd, Md, Ord, que, Rec, Soc, Usr } from "../src/pra/que.ts"
|
||||
import { Agd, Dst, Md, Ord, que, Rec, Soc, Usr } from "../src/pra/que.ts"
|
||||
import { ord_c } from "../src/eid/ord.ts"
|
||||
import { dst_c } from "../src/eid/dst.ts";
|
||||
import { lim_rd } from "../src/eid/is.ts";
|
||||
|
||||
await db("tst", true)
|
||||
const utc = Date.now()
|
||||
@ -33,6 +35,12 @@ await Promise.all([
|
||||
rec_c(coll.work, { _id: { uid: 2, aid: 1, utc: utc + 1 }, rej: [], ref: [], work: "video", nam: "nam", src: "src" }),
|
||||
rec_c(coll.fund, { _id: { uid: 1, aid: 1, utc }, fund: 100, msg: "fund" }),
|
||||
rec_c(coll.fund, { _id: { uid: 3, aid: 2, utc: utc + 1 }, fund: 100, msg: "fund" }),
|
||||
dst_c({ _id: { rd: lim_rd }, json: JSON.stringify({ nam: "nam", c: 32 }) }),
|
||||
dst_c({ _id: { rd: lim_rd, aid: 1 } }),
|
||||
dst_c({ _id: { rd: lim_rd, aid: 2 } }),
|
||||
dst_c({ _id: { rd: lim_rd, aid: 1, uid: 1 } }),
|
||||
dst_c({ _id: { rd: lim_rd, aid: 1, uid: 2 } }),
|
||||
dst_c({ _id: { rd: lim_rd, aid: 2, uid: 2 } }),
|
||||
await md_c(coll.wsl, { nam: "标题一", uid: 1 }),
|
||||
md_c(coll.wsl, { nam: "标题二", uid: 2 }),
|
||||
md_c(coll.lit, { nam: "标题一", uid: 2 }),
|
||||
@ -114,6 +122,12 @@ Deno.test("rec", async () => {
|
||||
assertEquals(fund_aid2, fund_sid2)
|
||||
})
|
||||
|
||||
Deno.test("dst", async () => {
|
||||
const dst = await que("dst", p({})) as Dst
|
||||
assertEquals({ nam: "nam", c: 32 }, JSON.parse(dst?.rd!))
|
||||
assertEquals([{ aid: 1, ndst: 2 }, { aid: 2, ndst: 1 }], dst?.dst)
|
||||
})
|
||||
|
||||
Deno.test("md", async () => {
|
||||
const wsl = await que("md", p({ wslid: 0, f: "" })) as Md
|
||||
const lit = await que("md", p({ litid: 0, f: "" })) as Md
|
||||
|
Reference in New Issue
Block a user