-
Notifications
You must be signed in to change notification settings - Fork 0
Session 1 : Adding getVirus, createVirus and deleteVirus #1
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
base: session-1-v3
Are you sure you want to change the base?
Conversation
backend/functions/getVirus.ts
Outdated
|
|
||
| const listOfViruses: Array<Virus> = [{id: 1, type: 1},{id: 2, type: 1},{id: 3, type: 3},{id: 4, type: 2},{id: 5, type: 1}] | ||
|
|
||
| export const main: APIGatewayProxyHandler = async event => { |
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 déstructurer ton objet event pour plus de lisibilité :
export const main: APIGatewayProxyHandler = async { queryStringParameters } => {
backend/functions/getVirus.ts
Outdated
| const listOfViruses: Array<Virus> = [{id: 1, type: 1},{id: 2, type: 1},{id: 3, type: 3},{id: 4, type: 2},{id: 5, type: 1}] | ||
|
|
||
| export const main: APIGatewayProxyHandler = async event => { | ||
| if (event.queryStringParameters != null && Object.keys(event.queryStringParameters).includes("id")){ |
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.
Du coup tu peux faire const {id} = queryStringParameters puis if (id !== null)
backend/functions/getVirus.ts
Outdated
| return { | ||
| statusCode: 200, | ||
| body: JSON.stringify({ | ||
| message: targettedVirus, | ||
| input: event, | ||
| }), | ||
| }; | ||
| } else { |
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 éviter la duplication en écrivant un générateur de réponse HTTP
backend/functions/deleteVirus.ts
Outdated
| headers: { | ||
| 'Access-Control-Allow-Origin': '*', | ||
| }, |
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 déléguer ça à API Gateway : https://docs.aws.amazon.com/fr_fr/apigateway/latest/developerguide/how-to-cors.html
backend/types/virus.ts
Outdated
| id: string; | ||
| positionX: number; | ||
| positionY: number; | ||
| virus_category: number; |
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.
Prends l'habitude d'utiliser du camelCase : https://fr.wikipedia.org/wiki/Camel_case
No description provided.