Skip to content

Conversation

@guillaumeduboc
Copy link
Owner

No description provided.

@guillaumeduboc guillaumeduboc changed the title Adding a getVirus route Session 1 : Adding getVirus, createVirus and deleteVirus Oct 20, 2021

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 => {
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 déstructurer ton objet event pour plus de lisibilité :
export const main: APIGatewayProxyHandler = async { queryStringParameters } => {

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")){
Copy link
Collaborator

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)

Comment on lines 10 to 17
return {
statusCode: 200,
body: JSON.stringify({
message: targettedVirus,
input: event,
}),
};
} else {
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 éviter la duplication en écrivant un générateur de réponse HTTP

Comment on lines 7 to 9
headers: {
'Access-Control-Allow-Origin': '*',
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

id: string;
positionX: number;
positionY: number;
virus_category: number;
Copy link
Collaborator

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

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