From 3cfd63d708d34d9be1878bea1be92734792d5ccb Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Fri, 29 Sep 2023 12:47:34 -0400 Subject: [PATCH] add route that takes a request body based on excel file version R6 --- api.ts | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/api.ts b/api.ts index bbf0f29..3bd8239 100644 --- a/api.ts +++ b/api.ts @@ -50,6 +50,43 @@ router.get('/sales_walk/write_note/:ship_cust/:bucket/:notes', async (ctx) => { }); +router.post('/sales_walk/flag_cust', async (ctx) => { + try { + const currentTime = new Date().toLocaleString('en-US', { timeZone: 'America/New_York' }); + console.log("------------------------",currentTime,"-----------------------------") + const clientIp = ctx.request.ip; + console.log('Client IP:', clientIp); + //console.log('URL:', ctx.request.url); + //console.log('Method:', ctx.request.method); + + // Log headers + //console.log('Headers:', [...ctx.request.headers].map(header => `${header[0]}: ${header[1]}`).join(', ')); + + // Get the body object to log the type + //const body = await ctx.request.body(); + //console.log('Body Type:', body.type); // Logging the body type + + // Log the body as text + const bodyText = await ctx.request.body({ type: 'text' }).value; + console.log('Body Text:', bodyText); + + // If you expect a JSON body, you can then parse it + if (ctx.request.hasBody) { + const body = JSON.parse(bodyText); + console.log("Body JSON:", body); + const { ship_cust, bucket, notes } = body; // Destructure the needed values from the JSON + const result = await client.queryObject({args: [ship_cust, bucket, notes], text: query} ); + } + + } catch (error) { + console.error('Error:', error.message); + ctx.response.status = 500; + ctx.response.body = { error: 'Internal Server Error' }; + } + +}); + + app.use(router.routes()); app.use(router.allowedMethods());