add route that takes a request body based on excel file version R6

This commit is contained in:
Paul Trowbridge 2023-09-29 12:47:34 -04:00
parent e350170e5a
commit 3cfd63d708
1 changed files with 37 additions and 0 deletions

37
api.ts
View File

@ -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());