The API for /api/bulk-email/OT_3_5_TEST successfully resolved without sending a response, which could potentially cause delays in processing requests

My API is throwing an SQL error and not sending a response, despite passing all the correct inputs as far as I can tell.

This is how I call the database:

 const fetchData: any = async (po: any) => {
        const response: any = await axios.get(`/api/bulk-email/${po}`);
        //Data fetched...
    };

Here's the query I'm using in my API to interact with the database:

 `SELECT o.channel_order_id, oi.po, oi.id, p.product_id, oi.quantity, oi.scanned_qty,
            oi.qty_canceled, oi.channel_order_item_id, p.description, p.manufacturers_id, p.gtin, p.upc
            FROM shopper s INNER JOIN orders o on s.id = o.shopper_id INNER JOIN orderitems oi ON o.id = oi.order_id
            INNER JOIN products p ON oi.item_id = p.id
            WHERE oi.po = ? AND (oi.quantity > oi.scanned_qty or oi.scanned_qty is null);`,

This is where I set the value of PO:

const pullPOs = async () => {
        const response: any = await axios.get(`/api/get-pos`);
        setPOs(response.data);
    };

const handleSelectPO = (e: any) => {
        setPo(e.target.innerText);
        fetchData(e.target.innerText);
    };

When I console.log(po);, it returns the expected result. When I

console.log(fetchData(e.target.innerText));
, I get a pending promise. Likely due to the unresolved SQL error.

Here's the specific error message:

SqlError: Parameter at position 1 is undefined
SELECT o.channel_order_id, oi.po, oi.id, p.product_id, oi.quantity, oi.scanned_qty,
            oi.qty_canceled, oi.channel_order_item_id, p.description, p.manufacturers_id, p.gtin, p.upc
            FROM shopper s INNER JOIN orders o on s.id = o.shopper_i...
...
API resolved without sending a response for /api/bulk-email/OT_3_5_TEST, this may result in stalled requests.

This is the code snippet for the API:

import type { NextApiRequest, NextApiResponse } from 'next';
import * as pool from '../../../src/utils/dbConnection';
import console from 'console';
...

Thank you for any assistance provided!

Answer №1

I encountered an issue where po was not listed in the correct position within the array. After moving po to the first position (above channel_order_id), my SQL error was resolved successfully.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The error message "external.js: $ is not defined" indicates that

Recently, I integrated an external JavaScript file into my Angular 14 project. This JS file contains the event $('.class').click(). However, every time I launch the application on localhost, a message pops up in the browser stating that $ is not ...

Exploring the concept of indexing partial types in Typescript, utilizing react-hook-form to track dirty fields and update

