diff --git a/.eslintrc.js b/.eslintrc.js index 9527350..dc04463 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -10,10 +10,9 @@ module.exports = { "ecmaVersion": "latest" }, "rules": { - "no-unused-vars": "off", indent: ["error", 4], "linebreak-style": ["error", "unix"], quotes: ["error", "double"], semi: ["error", "always"] } -}; +}; \ No newline at end of file diff --git a/lib/controllers/ExplorerController.js b/lib/controllers/ExplorerController.js index 85590a6..f1cca84 100644 --- a/lib/controllers/ExplorerController.js +++ b/lib/controllers/ExplorerController.js @@ -2,25 +2,30 @@ const ExplorerService = require("../services/ExplorerService"); const FizzbuzzService = require("../services/FizzbuzzService"); const Reader = require("../utils/reader"); -class ExplorerController{ - static getExplorersByMission(mission){ +class ExplorerController { + static getExplorersByMission(mission) { const explorers = Reader.readJsonFile("explorers.json"); return ExplorerService.filterByMission(explorers, mission); } - static applyFizzbuzz(score){ + static applyFizzbuzz(score) { return FizzbuzzService.applyValidationInNumber(score); } - static getExplorersUsernamesByMission(mission){ + static getExplorersUsernamesByMission(mission) { const explorers = Reader.readJsonFile("explorers.json"); return ExplorerService.getExplorersUsernamesByMission(explorers, mission); } - static getExplorersAmonutByMission(mission){ + static getExplorersAmonutByMission(mission) { const explorers = Reader.readJsonFile("explorers.json"); return ExplorerService.getAmountOfExplorersByMission(explorers, mission); } + + static getfilterByStack(stack) { + const explorers = Reader.readJsonFile("explorers.json"); + return ExplorerService.filterByStack(explorers, stack); + } } -module.exports = ExplorerController; +module.exports = ExplorerController; \ No newline at end of file diff --git a/lib/server.js b/lib/server.js index 9860b43..fb14aac 100644 --- a/lib/server.js +++ b/lib/server.js @@ -5,7 +5,7 @@ app.use(express.json()); const port = 3000; app.get("/", (request, response) => { - response.json({message: "FizzBuzz Api welcome!"}); + response.json({ message: "FizzBuzz Api welcome!" }); }); app.get("/v1/explorers/:mission", (request, response) => { @@ -17,22 +17,27 @@ app.get("/v1/explorers/:mission", (request, response) => { app.get("/v1/explorers/amount/:mission", (request, response) => { const mission = request.params.mission; const explorersAmountInMission = ExplorerController.getExplorersAmonutByMission(mission); - response.json({mission: request.params.mission, quantity: explorersAmountInMission}); + response.json({ mission: request.params.mission, quantity: explorersAmountInMission }); }); app.get("/v1/explorers/usernames/:mission", (request, response) => { const mission = request.params.mission; const explorersUsernames = ExplorerController.getExplorersUsernamesByMission(mission); - response.json({mission: request.params.mission, explorers: explorersUsernames}); + response.json({ mission: request.params.mission, explorers: explorersUsernames }); }); app.get("/v1/fizzbuzz/:score", (request, response) => { const score = parseInt(request.params.score); const fizzbuzzTrick = ExplorerController.applyFizzbuzz(score); - response.json({score: score, trick: fizzbuzzTrick}); + response.json({ score: score, trick: fizzbuzzTrick }); }); -app.listen(port, () => { - console.log(`FizzBuzz API in localhost:${port}`); +app.get("/v1/explorers/stack/:stack", (request, response) => { + const stack = request.params.stack; + const explorersInStack = ExplorerController.getfilterByStack(stack); + response.json(explorersInStack); }); +app.listen(port, () => { + console.log(`FizzBuzz API in localhost:${port}`); +}); \ No newline at end of file diff --git a/lib/services/ExplorerService.js b/lib/services/ExplorerService.js index 9fef957..194c9f2 100644 --- a/lib/services/ExplorerService.js +++ b/lib/services/ExplorerService.js @@ -1,21 +1,25 @@ class ExplorerService { - static filterByMission(explorers, mission){ + static filterByMission(explorers, mission) { const explorersByMission = explorers.filter((explorer) => explorer.mission == mission); return explorersByMission; } - static getAmountOfExplorersByMission(explorers, mission){ + static getAmountOfExplorersByMission(explorers, mission) { const explorersByMission = ExplorerService.filterByMission(explorers, mission); return explorersByMission.length; } - static getExplorersUsernamesByMission(explorers, mission){ + static getExplorersUsernamesByMission(explorers, mission) { const explorersByMission = ExplorerService.filterByMission(explorers, mission); const explorersUsernames = explorersByMission.map((explorer) => explorer.githubUsername); return explorersUsernames; } + static filterByStack(explorers, stack) { + const explorersByStack = explorers.filter((explorer) => explorer.stacks == stack); + return explorersByStack; + } } -module.exports = ExplorerService; +module.exports = ExplorerService; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index bb4f2aa..7b83fc3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "express": "^4.17.3" }, "devDependencies": { - "eslint": "^8.14.0", + "eslint": "^8.15.0", "jest": "^27.5.1" } }, @@ -567,19 +567,19 @@ "dev": true }, "node_modules/@eslint/eslintrc": { - "version": "1.2.2", - "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.2.2.tgz", - "integrity": "sha512-lTVWHs7O2hjBFZunXTZYnYqtB9GakA1lnxIf+gKq2nY5gxkkNi/lQvveW6t8gFdOHTg6nG50Xs95PrLqVpcaLg==", + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.2.3.tgz", + "integrity": "sha512-uGo44hIwoLGNyduRpjdEpovcbMdd+Nv7amtmJxnKmI8xj6yd5LncmSwDa5NgX/41lIFJtkjD6YdVfgEzPfJ5UA==", "dev": true, "dependencies": { "ajv": "^6.12.4", "debug": "^4.3.2", - "espree": "^9.3.1", + "espree": "^9.3.2", "globals": "^13.9.0", "ignore": "^5.2.0", "import-fresh": "^3.2.1", "js-yaml": "^4.1.0", - "minimatch": "^3.0.4", + "minimatch": "^3.1.2", "strip-json-comments": "^3.1.1" }, "engines": { @@ -593,9 +593,9 @@ "dev": true }, "node_modules/@eslint/eslintrc/node_modules/globals": { - "version": "13.13.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-13.13.0.tgz", - "integrity": "sha512-EQ7Q18AJlPwp3vUDL4mKA0KXrXyNIQyWon6T6XQiBQF0XHvRsiCSrWmmeATpUzdJN2HhWZU6Pdl0a9zdep5p6A==", + "version": "13.14.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-13.14.0.tgz", + "integrity": "sha512-ERO68sOYwm5UuLvSJTY7w7NP2c8S4UcXs3X1GBX8cwOr+ShOcDBbCY5mH4zxz0jsYCdJ8ve8Mv9n2YGJMB1aeg==", "dev": true, "dependencies": { "type-fest": "^0.20.2" @@ -1094,9 +1094,9 @@ } }, "node_modules/acorn": { - "version": "8.7.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.7.0.tgz", - "integrity": "sha512-V/LGr1APy+PXIwKebEWrkZPwoeoF+w1jiOBUmuxuiUIaOHtob8Qc9BTrYo7VuI5fR8tqsy+buA2WFooR5olqvQ==", + "version": "8.7.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.7.1.tgz", + "integrity": "sha512-Xx54uLJQZ19lKygFXOWsscKUbsBZW0CPykPhVQdhIeIwrbPmJzqeASDInc8nKBnp/JT6igTs82qPXz069H8I/A==", "dev": true, "bin": { "acorn": "bin/acorn" @@ -1911,12 +1911,12 @@ } }, "node_modules/eslint": { - "version": "8.14.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.14.0.tgz", - "integrity": "sha512-3/CE4aJX7LNEiE3i6FeodHmI/38GZtWCsAtsymScmzYapx8q1nVVb+eLcLSzATmCPXw5pT4TqVs1E0OmxAd9tw==", + "version": "8.15.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.15.0.tgz", + "integrity": "sha512-GG5USZ1jhCu8HJkzGgeK8/+RGnHaNYZGrGDzUtigK3BsGESW/rs2az23XqE0WVwDxy1VRvvjSSGu5nB0Bu+6SA==", "dev": true, "dependencies": { - "@eslint/eslintrc": "^1.2.2", + "@eslint/eslintrc": "^1.2.3", "@humanwhocodes/config-array": "^0.9.2", "ajv": "^6.10.0", "chalk": "^4.0.0", @@ -1927,7 +1927,7 @@ "eslint-scope": "^7.1.1", "eslint-utils": "^3.0.0", "eslint-visitor-keys": "^3.3.0", - "espree": "^9.3.1", + "espree": "^9.3.2", "esquery": "^1.4.0", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", @@ -1943,7 +1943,7 @@ "json-stable-stringify-without-jsonify": "^1.0.1", "levn": "^0.4.1", "lodash.merge": "^4.6.2", - "minimatch": "^3.0.4", + "minimatch": "^3.1.2", "natural-compare": "^1.4.0", "optionator": "^0.9.1", "regexpp": "^3.2.0", @@ -2120,13 +2120,13 @@ } }, "node_modules/espree": { - "version": "9.3.1", - "resolved": "https://registry.npmjs.org/espree/-/espree-9.3.1.tgz", - "integrity": "sha512-bvdyLmJMfwkV3NCRl5ZhJf22zBFo1y8bYh3VYb+bfzqNB4Je68P2sSuXyuFquzWLebHpNd2/d5uv7yoP9ISnGQ==", + "version": "9.3.2", + "resolved": "https://registry.npmjs.org/espree/-/espree-9.3.2.tgz", + "integrity": "sha512-D211tC7ZwouTIuY5x9XnS0E9sWNChB7IYKX/Xp5eQj3nFXhqmiUDB9q27y76oFl8jTg3pXcQx/bpxMfs3CIZbA==", "dev": true, "dependencies": { - "acorn": "^8.7.0", - "acorn-jsx": "^5.3.1", + "acorn": "^8.7.1", + "acorn-jsx": "^5.3.2", "eslint-visitor-keys": "^3.3.0" }, "engines": { @@ -5451,19 +5451,19 @@ "dev": true }, "@eslint/eslintrc": { - "version": "1.2.2", - "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.2.2.tgz", - "integrity": "sha512-lTVWHs7O2hjBFZunXTZYnYqtB9GakA1lnxIf+gKq2nY5gxkkNi/lQvveW6t8gFdOHTg6nG50Xs95PrLqVpcaLg==", + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.2.3.tgz", + "integrity": "sha512-uGo44hIwoLGNyduRpjdEpovcbMdd+Nv7amtmJxnKmI8xj6yd5LncmSwDa5NgX/41lIFJtkjD6YdVfgEzPfJ5UA==", "dev": true, "requires": { "ajv": "^6.12.4", "debug": "^4.3.2", - "espree": "^9.3.1", + "espree": "^9.3.2", "globals": "^13.9.0", "ignore": "^5.2.0", "import-fresh": "^3.2.1", "js-yaml": "^4.1.0", - "minimatch": "^3.0.4", + "minimatch": "^3.1.2", "strip-json-comments": "^3.1.1" }, "dependencies": { @@ -5474,9 +5474,9 @@ "dev": true }, "globals": { - "version": "13.13.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-13.13.0.tgz", - "integrity": "sha512-EQ7Q18AJlPwp3vUDL4mKA0KXrXyNIQyWon6T6XQiBQF0XHvRsiCSrWmmeATpUzdJN2HhWZU6Pdl0a9zdep5p6A==", + "version": "13.14.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-13.14.0.tgz", + "integrity": "sha512-ERO68sOYwm5UuLvSJTY7w7NP2c8S4UcXs3X1GBX8cwOr+ShOcDBbCY5mH4zxz0jsYCdJ8ve8Mv9n2YGJMB1aeg==", "dev": true, "requires": { "type-fest": "^0.20.2" @@ -5895,9 +5895,9 @@ } }, "acorn": { - "version": "8.7.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.7.0.tgz", - "integrity": "sha512-V/LGr1APy+PXIwKebEWrkZPwoeoF+w1jiOBUmuxuiUIaOHtob8Qc9BTrYo7VuI5fR8tqsy+buA2WFooR5olqvQ==", + "version": "8.7.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.7.1.tgz", + "integrity": "sha512-Xx54uLJQZ19lKygFXOWsscKUbsBZW0CPykPhVQdhIeIwrbPmJzqeASDInc8nKBnp/JT6igTs82qPXz069H8I/A==", "dev": true }, "acorn-globals": { @@ -6511,12 +6511,12 @@ } }, "eslint": { - "version": "8.14.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.14.0.tgz", - "integrity": "sha512-3/CE4aJX7LNEiE3i6FeodHmI/38GZtWCsAtsymScmzYapx8q1nVVb+eLcLSzATmCPXw5pT4TqVs1E0OmxAd9tw==", + "version": "8.15.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.15.0.tgz", + "integrity": "sha512-GG5USZ1jhCu8HJkzGgeK8/+RGnHaNYZGrGDzUtigK3BsGESW/rs2az23XqE0WVwDxy1VRvvjSSGu5nB0Bu+6SA==", "dev": true, "requires": { - "@eslint/eslintrc": "^1.2.2", + "@eslint/eslintrc": "^1.2.3", "@humanwhocodes/config-array": "^0.9.2", "ajv": "^6.10.0", "chalk": "^4.0.0", @@ -6527,7 +6527,7 @@ "eslint-scope": "^7.1.1", "eslint-utils": "^3.0.0", "eslint-visitor-keys": "^3.3.0", - "espree": "^9.3.1", + "espree": "^9.3.2", "esquery": "^1.4.0", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", @@ -6543,7 +6543,7 @@ "json-stable-stringify-without-jsonify": "^1.0.1", "levn": "^0.4.1", "lodash.merge": "^4.6.2", - "minimatch": "^3.0.4", + "minimatch": "^3.1.2", "natural-compare": "^1.4.0", "optionator": "^0.9.1", "regexpp": "^3.2.0", @@ -6664,13 +6664,13 @@ "dev": true }, "espree": { - "version": "9.3.1", - "resolved": "https://registry.npmjs.org/espree/-/espree-9.3.1.tgz", - "integrity": "sha512-bvdyLmJMfwkV3NCRl5ZhJf22zBFo1y8bYh3VYb+bfzqNB4Je68P2sSuXyuFquzWLebHpNd2/d5uv7yoP9ISnGQ==", + "version": "9.3.2", + "resolved": "https://registry.npmjs.org/espree/-/espree-9.3.2.tgz", + "integrity": "sha512-D211tC7ZwouTIuY5x9XnS0E9sWNChB7IYKX/Xp5eQj3nFXhqmiUDB9q27y76oFl8jTg3pXcQx/bpxMfs3CIZbA==", "dev": true, "requires": { - "acorn": "^8.7.0", - "acorn-jsx": "^5.3.1", + "acorn": "^8.7.1", + "acorn-jsx": "^5.3.2", "eslint-visitor-keys": "^3.3.0" } }, diff --git a/package.json b/package.json index 119436d..f4bfc8b 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "author": "", "license": "ISC", "devDependencies": { - "eslint": "^8.14.0", + "eslint": "^8.15.0", "jest": "^27.5.1" }, "dependencies": { diff --git a/test/services/ExplorerService.test.js b/test/services/ExplorerService.test.js index 4313f19..1002a6f 100644 --- a/test/services/ExplorerService.test.js +++ b/test/services/ExplorerService.test.js @@ -2,9 +2,14 @@ const ExplorerService = require("./../../lib/services/ExplorerService"); describe("Tests para ExplorerService", () => { test("Requerimiento 1: Calcular todos los explorers en una misiĆ³n", () => { - const explorers = [{mission: "node"}]; + const explorers = [{ mission: "node" }]; const explorersInNode = ExplorerService.filterByMission(explorers, "node"); expect(explorersInNode.length).toBe(1); }); -}); + test("Requerimiento 2: Devolver lista de explorers con ese stack", () => { + const explorers = [{ stacks: "javascript" }]; + const explorersInStack = ExplorerService.filterByStack(explorers, "javascript"); + expect(explorersInStack.length).toBe(1); + }); +}); \ No newline at end of file