Error with the `this` keyword in TypeScript - value is undefined

I'm encountering an issue with my AWS Lambda function written in TypeScript that calls functions from different classes. The problem is that I am receiving 'undefined' for the existingProducts variable, even though it functions correctly when the React UI triggers a call to the function. Below is a snippet of my code which uses the 'this' keyword to reference methods from other classes within the current object's scope.

Entry point for the lambda

export const handler = async (upload: FileUpload, context: Context) => {
     .....code .....
     const parser = new ExcelValidator(new LookupService(), new ProductService());
     const status = await parser.performExistingUpcValidation(products as Product[], upload, workbook);
     return status

PerformExisitingUPCValidation

export class ExcelValidator {

    constructor(public lookupService: LookupService, public productService: ProductService) {

    }

    async performExistingUpcValidation(products: Product[], upload: FileUpload, workbook?: Workbook): Promise<FileStatus> {
       ...code...
       const existingProducts: any[] = await this.productService.getExistingProductsByUpcOrProductCode(productUpcs, productCodes);
       console.log("This is the exisitingProduct", existingProducts)
}

ProductServiceClass

export class ProductService {


    constructor() {
    }

    @Query(()=>[Product])
    async getExistingProductsByUpcOrProductCode(@Arg("upcs", ()=> [String]) upcs: string[], @Arg("productCodes", ()=> [String]) productCodes: string[]): Promise<Product[]> {
        console.log("I came here")
        let query = `SELECT * from table
            in (${upcs.join(",")})`;
        if(productCodes.length){
            query += ` OR "productCode" in ('${productCodes.join("','")}')`;
        }
        const results = await pool.snowflake?.execute(query);
        return results as Product[];
    }

Following the execution, I notice

This is the exisitingProduct undefined

indicating that my execution doesn't reach the ProductServiceClass. Can someone help me identify what could be wrong or missing? Any additional documentation or references would be greatly appreciated.

Answer №1

Consider evaluating the following code snippet:

let data = await connection.postgres?.query(sqlStatement);

Before proceeding, ensure that postgres is not null as you are allowing it to be undefined by using the optional chaining operator.

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

streaming an HTML5 video directly from memory source

After retrieving multiple encrypted data using ajax queries and performing necessary manipulations to turn them into a valid video, I find myself at a standstill. The binary of the video is now stored in memory, but I am unsure how to display it. To confi ...

Sending returned values from a promise to the calling function in Angular

I have a created a promise to retrieve values from a service and then assign them to variables trans and confidence, which should be used as transcript and conf in the save_data function. How can I return these values to the calling function and ensure tha ...

The component does not contain the specified property

One Angular 4 component that I have is like this: export class MenuComponent { constructor(private menuService: MenuService) { } @Input(nodes):any; getMenu(path:string): void { this.menuService.getData(path).subscribe(data => { // Re ...

Guidelines for displaying user profile information in the dashboard page through an Angular project, considering the different user types (user, super user, admin)

In my application, I have implemented the dashboard feature. There are three types of dashboards: the regular user dashboard, super user dashboard, and admin dashboard. The super user and admin dashboards include additional tables along with the data from ...

Exploring the method to retrieve data on the server side through Express when it is shared by the client within a put request

Here is the angular http put request I am working with: sendPutRequest(data) : Observable<any>{ return this.http.put("http://localhost:5050", data).pipe(map(this.handleData)); } After making this call, the server side method being invoked is ...

using async/await to retrieve data from a Google spreadsheet in Node.js

How can I use a for-loop to iterate through sheets in a Google spreadsheet and access specific cells within each sheet? I have a Google spreadsheet with Sheet1, Sheet2,... , Sheet5 where the cell values are Value1,..., Value5. The expected result should be ...

The attribute 'map' is not found on the object of type 'List'

I am currently working on a project that involves lists, each with its own title. However, while using Map, I encountered the following error: Property 'map' does not exist on type 'List' Any suggestions on how to resolve this issue? ...

What is the best way to import all Vue3 components asynchronously?

I've been struggling to get the components to work properly. My goal is to store component names in an array, import them asynchronously, and then somehow assign them to app.component. I've spent about six hours on this and just can't seem t ...

Creating a drop-down menu within an HTML table along with a D3 bar chart

How can I implement a drop-down menu allowing the user to choose a time interval for this HTML table and d3 bar chart? The time intervals needed are: Now, 24 hours, 48 hours, 72 hours, 1 week, and 1 month. I am relatively new to creating dynamic tables and ...

Action triggered by clicking a button for every individual table column button

Managing my visitor records is made easier with a visitor table that allows me to add and display visitors. Each entry in the table includes a set of sign-in and sign-out buttons placed in two columns. Whenever I click the sign-in button, the current times ...

Narrowing Types Based on a Conditional List of Keys

Below is the code snippet I am currently working with: type AlphaNumeric = string | number | null | boolean | undefined; type AlphaNumericKeys<T> = { [key in keyof T]: key extends string ? (T[key] extends AlphaNumeric ? key : never) : never; }[k ...

Tips for organizing the router.js file in VueJs

With my router.js file currently reaching around 500 lines, I’m looking for a better way to structure it. { path: "/", component: () => import("./../src/views/dashboard/Dashboard.vue"), meta: { auth ...

What are the steps to incorporate a jquery-ui checkbox into a widget?

I have encountered an issue where using a jquery-ui checkbox within a container that has the class ui-widget-content is causing a problem with the CSS rules. Specifically, the ".ui-widget-content .ui-state-hover" rule is overriding the .ui-icon-check rule, ...

Using AJAX to dynamically update a DIV when there are changes in the XML data

After dedicating the past four years to solving this problem intermittently, my brain is feeling the strain. I serve as a volunteer designer for a local community project involving a radio station. Our "On Air" module showcases the current and upcoming tr ...

Changing a Javascript Array into a string with delimiters

I have a Javascript array of strings that contain alphanumeric values such as A12, B50, C105. My goal is to convert this array into a pipe delimited string format like: A12|B50|C105... Can anyone guide me on how to achieve this? I am specifically working ...

Having trouble configuring Angular-UI Router to work properly with Apache server

My web app is running on my PC through an Apache server, but I'm having issues with the routing provided by ui.route. It seems that the simple state I defined is never being reached. To troubleshoot, I added a wildcard to catch all paths and found th ...

Utilizing AJAX to dynamically update div content within an overlay

Can someone please help me figure out what is going on with my code. I have 3 links, each with a data-action and an ID number. When I click on the links, nothing happens. It seems like it's not fetching the data from my ajax request (action.php). H ...

.fetchevery(...).then has no function

I recently upgraded Angular to version 1.6.4. As a result, I made changes to the code by replacing .success and .error with .then However, now I am encountering the following error: An unexpected TypeError occurred: .getAll(...).then is not a function ...

Using Behavior Subject for pagination in Angular with RxJS

Currently, I am creating a filtering system for a product list based on category IDs using the RXJS operator BehaviorSubject. However, I have encountered an issue with implementing infinite scrolling with Behavior Subject because I am unable to access the ...

How can I execute a synchronous MongoDB query in Node.js properly?

When utilizing the Node.JS driver for MongoDB, I am interested in executing a synchronous query. Here is an example of what I am aiming to achieve: function retrieveSomething() { var database = new mongo.Db("mydatabase", server, {}); database.ope ...