Skip to content

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.

3 participants