diff --git a/cli/json.ts b/cli/json.ts index 79b83a0..25c41de 100644 --- a/cli/json.ts +++ b/cli/json.ts @@ -19,7 +19,7 @@ await Promise.all(uid.map(async ({ _id }) => { rec_of_uid(coll.fund, [_id]), ]) await Deno.writeTextFile(`json/u${_id}.json`, JSON.stringify({ - ...u, worker, work, fund + ...u, rec: { worker, work, fund } })) })) await Promise.all(sid.map(async ({ _id }) => { @@ -30,7 +30,7 @@ await Promise.all(sid.map(async ({ _id }) => { rec_of_sid(coll.fund, _id), ]) await Deno.writeTextFile(`json/s${_id}.json`, JSON.stringify({ - ...s, worker, work, fund + ...s, rec: { worker, work, fund } })) })) await Promise.all(a.map(async ({ _id }) => { @@ -55,5 +55,5 @@ export type Rec = { } export type Agenda = typeof a[0] export type Recent = typeof r -export type User = Awaited> & Rec -export type Soc = Awaited> & Rec +export type User = Awaited> & { rec: Rec } +export type Soc = Awaited> & { rec: Rec } diff --git a/ismism.ts/src/query/agenda.ts b/ismism.ts/src/query/agenda.ts index e079469..4a2f2c2 100644 --- a/ismism.ts/src/query/agenda.ts +++ b/ismism.ts/src/query/agenda.ts @@ -5,10 +5,10 @@ export async function agenda( ) { const a = await coll.agenda.find().sort({ _id: -1 }).toArray() return Promise.all(a.map(async a => { - const [nrec, dat] = await Promise.all([ + const [rec, dat] = await Promise.all([ nrec_of_aid(a._id), dat_of_aid(a._id), ]) - return { ...a, ...nrec, dat } + return { ...a, rec, dat } })) } diff --git a/ismism.ts/src/query/soc.ts b/ismism.ts/src/query/soc.ts index 1d3764f..d8166e0 100644 --- a/ismism.ts/src/query/soc.ts +++ b/ismism.ts/src/query/soc.ts @@ -26,9 +26,9 @@ export async function soc( if (sid === 0) return null const s = await soc_of_sid(sid) if (s === null) return null - const [nrec, uname] = await Promise.all([ + const [rec, uname] = await Promise.all([ nrec_of_uid(s.uid), idname(coll.user, s.uid), ]) - return { ...s, ...nrec, uname } + return { ...s, rec, uname } } diff --git a/ismism.ts/src/query/user.ts b/ismism.ts/src/query/user.ts index a55712f..4959d25 100644 --- a/ismism.ts/src/query/user.ts +++ b/ismism.ts/src/query/user.ts @@ -14,11 +14,11 @@ export async function user( uid: number ) { if (uid === 0) return null - const [u, soc, nrec] = await Promise.all([ + const [u, soc, rec] = await Promise.all([ user_of_uid(uid), soc_of_uid(uid), nrec_of_uid([uid]), ]) if (u === null) return null - return { ...u, soc, ...nrec } + return { ...u, soc, rec } } diff --git a/ismism.ts/tst/query.test.ts b/ismism.ts/tst/query.test.ts index f2c7664..c473edd 100644 --- a/ismism.ts/tst/query.test.ts +++ b/ismism.ts/tst/query.test.ts @@ -8,7 +8,7 @@ Deno.test("user", async () => { const u = await user(728) console.log(u) assert(u && u.name === "万大可") - assert(u.worker === 1 && u.work === 1 && u.fund === 0) + assert(u.rec.worker === 1 && u.rec.work === 1 && u.rec.fund === 0) const [worker, work, fund] = await Promise.all([ rec_of_uid(coll.worker, [728]), rec_of_uid(coll.work, [728]), @@ -24,8 +24,9 @@ Deno.test("soc", async () => { assert(s && s.name === "主义主义软件开发") const uname = new Map(s.uname) assert(uname.get(s.uid[1]) === "万大可") - assert(s.worker === 2) - assert(s.work === 3) + assert(s.rec.worker === 2) + assert(s.rec.work === 3) + assert(s.rec.fund === 0) const [worker, work, fund] = await Promise.all([ rec_of_sid(coll.worker, 2), rec_of_sid(coll.work, 2), @@ -47,7 +48,7 @@ Deno.test("agenda", async () => { console.log(worker, work, fund) assert(a.length === 4 && a4._id === 4) assert(a4.dat?.typ === "imgsrc" && a1.dat === null) - assert(worker.rec.length === a1.worker) - assert(work.rec.length === a1.work) - assert(fund.rec.length === a1.fund) + assert(worker.rec.length === a1.rec.worker) + assert(work.rec.length === a1.rec.work) + assert(fund.rec.length === a1.rec.fund) }) diff --git a/ismism.ts/ui/bind.ts b/ismism.ts/ui/bind.ts index c39e31b..4547d7b 100644 --- a/ismism.ts/ui/bind.ts +++ b/ismism.ts/ui/bind.ts @@ -268,8 +268,10 @@ window.addEventListener("hashchange", () => { async function load( ) { - agenda = await json("agenda") - recent = await json("recent") + [agenda, recent] = await Promise.all([ + await json("agenda"), + await json("recent"), + ]) window.dispatchEvent(new Event("hashchange")) }