-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: session-2-v2
Are you sure you want to change the base?
Conversation
Correcting GET route's response
backend/src/handlers/virus/get.ts
Outdated
|
||
return success({ viruses }); | ||
export const main: APIGatewayProxyHandler = async () => { | ||
return documentClient.query({TableName: "dojo-serverless-table"}, function(err, data) { |
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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 }) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tu peux typer pathParameters
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)); | ||
}; |
There was a problem hiding this comment.
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
No description provided.