When using react-hook-form, you can access the dirtyFields property which indicates updated fields with a value of true. v = { username: 'alice', email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="84e ...

Why does my array become empty once it exits the useEffect scope?

const [allJobs, setAllJobs] = useState([]); useEffect(() => { axios.get('http://localhost:3002/api/jobs') .then(res => setAllJobs(res.data)); allJobs.map((job, i) => { if (job.language.toLowerCas ...

Issue: TypeScript does not allow assigning a boolean type to either true or false when using two interfaces

When utilizing code similar to the one below, one would assume that TypeScript could infer that badObj is a valid argument for fn, as it should have the type Bad. Interestingly, within the body of fn there seems to be no issue. However, when calling fn(ba ...

The global CSS header element in Next.js is not being applied to parsed markdown files; instead, it is being replaced by Tailwind CSS

After attempting to convert Markdown into HTML, I encountered an issue. While the markdown parsed correctly, the rendered output did not match my expectations. Specifically, I expected the headers to automatically appear bold and with a larger font size, b ...

Guidelines on specifying the type for a component that is a union type

I came across a situation where I encountered a type error. Here is the case: https://codesandbox.io/s/stupefied-herschel-9lvmb?file=/src/App.tsx import * as React from "react"; import "./styles.css"; const A: React.FC<{ a: string } ...

Diving into the world of React and Typescript: Leveraging the power of Typescript in defining constants

Can you help me understand how to incorporate TypeScript into the code snippet below? I've been struggling for an hour and would really appreciate your guidance! In the code snippet, the map function utilizes sortOptions, which I attempted to define ...

The Value Entered in Angular is Unsaved

I have encountered an issue with my app's table functionality. The user can enter information into an input field and save it, but upon refreshing the page, the field appears empty as if no data was entered. Can someone please review my code snippet b ...

Using Typescript with Vue.js: Defining string array type for @Prop

How can I properly set the type attribute of the @Prop decorator to be Array<string>? Is it feasible? I can only seem to set it as Array without including string as shown below: <script lang="ts"> import { Component, Prop, Vue } from ...

I'm seeking assistance in grasping the concept of the useState generic definition. Can anyone help

I recently came across a new definition for useState generics in a TS course, but it was briefly covered and I'm still struggling to fully grasp it. function useState<S>(initialState: S | (() => S)): [S, Dispatch<SetStateAction<S>&g ...

Using a type guard with generic types

Currently, I am in the process of developing an API model that has the capability to provide two different types of outputs depending on whether the response was returned correctly or not. If the response is correct: IApiResponse<T>, where T denot ...

Comparing Node.JS using Typescript versus Javascript to Ruby On Rails

My question can be simplified as follows: 1. Does Ruby perform as well as Node with MongoDB? 2. Should I use Typescript or JavaScript with Node? I come from a .NET background (ASP.NET MVC) and am now venturing into creating an Angular project with a Mongo ...

The element is absent in Type {}, however, it is mandatory in Type '&' and '&' cannot be designated to String Index Type Errors

I have a goal of passing the logged-in user's email address to a 'dict' as a key, fetching its corresponding token value, and using it as a query parameter for an API call. The user's email is retrieved from the user data upon login, sp ...

What steps can I take to fix the TS2705 error in my TypeScript code?

Issue TS2705: The use of async functions or methods in ES5/ES3 requires the 'Promise' constructor. Please ensure that you have included a declaration for the 'Promise' constructor or added 'ES2015' to your --lib option. impor ...

Introduction: Utilizing Google Maps API with Angular-CLI - A Beginner's Guide

After just starting with ng2, I decided to create a project using angular-cli. However, I soon realized that I needed some third-party modules such as Google Maps API, Lodash, and JQuery. Although I have a basic understanding of Typescript, I was unsure ho ...

Exploring the New Features of NodeJS 13 and Typescript 3.8: A Guide to Importing esm Modules

I'm encountering difficulties with some imports in NodeJS related to the utilization of Typescript 3.8's advanced features such as private fields like #myPrivateField. I've been struggling to correctly import the "typescript" module into my ...

Configure Typescript to skip errors for a specific file

Is there a way to suppress TypeScript errors for specific files using the tsconfig.json file? I am aware of the exclude property mentioned on the TypeScript website, but that's not exactly what I'm looking for. As it's explained: If a fil ...

The JSX element with type 'Component' does not support any construct or call signatures at this time

I am facing an issue with the following code snippet const pageArea = (Component:ReactNode,title:string) => ({ ...props }) => { return ( <> <div> { Component && (<Component { ...

Electron window widens but does not shrink in size

Currently, I am utilizing electron to create an application where I am using ipc messages to expand and retract the width of the app. The frontend is able to trigger these ipc messages successfully, but for some reason, it refuses to go back to a width of ...

Issue: React cannot render Objects as children (received: [object Promise]). If you intended to display multiple children, please use an array instead. (Next)

My dilemma is this: I am trying to display my GitHub repositories on a React component, but I keep encountering the following error: Error: Objects are not valid as a React child (found: [object Promise]). If you meant to render a collection of children, u ...