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

Ex4 #39

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open

Ex4 #39

wants to merge 37 commits into from

Conversation

Kuper-S
Copy link

@Kuper-S Kuper-S commented Jun 17, 2022

@Kuper-S
Copy link
Author

Kuper-S commented Jun 17, 2022

@monadav
@liorshamian

@Kuper-S Kuper-S closed this Jun 17, 2022
@Kuper-S Kuper-S reopened this Jun 17, 2022
@Kuper-S
Copy link
Author

Kuper-S commented Jun 17, 2022

@liorshamian
@monadav

@Kuper-S Kuper-S marked this pull request as ready for review June 17, 2022 15:38
Copy link

@monadav monadav left a comment

Choose a reason for hiding this comment

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

Great work. the server performs well and even though I tried to find bugs, didn't find any.
Please mind my comments, and lets have a short GIT session.
Try to reduce the functions' length, shouldn't cross 20 lines, otherwise, you need to break it into small functions with dedicated functionality.

"license": "ISC",
"dependencies": {
"cors": "^2.8.5",
"express": "^4.18.1"
Copy link

Choose a reason for hiding this comment

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

missing axios package.

@@ -0,0 +1,16 @@
import express from "express";
Copy link

Choose a reason for hiding this comment

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

Nice!

Copy link

Choose a reason for hiding this comment

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

If you rename the file api.js I would assume that the route will be localhost/api/items, please rename the file or the routing

@@ -0,0 +1,7 @@
export function logger(req, res, next) {
Copy link

Choose a reason for hiding this comment

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

cool. worth changing the name to requestLogger as logger is more generic name and the functionality is coupled to incoming requests

@@ -0,0 +1,11 @@
export default function errorHandler(err, req, res, next) {
Copy link

Choose a reason for hiding this comment

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

cool.

@@ -0,0 +1,5 @@
export function validation(item) {
const elementsArr = item.split(/\s*,\s*/);
Copy link

Choose a reason for hiding this comment

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

elementsArr is not a meaning full name, would rename it

if (!isPokemon) {
//check pokemon by name
const isPokemon = await pokemonClinet.checkByPokemonName(inputArr[0]);
if (isPokemon) return this.checkByPokemonName(isPokemon);
Copy link

Choose a reason for hiding this comment

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

checkByPokemonName is an async function, use await

Comment on lines +102 to +106
const task = this.pokemonInit(false, inputArr[0]);
this.itemsArray.push(task);
this.newItems.push(task);
await fs.writeFile(this.jsonFile, JSON.stringify(this.itemsArray));
return this.newItems;
Copy link

Choose a reason for hiding this comment

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

this else scope will never run as you already checked !isPokemon in line 92

}
}

pokemonInit(isPokemon, item, imageUrl = "", pokemonId = "") {
Copy link

Choose a reason for hiding this comment

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

nice

try {
this.readFile();
const idx = this.itemsArray.findIndex((item) => item.itemId === itemId);
if (idx === -1) throw "err";
Copy link

Choose a reason for hiding this comment

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

throw meaningful error, and use throw new Error('my error')

throw `There is no task with id: ${itemId} `;
}
}
itemToAdd(arr) {
Copy link

Choose a reason for hiding this comment

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

rename the method's name to its purpose filterExistingPokemons

Copy link

Choose a reason for hiding this comment

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

you can use this.exsitsPokemon that already checking if the pokemon exists, you may need to pass an array you would like to perform the checking on

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