Skip to content

Updated project working #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 121 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
"devDependencies": {
"@types/aws-lambda": "^8.10.86",
"@types/jest": "^26.0.10",
"@types/node": "^10.17.27",
"@types/node": "^16.18.0",
"aws-cdk-lib": "^2.80.0",
"constructs": "^10.0.0",
"esbuild": "^0.14.49",
"jest": "^29.7.0",
"ts-jest": "^29.2.3",
"ts-node": "^9.0.0",
"typescript": "~3.9.7"
"ts-node": "^10.9.1",
"typescript": "~4.9.5"
},
"dependencies": {
"@aws-lambda-powertools/logger": "^1.0.1",
Expand Down
8 changes: 5 additions & 3 deletions src/api/delete-product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ const lambdaHandler = async (event: APIGatewayProxyEvent): Promise<APIGatewayPro
headers: { "content-type": "application/json" },
body: JSON.stringify({ message: "Product deleted" }),
};
} catch (error) {
logger.error('Unexpected error occurred while trying to delete product with ID '+ id, error);
} catch (error: unknown) {
logger.error(`Unexpected error occurred while trying to delete product with ID ${id}`, {
error: error instanceof Error ? error.message : String(error)
});

return {
statusCode: 500,
Expand All @@ -59,4 +61,4 @@ const handler = middy(lambdaHandler)

export {
handler
};
};
8 changes: 5 additions & 3 deletions src/api/get-product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ const lambdaHandler = async (event: APIGatewayProxyEvent): Promise<APIGatewayPro
headers: { "content-type": "application/json" },
body: JSON.stringify(result),
};
} catch (error) {
logger.error('Unexpected error occurred while trying to retrieve a product', error);
} catch (error: unknown) {
logger.error('Unexpected error occurred while trying to retrieve a product', {
error: error instanceof Error ? error.message : String(error)
});

return {
statusCode: 500,
Expand All @@ -68,4 +70,4 @@ const handler = middy(lambdaHandler)

export {
handler
};
};
8 changes: 5 additions & 3 deletions src/api/get-products.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ const lambdaHandler = async (event: APIGatewayProxyEvent): Promise<APIGatewayPro
headers: { "content-type": "application/json" },
body: `{"products":${JSON.stringify(result)}}`,
};
} catch (error) {
logger.error('Unexpected error occurred while trying to retrieve products', error as Error);
} catch (error: unknown) {
logger.error('Unexpected error occurred while trying to retrieve a product', {
error: error instanceof Error ? error.message : String(error)
});

return {
statusCode: 500,
Expand All @@ -46,4 +48,4 @@ const handler = middy(lambdaHandler)

export {
handler
};
};
15 changes: 9 additions & 6 deletions src/api/put-product.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT-0
import { APIGatewayProxyEvent, APIGatewayProxyResult } from "aws-lambda";
import { Product } from "../model/product";
import { Product } from "../model/Product";
import { DynamoDbStore } from "../store/dynamodb/dynamodb-store";
import { ProductStore } from "../store/product-store";
import { captureLambdaHandler } from '@aws-lambda-powertools/tracer';
Expand Down Expand Up @@ -48,7 +48,9 @@ const lambdaHandler = async (event: APIGatewayProxyEvent): Promise<APIGatewayPro
throw Error("Parsed product is not an object")
}
} catch (error) {
logger.error('Unexpected error occurred while trying to create a product', error);
logger.error('Unexpected error occurred while trying to create a product', {
error: error instanceof Error ? error.message : String(error)
});

return {
statusCode: 400,
Expand Down Expand Up @@ -82,9 +84,10 @@ const lambdaHandler = async (event: APIGatewayProxyEvent): Promise<APIGatewayPro
headers: { "content-type": "application/json" },
body: JSON.stringify({ message: "Product created" }),
};
} catch (error) {
logger.error('Unexpected error occurred while trying to create a product', error);

} catch (error: unknown) {
logger.error('Unexpected error occurred while trying to create a product', {
error: error instanceof Error ? error.message : String(error)
});
return {
statusCode: 500,
headers: { "content-type": "application/json" },
Expand All @@ -100,4 +103,4 @@ const handler = middy(lambdaHandler)

export {
handler
};
};
2 changes: 1 addition & 1 deletion src/store/product-store.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT-0
import { Product } from "../model/product";
import { Product } from "../model/Product";

export interface ProductStore {
getProduct: (id: string) => Promise<Product | undefined>;
Expand Down
11 changes: 8 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"target": "ES2018",
"module": "commonjs",
"lib": [
"es2018"
"ES2018",
"DOM"
],
"declaration": true,
"strict": true,
Expand All @@ -21,10 +22,14 @@
"strictPropertyInitialization": false,
"typeRoots": [
"./node_modules/@types"
]
],
"outDir": "dist",
"forceConsistentCasingInFileNames": true,
"rootDir": "."
},
"exclude": [
"node_modules",
"cdk.out"
"cdk.out",
"dist"
]
}