Skip to content
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

Session 2 : adding dynamo db #2

Open
wants to merge 3 commits into
base: session-2-v2
Choose a base branch
from

Conversation

guillaumeduboc
Copy link
Owner

No description provided.

@guillaumeduboc guillaumeduboc requested review from thibaudlemaire and removed request for thibaudlemaire October 21, 2021 12:06
@guillaumeduboc guillaumeduboc changed the title Session 2 v2 adding dynamo db Session 2 : adding dynamo db Oct 21, 2021

return success({ viruses });
export const main: APIGatewayProxyHandler = async () => {
return documentClient.query({TableName: "dojo-serverless-table"}, function(err, data) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tu peux faire sans la callback, avec un async/await et un try/catch

try {
await documentClient
.delete({
TableName: 'dojo-serverless-table',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tu peux mettre ça dans une constante


const documentClient = new DynamoDB.DocumentClient();

export const main: APIGatewayProxyHandler = async ({ pathParameters }) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tu peux typer pathParameters

Comment on lines 76 to 92
const addVirus = async () => {
console.log('Implement the post route first!');
// const response = await fetch(
// `${process.env.REACT_APP_API_BASE_URL}/virus`,
// { method: 'POST' },
// );
// const { id } = await response.json();
// setViruses((prevViruses) => prevViruses.concat(getRandomVirus(id)));
// console.log('Implement the post route first!');
const response = await fetch(
`${process.env.REACT_APP_API_BASE_URL}/virus`,
{ method: 'POST' },
);
const { id } = await response.json();
setViruses((prevViruses) => prevViruses.concat(getRandomVirus(id)));
};

const killVirus = async (virusId: string) => {
console.log('Implement the delete route first!');
// await fetch(`${process.env.REACT_APP_API_BASE_URL}/virus/${virusId}`, {
// method: 'DELETE',
// });
// setViruses((prevViruses) => prevViruses.filter(({ id }) => id !== virusId));
// console.log('Implement the delete route first!');
await fetch(`${process.env.REACT_APP_API_BASE_URL}/virus/${virusId}`, {
method: 'DELETE',
});
setViruses((prevViruses) => prevViruses.filter(({ id }) => id !== virusId));
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

La bonne pratique c'est de sortir cette logique dans un service

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants