pos 请求接口 #45
This commit is contained in:
@@ -24,8 +24,11 @@
|
|||||||
* `pra` 业务操作 `praxic`
|
* `pra` 业务操作 `praxic`
|
||||||
- `can.ts` 操作权限
|
- `can.ts` 操作权限
|
||||||
- `doc.ts` 数据组合 `document`
|
- `doc.ts` 数据组合 `document`
|
||||||
- `que.ts` 查询接口 `query`
|
- `que.ts` 查询接口 `query` `HTTP GET` 对数据组合做请求
|
||||||
- `pas.ts` 用户登陆 `pass`
|
- `pas.ts` 用户登陆 `pass` (的操作组合)
|
||||||
|
- `pre.ts` 创建操作 `pre-data` `prepare` (的操作组合)
|
||||||
|
- `put.ts` 数据操作 `put-data`(的操作组合)
|
||||||
|
- `pos.ts` 请求接口 `post` `HTTP POST` 对操作组合做请求
|
||||||
* `ser.ts` 服务接口 `serve`
|
* `ser.ts` 服务接口 `serve`
|
||||||
* `tst` 测试代码 `tests`
|
* `tst` 测试代码 `tests`
|
||||||
|
|
||||||
|
20
src/pra/pos.ts
Normal file
20
src/pra/pos.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import { Ret } from "./can.ts"
|
||||||
|
import { Psg, pas, psg } from "./pas.ts"
|
||||||
|
|
||||||
|
export type Pos = Psg
|
||||||
|
export type PosRet = Ret<typeof psg>
|
||||||
|
|
||||||
|
export async function pos(
|
||||||
|
b: string,
|
||||||
|
jwt?: string,
|
||||||
|
) {
|
||||||
|
let json
|
||||||
|
try { json = b.length > 0 ? JSON.parse(b) as Pos : {} }
|
||||||
|
catch { return { ret: null } }
|
||||||
|
|
||||||
|
const p = jwt ? await pas(jwt) : null
|
||||||
|
|
||||||
|
if ("psg" in json) return psg(p, json)
|
||||||
|
|
||||||
|
return { ret: null }
|
||||||
|
}
|
33
tst/pos.test.ts
Normal file
33
tst/pos.test.ts
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import { db } from "../src/eid/db.ts"
|
||||||
|
import { is_utc } from "../src/eid/is.ts"
|
||||||
|
import { usr_c, usr_r } from "../src/eid/usr.ts"
|
||||||
|
import { PsgRet } from "../src/pra/pas.ts"
|
||||||
|
import { Pos, PosRet, pos } from "../src/pra/pos.ts"
|
||||||
|
import { assertEquals } from "./mod.test.ts"
|
||||||
|
|
||||||
|
await db("tst", true)
|
||||||
|
|
||||||
|
function json(
|
||||||
|
p: Pos
|
||||||
|
): string {
|
||||||
|
return JSON.stringify(p)
|
||||||
|
}
|
||||||
|
|
||||||
|
Deno.test("pas", async () => {
|
||||||
|
const nbr = "11111111111"
|
||||||
|
const usr = await usr_c(nbr, "四川", "成都")
|
||||||
|
assertEquals(1, usr)
|
||||||
|
assertEquals([
|
||||||
|
{ ret: null }, { ret: null }, { ret: null }
|
||||||
|
], await Promise.all([
|
||||||
|
pos(""), pos("", ""), pos(json({ psg: "pas" }), "invalidkey")
|
||||||
|
]))
|
||||||
|
assertEquals({ ret: { sms: false } }, await pos(json({ psg: "sms", nbr, sms: false })))
|
||||||
|
const { ret: sms } = await pos(json({ psg: "sms", nbr, sms: false })) as { ret: PsgRet["sms"] }
|
||||||
|
assertEquals(true, sms && !sms.sms && is_utc(sms.utc!))
|
||||||
|
const code = await usr_r({ nbr }, { sms: 1 })
|
||||||
|
const { ret: pas, jwt } = await pos(json({ psg: "code", nbr, code: code?.sms?.code! })) as PosRet & { ret: PsgRet["code"] }
|
||||||
|
assertEquals(true, pas && pas.usr == usr && jwt!.length > 0)
|
||||||
|
assertEquals({ ret: pas }, await pos(json({ psg: "pas" }), jwt!))
|
||||||
|
assertEquals({ ret: 1, jwt: null }, await pos(json({ psg: "clr", usr: pas!.usr }), jwt!))
|
||||||
|
})
|
Reference in New Issue
Block a user