This commit is contained in:
728
2023-10-31 22:39:51 +08:00
parent c6438e998b
commit 1e7b9e8953
5 changed files with 15 additions and 15 deletions

View File

@ -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<Cdt["_id"], "utc">,

View File

@ -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 }, {}),

View File

@ -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<Pas> {
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()
])

View File

@ -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 })

View File

@ -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 }))