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.