From 1e7b9e8953d63b4e837d39ee6088343392d33770 Mon Sep 17 00:00:00 2001 From: 728 Date: Tue, 31 Oct 2023 22:39:51 +0800 Subject: [PATCH] cdt #43 --- ismism.ts/src/eid/rec.ts | 2 +- ismism.ts/src/pra/doc.ts | 6 +++--- ismism.ts/src/pra/pas.ts | 4 ++-- ismism.ts/src/pra/pre.ts | 6 +++--- ismism.ts/tst/eid.test.ts | 12 ++++++------ 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/ismism.ts/src/eid/rec.ts b/ismism.ts/src/eid/rec.ts index 55c5583..bc9a996 100644 --- a/ismism.ts/src/eid/rec.ts +++ b/ismism.ts/src/eid/rec.ts @@ -54,7 +54,7 @@ export async function cdt_u( } catch { return null } } -export async function cdt_a< +export async function cdt_f< P extends keyof Cdt, >( id: { usr: Cdt["_id"]["usr"] } | { soc: Cdt["_id"]["soc"] } | Omit, diff --git a/ismism.ts/src/pra/doc.ts b/ismism.ts/src/pra/doc.ts index fb0267b..664f7cf 100644 --- a/ismism.ts/src/pra/doc.ts +++ b/ismism.ts/src/pra/doc.ts @@ -3,7 +3,7 @@ import { coll } from "../eid/db.ts" import { id, idadm, idnam } from "../eid/id.ts" import { is_id } from "../eid/is.ts" import { msg_r, msg_f } from "../eid/msg.ts" -import { cdt_a, rec_f, rec_s } from "../eid/rec.ts" +import { cdt_f, rec_f, rec_s } from "../eid/rec.ts" import { soc_r } from "../eid/soc.ts" import { Agd, Msg, Rec, Soc, Usr } from "../eid/typ.ts" import { usr_r } from "../eid/usr.ts" @@ -25,7 +25,7 @@ export async function usr( if (!u) return null const [sec, cdt, cdt_s, dbt_s, ern_s] = await Promise.all([ // deno-lint-ignore no-explicit-any id(coll.soc, { sec: u._id } as any), - cdt_a({ usr: u._id }, { now: Date.now() }, { amt: 1, utc: 1 }), + cdt_f({ usr: u._id }, { now: Date.now() }, { amt: 1, utc: 1 }), rec_s(coll.cdt, { usr: u._id }, {}), rec_s(coll.dbt, { usr: u._id }, {}), rec_s(coll.ern, { usr: u._id }, {}), @@ -46,7 +46,7 @@ export async function soc( ) { const [s, a, c, cdt_s, dbt_s, ern_s] = await Promise.all([ soc_r(soc), id(coll.agd, { soc }), - cdt_a({ soc }, { now: Date.now() }, { _id: 1 }), + cdt_f({ soc }, { now: Date.now() }, { _id: 1 }), rec_s(coll.cdt, { soc }, {}), rec_s(coll.dbt, { soc }, {}), rec_s(coll.ern, { soc }, {}), diff --git a/ismism.ts/src/pra/pas.ts b/ismism.ts/src/pra/pas.ts index c113680..93ec597 100644 --- a/ismism.ts/src/pra/pas.ts +++ b/ismism.ts/src/pra/pas.ts @@ -6,7 +6,7 @@ import { usr_r, usr_u } from "../eid/usr.ts" import { utc_h } from "../ont/utc.ts" import { smssend } from "../ont/sms.ts" import { is_id, is_jwt, len_code, lim_code } from "../eid/is.ts" -import { cdt_a } from "../eid/rec.ts" +import { cdt_f } from "../eid/rec.ts" import { id } from "../eid/id.ts" import { aut_r } from "../eid/aut.ts" import { soc_r } from "../eid/soc.ts" @@ -27,7 +27,7 @@ async function pas_of_usr( ): DocR { if (!is_id(u._id)) return null const [cdt, sec, aut] = await Promise.all([ - cdt_a({ usr: u._id }, { now: Date.now() }, { _id: 1, utc: 1 }), // deno-lint-ignore no-explicit-any + cdt_f({ usr: u._id }, { now: Date.now() }, { _id: 1, utc: 1 }), // deno-lint-ignore no-explicit-any id(coll.soc, { sec: u._id } as any), aut_r() ]) diff --git a/ismism.ts/src/pra/pre.ts b/ismism.ts/src/pra/pre.ts index ea542a1..a2a044f 100644 --- a/ismism.ts/src/pra/pre.ts +++ b/ismism.ts/src/pra/pre.ts @@ -2,7 +2,7 @@ import type { Agd, Cdt, Dbt, Ern, Lit, Soc, Usr, Wsl } from "../eid/typ.ts" import { agd_c } from "../eid/agd.ts" import { coll } from "../eid/db.ts" import { msg_c } from "../eid/msg.ts" -import { cdt_a, rec_c, rec_s } from "../eid/rec.ts" +import { cdt_f, rec_c, rec_s } from "../eid/rec.ts" import { soc_c, soc_r } from "../eid/soc.ts" import { usr_c } from "../eid/usr.ts" import { Ret, is_pre } from "./can.ts" @@ -66,12 +66,12 @@ export async function pre( return s ? agd_c(p.nam, s.adm1, s.adm2, p.soc) : null } case "cdt": { const { _id: { usr, soc, utc }, msg, amt, sec, utc: { eft, exp } } = p.cdt - const a = await cdt_a({ usr, soc }, { eft, exp }, { _id: 1 }) + const a = await cdt_f({ usr, soc }, { eft, exp }, { _id: 1 }) if (a && a.length > 0 || !is_id(sec!)) return null return rec_c(coll.cdt, { _id: { usr, soc, utc }, msg, amt, sec, utc: { eft, exp, agr: 0 } }) } case "dbt": { const { _id: { usr, soc, utc }, msg, amt } = p.dbt - const a = await cdt_a({ usr, soc }, { now: utc }) + const a = await cdt_f({ usr, soc }, { now: utc }) if (!a || a.length == 0) return null const [d] = await rec_s(coll.dbt, { usr, soc }, { frm: a[0].utc.eft }) if (a[0].amt >= (d ? d.amt : 0) + p.dbt.amt) return rec_c(coll.dbt, { _id: { usr, soc, utc }, msg, amt }) diff --git a/ismism.ts/tst/eid.test.ts b/ismism.ts/tst/eid.test.ts index ea3580e..6e331ef 100644 --- a/ismism.ts/tst/eid.test.ts +++ b/ismism.ts/tst/eid.test.ts @@ -2,7 +2,7 @@ import { agd_c, agd_d, agd_r, agd_u } from "../src/eid/agd.ts" import { aut_r, aut_u } from "../src/eid/aut.ts" import { db, coll } from "../src/eid/db.ts" import { msg_c, msg_f, msg_r, msg_u } from "../src/eid/msg.ts" -import { rec_c, rec_d, rec_f, rec_s, cdt_a, rec_r, cdt_u } from "../src/eid/rec.ts" +import { rec_c, rec_d, rec_f, rec_s, cdt_f, rec_r, cdt_u } from "../src/eid/rec.ts" import { soc_c, soc_d, soc_r, soc_u } from "../src/eid/soc.ts" import { usr_c, usr_d, usr_r, usr_u } from "../src/eid/usr.ts" import { assertEquals } from "./mod.test.ts" @@ -61,13 +61,13 @@ Deno.test("rec", async () => { rec_c(coll.cdt, { _id: { usr, soc, utc: utc + 2 }, msg, amt, utc: { eft: 3, exp: 5, agr: 0 } }), ]) assertEquals([await rec_r(coll.cdt, { usr, soc, utc })], await rec_f(coll.cdt, { usr }, utc + 1)) - assertEquals(2, (await cdt_a({ usr }, { now: 4 }))?.length) - assertEquals(3, (await cdt_a({ usr, soc }, { eft: 1, exp: 5 }))?.length) - assertEquals(2, (await cdt_a({ soc }, { eft: 3, exp: 4 }))?.length) - assertEquals(0, (await cdt_a({ usr, soc }, { eft: 5, exp: 6 }))?.length) + assertEquals(2, (await cdt_f({ usr }, { now: 4 }))?.length) + assertEquals(3, (await cdt_f({ usr, soc }, { eft: 1, exp: 5 }))?.length) + assertEquals(2, (await cdt_f({ soc }, { eft: 3, exp: 4 }))?.length) + assertEquals(0, (await cdt_f({ usr, soc }, { eft: 5, exp: 6 }))?.length) assertEquals(1, await cdt_u(usr, soc, utc + 10)) assertEquals({ _id: { usr, soc, utc: utc + 2 }, utc: { eft: 3, exp: 5, agr: utc + 10 } }, - (await cdt_a({ usr, soc }, { now: 4 }, { utc: 1 }))![0]) + (await cdt_f({ usr, soc }, { now: 4 }, { utc: 1 }))![0]) assertEquals([{ soc, amt: 3 }], await rec_s(coll.cdt, { usr }, {})) assertEquals([{ soc, amt: 2 }], await rec_s(coll.cdt, { soc }, { now: 4 }))