From 0912f69ad9e11e970cdd36da8db7930f78fdc934 Mon Sep 17 00:00:00 2001 From: Sean Michael Wykes <8363933+cryptographix@users.noreply.github.com> Date: Mon, 6 May 2024 16:17:03 -0300 Subject: [PATCH] Upd for OAK v16 --- .../server/api-pix-server/api-pix-server.ts | 16 ++++++++-------- .../pix-server/server/api-pix-server/helpers.ts | 13 +++++-------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/packages/pix-server/server/api-pix-server/api-pix-server.ts b/packages/pix-server/server/api-pix-server/api-pix-server.ts index 86f52e3..c53bacd 100644 --- a/packages/pix-server/server/api-pix-server/api-pix-server.ts +++ b/packages/pix-server/server/api-pix-server/api-pix-server.ts @@ -7,7 +7,7 @@ import { CobIdentifier, CobListIdentifier, PixApiCobService } from "../../../api import { MemoryCobStore } from "./memory-cob-data-store.ts"; import { MemoryLocStore } from "./memory-loc-data-store.ts"; -import { getBodyJSON, getRouteParams, getQueryParams } from "./helpers.ts"; +import { getBodyJSON } from "./helpers.ts"; function convertDate(s: string): Date { return new Date(s); @@ -33,8 +33,8 @@ export function cobRouter( router .get(path + "/" + cobType, async (context) => { - let rawParams = getQueryParams(context); - let pag = { + const rawParams = context.params; + const pag = { paginaAtual: rawParams["paginacao.paginaAtual"], itensPorPagina: rawParams["paginacao.itensPorPagina"], } @@ -81,7 +81,7 @@ export function cobRouter( // context.response.body = "Hello world!"; }) .get(path + "/" + cobType + "/:txid", async (context) => { - const { txid } = getRouteParams(context); + const { txid } = context.params; try { const id: CobIdentifier = { @@ -98,15 +98,15 @@ export function cobRouter( } }) .post(path + "/" + cobType + "/:txid", async (context) => { - const body = context.request.body(); + const body = context.request.body; console.log( context.request.headers ); console.log( body.type ); - console.log( await (body.value) ); + console.log( await (body.text) ); context.response.body = "OK"; }) .put(path + "/" + cobType + "/:txid", async (context) => { - const { txid } = getRouteParams(context); + const { txid } = context.params; console.log(txid); const cobIn = await getBodyJSON(context); @@ -126,7 +126,7 @@ export function cobRouter( } }) .patch(path + "/" + cobType + "/:txid", async (context) => { - const { txid } = getRouteParams(context); + const { txid } = context.params; console.log(txid); const cobIn = await getBodyJSON(context); diff --git a/packages/pix-server/server/api-pix-server/helpers.ts b/packages/pix-server/server/api-pix-server/helpers.ts index 78c2a6f..9b2086f 100644 --- a/packages/pix-server/server/api-pix-server/helpers.ts +++ b/packages/pix-server/server/api-pix-server/helpers.ts @@ -1,19 +1,16 @@ -import { RouterContext, helpers } from "https://deno.land/x/oak/mod.ts"; +import { RouterContext } from "https://deno.land/x/oak/mod.ts"; -const { getQuery } = helpers; -export const getQueryParams = getQuery; - -export function getRouteParams( context: RouterContext ): A { +export function getRouteParams( context: RouterContext ): A { const params = context.params ?? {}; return params as unknown as A; } -export async function getBodyJSON( context: RouterContext ): Promise { +export async function getBodyJSON( context: RouterContext ): Promise { if ( context.request.hasBody ) { - const body = context.request.body( {type: 'json' }); + const body = context.request.body.json(); - return (await body.value) as unknown as A; + return (await body) as unknown as A; } else { return null as unknown as A;