From 687495a0faf396e2e4eebcb6ad61600d97b2e268 Mon Sep 17 00:00:00 2001 From: Alex Vargas Date: Wed, 3 Jan 2024 15:14:26 -0600 Subject: [PATCH 1/7] package-lock.json added to .gitignore file --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 5148e52..6b9c427 100644 --- a/.gitignore +++ b/.gitignore @@ -30,6 +30,9 @@ build/Release node_modules jspm_packages +# Lock pacjage +package-lock.json + # Optional npm cache directory .npm From 825fea886af1a492be0aa134fde62640365017e2 Mon Sep 17 00:00:00 2001 From: Alex Vargas Date: Wed, 3 Jan 2024 15:39:12 -0600 Subject: [PATCH 2/7] Some changes in the ES in quoteRepository --- quotesRepository.js | 26 ++++++++++++++------------ server.js | 7 +++++++ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/quotesRepository.js b/quotesRepository.js index 51aff0a..4a4dfc7 100644 --- a/quotesRepository.js +++ b/quotesRepository.js @@ -1,19 +1,21 @@ 'use strict'; -var quotes = require('./quotes'); +const quotes = require('./quotes'); -module.exports = { - getRandom: function getRandom(numberOfQuotes) { - var limit = numberOfQuotes > quotes.length ? quotes.length : numberOfQuotes; - - var out = new Array(limit); +const getRandom = (numberOfQuotes) => { + const limit = numberOfQuotes > quotes.length ? quotes.length : numberOfQuotes; + + const out = new Array(limit); - var availableQuotes = quotes.slice(); + const availableQuotes = quotes.slice(); - for (var i = 0; i < limit; i++) { - out[i] = availableQuotes.splice(Math.floor(Math.random() * availableQuotes.length), 1)[0]; - } - - return out; + for (const i = 0; i < limit; i++) { + out[i] = availableQuotes.splice(Math.floor(Math.random() * availableQuotes.length), 1)[0]; } + + return out; +} + +module.exports = { + getRandom }; diff --git a/server.js b/server.js index 7902e9a..83786a6 100644 --- a/server.js +++ b/server.js @@ -10,10 +10,17 @@ app.all('*', function (req, res, next) { next(); }); +app.get('/v1/quote/:id', function(req, res) { + res.send({ + quote: 'Yo soy el mero macizo', + author: 'Alex Vargas', + }) +}) app.get('/v1/quotes/:num?', function (req, res) { res.send(quotesRepository.getRandom(req.params.num || 1)); }); + app.listen(port, function () { console.log('Server running on port', port); }) \ No newline at end of file From 3ac3f41acb2f225b0759bb04186c15ad4f82eaab Mon Sep 17 00:00:00 2001 From: Alex Vargas Date: Wed, 3 Jan 2024 16:19:10 -0600 Subject: [PATCH 3/7] package-lock.json added to keep the same node modules versions --- .gitignore | 3 - package-lock.json | 656 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 656 insertions(+), 3 deletions(-) create mode 100644 package-lock.json diff --git a/.gitignore b/.gitignore index 6b9c427..5148e52 100644 --- a/.gitignore +++ b/.gitignore @@ -30,9 +30,6 @@ build/Release node_modules jspm_packages -# Lock pacjage -package-lock.json - # Optional npm cache directory .npm diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..6fbb1e5 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,656 @@ +{ + "name": "breaking-bad-quotes", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "breaking-bad-quotes", + "version": "1.0.0", + "dependencies": { + "express": "^4.14.1" + } + }, + "node_modules/accepts": { + "version": "1.3.8", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", + "integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==", + "dependencies": { + "mime-types": "~2.1.34", + "negotiator": "0.6.3" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/array-flatten": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", + "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==" + }, + "node_modules/body-parser": { + "version": "1.20.1", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz", + "integrity": "sha512-jWi7abTbYwajOytWCQc37VulmWiRae5RyTpaCyDcS5/lMdtwSz5lOpDE67srw/HYe35f1z3fDQw+3txg7gNtWw==", + "dependencies": { + "bytes": "3.1.2", + "content-type": "~1.0.4", + "debug": "2.6.9", + "depd": "2.0.0", + "destroy": "1.2.0", + "http-errors": "2.0.0", + "iconv-lite": "0.4.24", + "on-finished": "2.4.1", + "qs": "6.11.0", + "raw-body": "2.5.1", + "type-is": "~1.6.18", + "unpipe": "1.0.0" + }, + "engines": { + "node": ">= 0.8", + "npm": "1.2.8000 || >= 1.4.16" + } + }, + "node_modules/bytes": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", + "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/call-bind": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.5.tgz", + "integrity": "sha512-C3nQxfFZxFRVoJoGKKI8y3MOEo129NQ+FgQ08iye+Mk4zNZZGdjfs06bVTr+DBSlA66Q2VEcMki/cUCP4SercQ==", + "dependencies": { + "function-bind": "^1.1.2", + "get-intrinsic": "^1.2.1", + "set-function-length": "^1.1.1" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/content-disposition": { + "version": "0.5.4", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz", + "integrity": "sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==", + "dependencies": { + "safe-buffer": "5.2.1" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/content-type": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz", + "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.5.0.tgz", + "integrity": "sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie-signature": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", + "integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ==" + }, + "node_modules/debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dependencies": { + "ms": "2.0.0" + } + }, + "node_modules/define-data-property": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.1.tgz", + "integrity": "sha512-E7uGkTzkk1d0ByLeSc6ZsFS79Axg+m1P/VsgYsxHgiuc3tFSj+MjMIwe90FC4lOAZzNBdY7kkO2P2wKdsQ1vgQ==", + "dependencies": { + "get-intrinsic": "^1.2.1", + "gopd": "^1.0.1", + "has-property-descriptors": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/depd": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", + "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/destroy": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz", + "integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==", + "engines": { + "node": ">= 0.8", + "npm": "1.2.8000 || >= 1.4.16" + } + }, + "node_modules/ee-first": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", + "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==" + }, + "node_modules/encodeurl": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", + "integrity": "sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w==", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/escape-html": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", + "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==" + }, + "node_modules/etag": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", + "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/express": { + "version": "4.18.2", + "resolved": "https://registry.npmjs.org/express/-/express-4.18.2.tgz", + "integrity": "sha512-5/PsL6iGPdfQ/lKM1UuielYgv3BUoJfz1aUwU9vHZ+J7gyvwdQXFEBIEIaxeGf0GIcreATNyBExtalisDbuMqQ==", + "dependencies": { + "accepts": "~1.3.8", + "array-flatten": "1.1.1", + "body-parser": "1.20.1", + "content-disposition": "0.5.4", + "content-type": "~1.0.4", + "cookie": "0.5.0", + "cookie-signature": "1.0.6", + "debug": "2.6.9", + "depd": "2.0.0", + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "etag": "~1.8.1", + "finalhandler": "1.2.0", + "fresh": "0.5.2", + "http-errors": "2.0.0", + "merge-descriptors": "1.0.1", + "methods": "~1.1.2", + "on-finished": "2.4.1", + "parseurl": "~1.3.3", + "path-to-regexp": "0.1.7", + "proxy-addr": "~2.0.7", + "qs": "6.11.0", + "range-parser": "~1.2.1", + "safe-buffer": "5.2.1", + "send": "0.18.0", + "serve-static": "1.15.0", + "setprototypeof": "1.2.0", + "statuses": "2.0.1", + "type-is": "~1.6.18", + "utils-merge": "1.0.1", + "vary": "~1.1.2" + }, + "engines": { + "node": ">= 0.10.0" + } + }, + "node_modules/finalhandler": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.2.0.tgz", + "integrity": "sha512-5uXcUVftlQMFnWC9qu/svkWv3GTd2PfUhK/3PLkYNAe7FbqJMt3515HaxE6eRL74GdsriiwujiawdaB1BpEISg==", + "dependencies": { + "debug": "2.6.9", + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "on-finished": "2.4.1", + "parseurl": "~1.3.3", + "statuses": "2.0.1", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/forwarded": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", + "integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/fresh": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", + "integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/function-bind": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-intrinsic": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.2.tgz", + "integrity": "sha512-0gSo4ml/0j98Y3lngkFEot/zhiCeWsbYIlZ+uZOVgzLyLaUw7wxUL+nCTP0XJvJg1AXulJRI3UJi8GsbDuxdGA==", + "dependencies": { + "function-bind": "^1.1.2", + "has-proto": "^1.0.1", + "has-symbols": "^1.0.3", + "hasown": "^2.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/gopd": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", + "integrity": "sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==", + "dependencies": { + "get-intrinsic": "^1.1.3" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-property-descriptors": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.1.tgz", + "integrity": "sha512-VsX8eaIewvas0xnvinAe9bw4WfIeODpGYikiWYLH+dma0Jw6KHYqWiWfhQlgOVK8D6PvjubK5Uc4P0iIhIcNVg==", + "dependencies": { + "get-intrinsic": "^1.2.2" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.1.tgz", + "integrity": "sha512-7qE+iP+O+bgF9clE5+UoBFzE65mlBiVj3tKCrlNQ0Ogwm0BjpT/gK4SlLYDMybDh5I3TCTKnPPa0oMG7JDYrhg==", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-symbols": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", + "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/hasown": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.0.tgz", + "integrity": "sha512-vUptKVTpIJhcczKBbgnS+RtcuYMB8+oNzPK2/Hp3hanz8JmpATdmmgLgSaadVREkDm+e2giHwY3ZRkyjSIDDFA==", + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/http-errors": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz", + "integrity": "sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==", + "dependencies": { + "depd": "2.0.0", + "inherits": "2.0.4", + "setprototypeof": "1.2.0", + "statuses": "2.0.1", + "toidentifier": "1.0.1" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/iconv-lite": { + "version": "0.4.24", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", + "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + }, + "node_modules/ipaddr.js": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", + "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==", + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/media-typer": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", + "integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/merge-descriptors": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", + "integrity": "sha512-cCi6g3/Zr1iqQi6ySbseM1Xvooa98N0w31jzUYrXPX2xqObmFGHJ0tQ5u74H3mVh7wLouTseZyYIq39g8cNp1w==" + }, + "node_modules/methods": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", + "integrity": "sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", + "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==", + "bin": { + "mime": "cli.js" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" + }, + "node_modules/negotiator": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", + "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/object-inspect": { + "version": "1.13.1", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.1.tgz", + "integrity": "sha512-5qoj1RUiKOMsCCNLV1CBiPYE10sziTsnmNxkAI/rZhiD63CF7IqdFGC/XzjWjpSgLf0LxXX3bDFIh0E18f6UhQ==", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/on-finished": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", + "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==", + "dependencies": { + "ee-first": "1.1.1" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/parseurl": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", + "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/path-to-regexp": { + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", + "integrity": "sha512-5DFkuoqlv1uYQKxy8omFBeJPQcdoE07Kv2sferDCrAq1ohOU+MSDswDIbnx3YAM60qIOnYa53wBhXW0EbMonrQ==" + }, + "node_modules/proxy-addr": { + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", + "integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==", + "dependencies": { + "forwarded": "0.2.0", + "ipaddr.js": "1.9.1" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/qs": { + "version": "6.11.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz", + "integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==", + "dependencies": { + "side-channel": "^1.0.4" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/range-parser": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", + "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/raw-body": { + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.1.tgz", + "integrity": "sha512-qqJBtEyVgS0ZmPGdCFPWJ3FreoqvG4MVQln/kCgF7Olq95IbOp0/BWyMwbdtn4VTvkM8Y7khCQ2Xgk/tcrCXig==", + "dependencies": { + "bytes": "3.1.2", + "http-errors": "2.0.0", + "iconv-lite": "0.4.24", + "unpipe": "1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, + "node_modules/safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" + }, + "node_modules/send": { + "version": "0.18.0", + "resolved": "https://registry.npmjs.org/send/-/send-0.18.0.tgz", + "integrity": "sha512-qqWzuOjSFOuqPjFe4NOsMLafToQQwBSOEpS+FwEt3A2V3vKubTquT3vmLTQpFgMXp8AlFWFuP1qKaJZOtPpVXg==", + "dependencies": { + "debug": "2.6.9", + "depd": "2.0.0", + "destroy": "1.2.0", + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "etag": "~1.8.1", + "fresh": "0.5.2", + "http-errors": "2.0.0", + "mime": "1.6.0", + "ms": "2.1.3", + "on-finished": "2.4.1", + "range-parser": "~1.2.1", + "statuses": "2.0.1" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/send/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" + }, + "node_modules/serve-static": { + "version": "1.15.0", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.15.0.tgz", + "integrity": "sha512-XGuRDNjXUijsUL0vl6nSD7cwURuzEgglbOaFuZM9g3kwDXOWVTck0jLzjPzGD+TazWbboZYu52/9/XPdUgne9g==", + "dependencies": { + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "parseurl": "~1.3.3", + "send": "0.18.0" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/set-function-length": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.1.1.tgz", + "integrity": "sha512-VoaqjbBJKiWtg4yRcKBQ7g7wnGnLV3M8oLvVWwOk2PdYY6PEFegR1vezXR0tw6fZGF9csVakIRjrJiy2veSBFQ==", + "dependencies": { + "define-data-property": "^1.1.1", + "get-intrinsic": "^1.2.1", + "gopd": "^1.0.1", + "has-property-descriptors": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/setprototypeof": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", + "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==" + }, + "node_modules/side-channel": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz", + "integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==", + "dependencies": { + "call-bind": "^1.0.0", + "get-intrinsic": "^1.0.2", + "object-inspect": "^1.9.0" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/statuses": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", + "integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/toidentifier": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", + "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==", + "engines": { + "node": ">=0.6" + } + }, + "node_modules/type-is": { + "version": "1.6.18", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", + "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==", + "dependencies": { + "media-typer": "0.3.0", + "mime-types": "~2.1.24" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/unpipe": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", + "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/utils-merge": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", + "integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==", + "engines": { + "node": ">= 0.4.0" + } + }, + "node_modules/vary": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", + "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==", + "engines": { + "node": ">= 0.8" + } + } + } +} From ae0419efaa533e366277b5b2e4846c2ebb699e88 Mon Sep 17 00:00:00 2001 From: Alex Vargas Date: Wed, 3 Jan 2024 20:39:01 -0600 Subject: [PATCH 4/7] Update the project to the modern express rest api --- app.js | 5 + controllers/quotes.controller.js | 19 ++ data/quotes.js | 539 +++++++++++++++++++++++++++++++ models/server.js | 43 +++ package-lock.json | 21 ++ package.json | 3 +- quotes.js | 532 ------------------------------ quotesRepository.js | 21 -- routes/quotes.js | 8 + server.js | 26 -- 10 files changed, 637 insertions(+), 580 deletions(-) create mode 100644 app.js create mode 100644 controllers/quotes.controller.js create mode 100644 data/quotes.js create mode 100644 models/server.js delete mode 100644 quotes.js delete mode 100644 quotesRepository.js create mode 100644 routes/quotes.js delete mode 100644 server.js diff --git a/app.js b/app.js new file mode 100644 index 0000000..e07e04f --- /dev/null +++ b/app.js @@ -0,0 +1,5 @@ +const Server = require('./models/server'); + +const server = new Server(); + +server.listen(); \ No newline at end of file diff --git a/controllers/quotes.controller.js b/controllers/quotes.controller.js new file mode 100644 index 0000000..47e0eba --- /dev/null +++ b/controllers/quotes.controller.js @@ -0,0 +1,19 @@ +const { response, request } = require('express'); + +const { quotes, limit } = require('./../data/quotes'); + +const getRandom = (req = request, res = response) => { + const numberOfQuotes = req.params.num || 1; + const top = numberOfQuotes > limit ? limit : numberOfQuotes; + const out = new Array(top); + + for (let i = 0; i <= top; i++) { + out[i] = quotes[Math.floor(Math.random() * limit)]; + } + + res.send(out); +} + +module.exports = { + getRandom +} \ No newline at end of file diff --git a/data/quotes.js b/data/quotes.js new file mode 100644 index 0000000..ea92d8d --- /dev/null +++ b/data/quotes.js @@ -0,0 +1,539 @@ +'use strict'; + +const quotes = [ + { + quote: "I'm sorry, what were you asking me? Oh, yes, that stupid plastic container I asked you to buy. You see, hydrofluoric acid won't eat through plastic; it will however dissolve metal, rock, glass, ceramic. So there's that.", + author: "Walter White" + }, + { + quote: "Alright, I've got the talking pillow now... Okay?", + author: "Walter White" + }, + { + quote: "We tried to poison you. We tried to poison you because you are an insane, degenerate piece of filth and you deserve to die.", + author: "Walter White" + }, + { + quote: "Alright, tell you what. Both of you pull it out your butts right now, or I go grab a flashlight and some pliers and go exploring.", + author: "Jesse Pinkman" + }, + { + quote: "I do not believe fear to be an effective motivator. I want investment. For now, I'm simply interested in time frame.", + author: "Gustavo Fring" + }, + { + quote: "When you have children, you always have family. They will always be your priority, your responsibility. And a man, a man provides. And he does it even when he's not appreciated or respected or even loved. He simply bears up and he does it. Because he's a man.", + author: "Gustavo Fring" + }, + { + quote: "Hey, tell your douchebag brother-in-law to head towards the light.", + author: "Jesse Pinkman" + }, + { + quote: "Did you know that there's an acceptable level of rat turds that can go into candy bars? It's the government, jack. Even government doesn't care that much about quality. You know what is okay to put in hot dogs? Huh? Pig lips and *beep* But I say, hey, have at it bitches 'cause I love hot dogs.", + author: "Jesse Pinkman" + }, + { + quote: "The one that says if I can't kill you, you'll sure as *beep* wish you were dead.", + author: "Jesse Pinkman" + }, + { + quote: "You won, Walter. You got the job. Do yourself a favor and learn to take yes for an answer.", + author: "Mike Ehrmantraut" + }, + { + quote: "The thing is, if you just do stuff and nothing happens, what's it all mean? What's the point? Oh right, this whole thing is about self-acceptance.", + author: "Jesse Pinkman" + }, + { + quote: "You are a time bomb, tick-tick-ticking. And I have no intention of being around for the boom.", + author: "Mike Ehrmantraut" + }, + { + quote: "Don't drink and drive but if you do, call me.", + author: "Saul Goodman" + }, + { + quote: "I am not in danger, Skyler. I AM the danger!", + author: "Walter White" + }, + { + quote: "A guy opens his door and gets shot and you think that of me? No. I am the one who knocks!", + author: "Walter White" + }, + { + quote: "If that’s true, if you don’t know who I am, then maybe your best course… would be to tread lightly.", + author: "Walter White" + }, + { + quote: "Someone has to protect this family from the man who protects this family.", + author: "Skyler White" + }, + { + quote: "Smoking marijuana, eating cheetos, and masturbating do not constitute plans in my book.", + author: "Walter White" + }, + { + quote: "Stay out of my territory.", + author: "Walter White" + }, + { + quote: "Because I say so.", + author: "Walter White" + }, + { + quote: "I'm not in the meth business. I'm in the empire business.", + author: "Walter White" + }, + { + quote: "You all know exactly who I am. Say my name.", + author: "Walter White" + }, + { + quote: "I watched Jane die. I was there. And I watched her die.", + author: "Walter White" + }, + { + quote: "I did it for me. I liked it. I was good at it. And... I was really... I was alive.", + author: "Walter White" + }, + { + quote: "\"Cap'n Cook?\" That's not you? Like I said, no one is looking for you.", + author: "Walter White" + }, + { + quote: "Do you know how much I make a year? I mean, even if I told you, you wouldn't believe it.", + author: "Walter White" + }, + { + quote: "Jesus! Just grow some fucking balls!", + author: "Walter White" + }, + { + quote: "F*ck you! And your eyebrows!", + author: "Walter White" + }, + { + quote: "Send him to Belize? I'll send YOU to Belize.", + author: "Walter White" + }, + { + quote: "We're done when I say we're done.", + author: "Walter White" + }, + { + quote: "Sitting around, smoking marijuana, eating Cheetos and masturbating do not constitute \"plans\".", + author: "Walter White" + }, + { + quote: "I did it for me. I liked it. I was good at it. And I was really... I was alive.", + author: "Walter White" + }, + { + quote: "Bitch!", + author: "Jesse Pinkman" + }, + { + quote: "So you do have a plan? Yeah, Mr. White! Yeah, science!", + author: "Jesse Pinkman" + }, + { + quote: "I'm a criminal, yo.", + author: "Jesse Pinkman" + }, + { + quote: "Yeah, bitch! Magnets!", + author: "Jesse Pinkman" + }, + { + quote: "You're my free pass... bitch!", + author: "Jesse Pinkman" + }, + { + quote: "Fire in the hole, bitch!", + author: "Jesse Pinkman" + }, + { + quote: "Did you just bring a bomb into a hospital?", + author: "Jesse Pinkman" + }, + { + quote: "Seriously? \"Hello Kitty\"?", + author: "Jesse Pinkman" + }, + { + quote: "Speak into the mic, bitch.", + author: "Jesse Pinkman" + }, + { + quote: "Better call Saul!", + author: "Saul Goodman" + }, + { + quote: "You do seem to have a little “shit creek” action going… You know, FYI, you can buy a paddle.", + author: "Saul Goodman" + }, + { + quote: "If I ever get anal polyps, I'll know what to name them.", + author: "Saul Goodman" + }, + { + quote: "You two suck at peddling meth.", + author: "Saul Goodman" + }, + { + quote: "Clearly, his taste in women is the same as his taste in lawyers.", + author: "Saul Goodman" + }, + { + quote: "Congratulations, you’ve just left your family a second-hand Subaru.", + author: "Saul Goodman" + }, + { + quote: "I’m not saying it’s not bad. It’s bad. But it could be worse.", + author: "Saul Goodman" + }, + { + quote: "I hide in plain sight, same as you.", + author: "Gustavo Fring" + }, + { + quote: "May his death satisfy you.", + author: "Gustavo Fring" + }, + { + quote: "I will kill your wife, I will kill your son, I will kill your infant daughter.", + author: "Gustavo Fring" + }, + { + quote: "Everyone sounds like Meryl Streep with a gun to their head.", + author: "Mike Ehrmantraut" + }, + { + quote: "You know how they say it's been a pleasure'? Well... it hasn't.", + author: "Mike Ehrmantraut" + }, + { + quote: "Just because you shot Jesse James doesn't mean you are Jesse James.", + author: "Mike Ehrmantraut" + }, + { + quote: "No more half-measures, Walter.", + author: "Mike Ehrmantraut" + }, + { + quote: "Shut the f*ck up and let me die in peace.", + author: "Mike Ehrmantraut" + }, + { + quote: "Keys, scumbag. It's the universal symbol for keys.", + author: "Mike Ehrmantraut" + }, + { + quote: "I will put you under the jail.", + author: "Hank Schrader" + }, + { + quote: "My name is ASAC Schrader, and you can go f*ck yourself.", + author: "Hank Schrader" + }, + { + quote: "They're minerals, Marie! Jesus!", + author: "Hank Schrader" + }, + { + quote: "Since when do vegans eat fried chicken?", + author: "Hank Schrader" + }, + { + quote: "You're the smartest guy I ever met, and you're too stupid to see he made up his mind 10 minutes ago.", + author: "Hank Schrader" + }, + { + quote: "All I can do is wait... for the cancer to come back.", + author: "Skyler White" + }, + { + quote: "Put me on your magical boat, man, and sail me down your chocolaty river of meth!", + author: "Badger" + }, + { + quote: "Buzz buzz buzz", + author: "The fly" + }, + { + quote: "The Universe is Random. Not Inevitable. It's simple Chaos.", + author: "Walter White" + }, + { + quote: "Sometimes it just feels better not to talk. At All. About Anything. To Anyone.", + author: "Walter White" + }, + { + quote: "Name one thing in this world that is non negotiable.", + author: "Walter White" + }, + { + quote: "You are not the guy. You're not capable of being the guy. I had a guy but now I don't. You are not the guy.", + author: "Mike Ehrmantraut" + }, + { + quote: "If you don’t know who I am, then maybe your best course would be to tread lightly.", + author: "Walter White" + }, + { + quote: "Walter Jr., you're my big man. There are going to be some things that you'll come to learn about me in the next few days. But just know that no matter how it may look, I only had you in my heart. Goodbye!", + author: "Walter White" + }, + { + quote: "What I came to realise is that fear, that's the worst of it. That's the real enemy. So, get up, get out in the real world and you kick that bastard as hard you can right in the teeth.", + author: "Walter White" + }, + { + quote: "You need to stop focusing on the darkness behind you. The past is the past. Nothing can change what we’ve done.", + author: "Walter White" + }, + { + quote: "This is my own private domicile and I will not be harassed... bitch!", + author: "Jesse Pinkman" + }, + { + quote: "You don't want a criminal lawyer. You want a criminal lawyer.", + author: "Jesse Pinkman" + }, + { + quote: "So roll me further bitch!", + author: "Jesse Pinkman" + }, + { + quote: "I Won.", + author: "Walter White" + }, + { + quote: "You're never too old for balloons.", + author: "Mike Ehrmantraut" + }, + { + quote: "I have spent my whole life scared frightened of things that could happen, might happen, might not happen.", + author: "Walter White" + }, + { + quote: "Now, hey, remember, not all learning comes out of books.", + author: "Jesse Pinkman" + }, + { + quote: "Then why don't you just fucking die, already?", + author: "Walter White Jr" + }, + { + quote: "He handles the businesses, and I handle him.", + author: "Walter White" + }, + { + quote: "Shit!", + author: "Walter White" + }, + { + quote: "You little bastard.", + author: "Walter White" + }, + { + quote: "Stop acting like such a baby.", + author: "Walter White" + }, + { + quote: "Is that your fly-sabre?", + author: "Jesse Pinkman" + }, + { + quote: "Don't bullshit a bullshitter.", + author: "Walter White" + }, + { + quote: "Some people are immune to good advice.", + author: "Walter White" + }, + { + quote: "Well, technically, chemistry is the study of matter. But I prefer to see it as the study of change.", + author: "Walter White" + }, + { + quote: "Find what you love and let it kill you.", + author: "Walter White" + }, + { + quote: "Let's see, how should i put this? I'm in, you're out.", + author: "Walter White" + }, + { + quote: "Never give up control. Live life on your own terms.", + author: "Walter White" + }, + { + quote: "Fear is the real enemy.", + author: "Walter White" + }, + { + quote: "All bad things must come to an end.", + author: "Walter White" + }, + { + quote: "Jesse, you asked me if I was in the meth business or the money business.. Neither. I'm in the empire business.", + author: "Walter White" + }, + { + quote: "Sometimes the forbidden fruit tastes the sweetest.", + author: "Hank Schrader" + }, + { + quote: "Free food always tastes good. Free drinks even better.", + author: "Hank Schrader" + }, + { + quote: "My friends, I promise you that together, we will prosper.", + author: "Gustavo Fring" + }, + { + quote: "Now look buddy, the last thing I want to do is get you in hot water, but some meth monkey had a feeding frenzy in here.", + author: "Hank Schrader" + }, + { + quote: "Fifty years I spent like that. Finding myself awake at three in the morning. But you know what? Ever since my diagnosis, I sleep just fine.", + author: "Walter White" + }, + { + quote: "I told you, Skyler, I warned you for a solid year: you cross me, and there will be consequences.", + author: "Walter White" + }, + { + quote: "I want my kids back. I want my life back. Please tell me – How much is enough? How big does this pile have to be?", + author: "Skyler White" + }, + { + quote: "It’s easy money. Until we catch you.", + author: "Hank Schrader" + }, + { + quote: "I once told a woman I was Kevin Costner and it worked because I believed it.", + author: "Saul Goodman" + }, + { + quote: "Scientists love lasers.", + author: "Saul Goodman" + }, + { + quote: "If you’re committed enough, you can make any story work.", + author: "Saul Goodman" + }, + { + quote: "Did I say you could open your mouth? And, hands off the car!", + author: "Hank Schrader" + }, + { + quote: "If you believe that there’s a hell, we’re pretty much already going there.", + author: "Walter White" + }, + { + quote: "You add plus a douchebag to a minus douchebag and you get, Like, Zero Douchebags.", + author: "Jesse Pinkman" + }, + { + quote: "A guy that clean has to be dirty.", + author: "Hank Schrader" + }, + { + quote: "There is gold in the streets just waiting for someone to come and scoop it up.", + author: "Walter White" + }, + { + quote: "The fun’s over. From here on out, I’m Mr. Low Profile. Just another douche bag with a job and three pairs of Dockers. If I’m lucky, month from now, best-case scenario, I’m managing a Cinnabon in Omaha.", + author: "Saul Goodman" + }, + { + quote: "I am speaking to my family now. Skyler, you are the love of my life. I hope you know that.", + author: "Walter White" + }, + { + quote: "I could have saved her.", + author: "Walter White" + }, + { + quote: "I'm not a criminal. I'm a criminal lawyer.", + author: "Saul Goodman" + }, + { + quote: "I have lived under the threat of death for a year now, and because of that, I've made peace with it.", + author: "Walter White" + }, + { + quote: "I investigate everyone with whom I do business. What careful man wouldn't?", + author: "Gustavo Fring" + }, + { + quote: "It’s like Scarface had sex with Mr. Rogers or something.", + author: "Hank Schrader" + }, + { + quote: "Sitting around, smoking marijuana, eating Cheetos and masturbating do not constitute ‘plans.’", + author: "Walter White" + }, + { + quote: "Gatorade me, bitch!", + author: "Jesse Pinkman" + }, + { + quote: "We're done when I say we're done.", + author: "Walter White" + }, + { + quote: "My name is Skyler White yo. My husband is Walter White... yo.", + author: "Skyler White" + }, + { + quote: "To all law enforcement entities, this is not an admission of guilt.", + author: "Walter White" + }, + { + quote: "We're all on the same page. The one that says, if I can't kill you, you'll sure as shit wish you were dead.", + author: "Jesse Pinkman" + }, + { + quote: "Coin flip is sacred.", + author: "Jesse Pinkman" + }, + { + quote: "You either run from things, or you face them, Mr. White.", + author: "Jesse Pinkman" + }, + { + quote: "Tight. Tight. Tight.", + author: "Tuco Salamanca" + }, + { + quote: "Get busy living or get busy dying.", + author: "Stephen King" + }, + { + quote: "Free to cook anytime, anywhere.", + author: "Jesse Pinkman" + }, + { + quote: "Cooking is art. And the shit I cook is the bomb.", + author: "Jesse Pinkman" + }, + { + quote: "I'm the guy your boss brought here to show you how it's done.", + author: "Jesse Pinkman" + }, + { + quote: "Moral of the story is: I chose a half measure when I should have gone all the way. I'll never make that mistake again. No more half measures, Walter.", + author: "Mike Ehrmantraut" + }, +]; + +const limit = quotes.length; + +module.exports = { + quotes, + limit +}; diff --git a/models/server.js b/models/server.js new file mode 100644 index 0000000..9a53d96 --- /dev/null +++ b/models/server.js @@ -0,0 +1,43 @@ +const express = require('express'); +const cors = require('cors'); + +class Server { + + constructor() { + this.app = express(); + this.port = process.env.PORT || 3001; + + this.paths = { + quotes: '/v1/quotes' + } + + this.middlewares(); + + this.routes(); + } + + middlewares() { + this.app.use(cors()); + this.app.use(express.json()); + } + + routes() { + this.app.use(this.paths.quotes, require('./../routes/quotes')); + } + + listen() { + this.app.listen(this.port, () => { + console.log('Server running on port', this.port); + }) + } +} + +module.exports = Server; +/** + * Old way to handle the entries by cross origin + * app.all('*', function (req, res, next) { + res.set('Access-Control-Allow-Origin', '*'); + next(); + }); + * + */ diff --git a/package-lock.json b/package-lock.json index 6fbb1e5..2a1fa34 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,7 @@ "name": "breaking-bad-quotes", "version": "1.0.0", "dependencies": { + "cors": "^2.8.5", "express": "^4.14.1" } }, @@ -104,6 +105,18 @@ "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", "integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ==" }, + "node_modules/cors": { + "version": "2.8.5", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", + "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==", + "dependencies": { + "object-assign": "^4", + "vary": "^1" + }, + "engines": { + "node": ">= 0.10" + } + }, "node_modules/debug": { "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", @@ -422,6 +435,14 @@ "node": ">= 0.6" } }, + "node_modules/object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/object-inspect": { "version": "1.13.1", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.1.tgz", diff --git a/package.json b/package.json index 44a11bd..dd16a3f 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "start": "node server.js" }, "dependencies": { + "cors": "^2.8.5", "express": "^4.14.1" } -} \ No newline at end of file +} diff --git a/quotes.js b/quotes.js deleted file mode 100644 index 65906cd..0000000 --- a/quotes.js +++ /dev/null @@ -1,532 +0,0 @@ -'use strict'; - -module.exports = [ - { - "quote": "I'm sorry, what were you asking me? Oh, yes, that stupid plastic container I asked you to buy. You see, hydrofluoric acid won't eat through plastic; it will however dissolve metal, rock, glass, ceramic. So there's that.", - "author": "Walter White" - }, - { - "quote": "Alright, I've got the talking pillow now... Okay?", - "author": "Walter White" - }, - { - "quote": "We tried to poison you. We tried to poison you because you are an insane, degenerate piece of filth and you deserve to die.", - "author": "Walter White" - }, - { - "quote": "Alright, tell you what. Both of you pull it out your butts right now, or I go grab a flashlight and some pliers and go exploring.", - "author": "Jesse Pinkman" - }, - { - "quote": "I do not believe fear to be an effective motivator. I want investment. For now, I'm simply interested in time frame.", - "author": "Gustavo Fring" - }, - { - "quote": "When you have children, you always have family. They will always be your priority, your responsibility. And a man, a man provides. And he does it even when he's not appreciated or respected or even loved. He simply bears up and he does it. Because he's a man.", - "author": "Gustavo Fring" - }, - { - "quote": "Hey, tell your douchebag brother-in-law to head towards the light.", - "author": "Jesse Pinkman" - }, - { - "quote": "Did you know that there's an acceptable level of rat turds that can go into candy bars? It's the government, jack. Even government doesn't care that much about quality. You know what is okay to put in hot dogs? Huh? Pig lips and *beep* But I say, hey, have at it bitches 'cause I love hot dogs.", - "author": "Jesse Pinkman" - }, - { - "quote": "The one that says if I can't kill you, you'll sure as *beep* wish you were dead.", - "author": "Jesse Pinkman" - }, - { - "quote": "You won, Walter. You got the job. Do yourself a favor and learn to take yes for an answer.", - "author": "Mike Ehrmantraut" - }, - { - "quote": "The thing is, if you just do stuff and nothing happens, what's it all mean? What's the point? Oh right, this whole thing is about self-acceptance.", - "author": "Jesse Pinkman" - }, - { - "quote": "You are a time bomb, tick-tick-ticking. And I have no intention of being around for the boom.", - "author": "Mike Ehrmantraut" - }, - { - "quote": "Don't drink and drive but if you do, call me.", - "author": "Saul Goodman" - }, - { - "quote": "I am not in danger, Skyler. I AM the danger!", - "author": "Walter White" - }, - { - "quote": "A guy opens his door and gets shot and you think that of me? No. I am the one who knocks!", - "author": "Walter White" - }, - { - "quote": "If that’s true, if you don’t know who I am, then maybe your best course… would be to tread lightly.", - "author": "Walter White" - }, - { - "quote": "Someone has to protect this family from the man who protects this family.", - "author": "Skyler White" - }, - { - "quote": "Smoking marijuana, eating cheetos, and masturbating do not constitute plans in my book.", - "author": "Walter White" - }, - { - "quote": "Stay out of my territory.", - "author": "Walter White" - }, - { - "quote": "Because I say so.", - "author": "Walter White" - }, - { - "quote": "I'm not in the meth business. I'm in the empire business.", - "author": "Walter White" - }, - { - "quote": "You all know exactly who I am. Say my name.", - "author": "Walter White" - }, - { - "quote": "I watched Jane die. I was there. And I watched her die.", - "author": "Walter White" - }, - { - "quote": "I did it for me. I liked it. I was good at it. And... I was really... I was alive.", - "author": "Walter White" - }, - { - "quote": "\"Cap'n Cook?\" That's not you? Like I said, no one is looking for you.", - "author": "Walter White" - }, - { - "quote": "Do you know how much I make a year? I mean, even if I told you, you wouldn't believe it.", - "author": "Walter White" - }, - { - "quote": "Jesus! Just grow some fucking balls!", - "author": "Walter White" - }, - { - "quote": "F*ck you! And your eyebrows!", - "author": "Walter White" - }, - { - "quote": "Send him to Belize? I'll send YOU to Belize.", - "author": "Walter White" - }, - { - "quote": "We're done when I say we're done.", - "author": "Walter White" - }, - { - "quote": "Sitting around, smoking marijuana, eating Cheetos and masturbating do not constitute \"plans\".", - "author": "Walter White" - }, - { - "quote": "I did it for me. I liked it. I was good at it. And I was really... I was alive.", - "author": "Walter White" - }, - { - "quote": "Bitch!", - "author": "Jesse Pinkman" - }, - { - "quote": "So you do have a plan? Yeah, Mr. White! Yeah, science!", - "author": "Jesse Pinkman" - }, - { - "quote": "I'm a criminal, yo.", - "author": "Jesse Pinkman" - }, - { - "quote": "Yeah, bitch! Magnets!", - "author": "Jesse Pinkman" - }, - { - "quote": "You're my free pass... bitch!", - "author": "Jesse Pinkman" - }, - { - "quote": "Fire in the hole, bitch!", - "author": "Jesse Pinkman" - }, - { - "quote": "Did you just bring a bomb into a hospital?", - "author": "Jesse Pinkman" - }, - { - "quote": "Seriously? \"Hello Kitty\"?", - "author": "Jesse Pinkman" - }, - { - "quote": "Speak into the mic, bitch.", - "author": "Jesse Pinkman" - }, - { - "quote": "Better call Saul!", - "author": "Saul Goodman" - }, - { - "quote": "You do seem to have a little “shit creek” action going… You know, FYI, you can buy a paddle.", - "author": "Saul Goodman" - }, - { - "quote": "If I ever get anal polyps, I'll know what to name them.", - "author": "Saul Goodman" - }, - { - "quote": "You two suck at peddling meth.", - "author": "Saul Goodman" - }, - { - "quote": "Clearly, his taste in women is the same as his taste in lawyers.", - "author": "Saul Goodman" - }, - { - "quote": "Congratulations, you’ve just left your family a second-hand Subaru.", - "author": "Saul Goodman" - }, - { - "quote": "I’m not saying it’s not bad. It’s bad. But it could be worse.", - "author": "Saul Goodman" - }, - { - "quote": "I hide in plain sight, same as you.", - "author": "Gustavo Fring" - }, - { - "quote": "May his death satisfy you.", - "author": "Gustavo Fring" - }, - { - "quote": "I will kill your wife, I will kill your son, I will kill your infant daughter.", - "author": "Gustavo Fring" - }, - { - "quote": "Everyone sounds like Meryl Streep with a gun to their head.", - "author": "Mike Ehrmantraut" - }, - { - "quote": "You know how they say it's been a pleasure'? Well... it hasn't.", - "author": "Mike Ehrmantraut" - }, - { - "quote": "Just because you shot Jesse James doesn't mean you are Jesse James.", - "author": "Mike Ehrmantraut" - }, - { - "quote": "No more half-measures, Walter.", - "author": "Mike Ehrmantraut" - }, - { - "quote": "Shut the f*ck up and let me die in peace.", - "author": "Mike Ehrmantraut" - }, - { - "quote": "Keys, scumbag. It's the universal symbol for keys.", - "author": "Mike Ehrmantraut" - }, - { - "quote": "I will put you under the jail.", - "author": "Hank Schrader" - }, - { - "quote": "My name is ASAC Schrader, and you can go f*ck yourself.", - "author": "Hank Schrader" - }, - { - "quote": "They're minerals, Marie! Jesus!", - "author": "Hank Schrader" - }, - { - "quote": "Since when do vegans eat fried chicken?", - "author": "Hank Schrader" - }, - { - "quote": "You're the smartest guy I ever met, and you're too stupid to see he made up his mind 10 minutes ago.", - "author": "Hank Schrader" - }, - { - "quote": "All I can do is wait... for the cancer to come back.", - "author": "Skyler White" - }, - { - "quote": "Put me on your magical boat, man, and sail me down your chocolaty river of meth!", - "author": "Badger" - }, - { - "quote": "Buzz buzz buzz", - "author": "The fly" - }, - { - "quote": "The Universe is Random. Not Inevitable. It's simple Chaos.", - "author": "Walter White" - }, - { - "quote": "Sometimes it just feels better not to talk. At All. About Anything. To Anyone.", - "author": "Walter White" - }, - { - "quote": "Name one thing in this world that is non negotiable.", - "author": "Walter White" - }, - { - "quote": "You are not the guy. You're not capable of being the guy. I had a guy but now I don't. You are not the guy.", - "author": "Mike Ehrmantraut" - }, - { - "quote": "If you don’t know who I am, then maybe your best course would be to tread lightly.", - "author": "Walter White" - }, - { - "quote": "Walter Jr., you're my big man. There are going to be some things that you'll come to learn about me in the next few days. But just know that no matter how it may look, I only had you in my heart. Goodbye!", - "author": "Walter White" - }, - { - "quote": "What I came to realise is that fear, that's the worst of it. That's the real enemy. So, get up, get out in the real world and you kick that bastard as hard you can right in the teeth.", - "author": "Walter White" - }, - { - "quote": "You need to stop focusing on the darkness behind you. The past is the past. Nothing can change what we’ve done.", - "author": "Walter White" - }, - { - "quote": "This is my own private domicile and I will not be harassed... bitch!", - "author": "Jesse Pinkman" - }, - { - "quote": "You don't want a criminal lawyer. You want a criminal lawyer.", - "author": "Jesse Pinkman" - }, - { - "quote": "So roll me further bitch!", - "author": "Jesse Pinkman" - }, - { - "quote": "I Won.", - "author": "Walter White" - }, - { - "quote": "You're never too old for balloons.", - "author": "Mike Ehrmantraut" - }, - { - "quote": "I have spent my whole life scared frightened of things that could happen, might happen, might not happen.", - "author": "Walter White" - }, - { - "quote": "Now, hey, remember, not all learning comes out of books.", - "author": "Jesse Pinkman" - }, - { - "quote": "Then why don't you just fucking die, already?", - "author": "Walter White Jr" - }, - { - "quote": "He handles the businesses, and I handle him.", - "author": "Walter White" - }, - { - "quote": "Shit!", - "author": "Walter White" - }, - { - "quote": "You little bastard.", - "author": "Walter White" - }, - { - "quote": "Stop acting like such a baby.", - "author": "Walter White" - }, - { - "quote": "Is that your fly-sabre?", - "author": "Jesse Pinkman" - }, - { - "quote": "Don't bullshit a bullshitter.", - "author": "Walter White" - }, - { - "quote": "Some people are immune to good advice.", - "author": "Walter White" - }, - { - "quote": "Well, technically, chemistry is the study of matter. But I prefer to see it as the study of change.", - "author": "Walter White" - }, - { - "quote": "Find what you love and let it kill you.", - "author": "Walter White" - }, - { - "quote": "Let's see, how should i put this? I'm in, you're out.", - "author": "Walter White" - }, - { - "quote": "Never give up control. Live life on your own terms.", - "author": "Walter White" - }, - { - "quote": "Fear is the real enemy.", - "author": "Walter White" - }, - { - "quote": "All bad things must come to an end.", - "author": "Walter White" - }, - { - "quote": "Jesse, you asked me if I was in the meth business or the money business.. Neither. I'm in the empire business.", - "author": "Walter White" - }, - { - "quote": "Sometimes the forbidden fruit tastes the sweetest.", - "author": "Hank Schrader" - }, - { - "quote": "Free food always tastes good. Free drinks even better.", - "author": "Hank Schrader" - }, - { - "quote": "My friends, I promise you that together, we will prosper.", - "author": "Gustavo Fring" - }, - { - "quote": "Now look buddy, the last thing I want to do is get you in hot water, but some meth monkey had a feeding frenzy in here.", - "author": "Hank Schrader" - }, - { - "quote": "Fifty years I spent like that. Finding myself awake at three in the morning. But you know what? Ever since my diagnosis, I sleep just fine.", - "author": "Walter White" - }, - { - "quote": "I told you, Skyler, I warned you for a solid year: you cross me, and there will be consequences.", - "author": "Walter White" - }, - { - "quote": "I want my kids back. I want my life back. Please tell me – How much is enough? How big does this pile have to be?", - "author": "Skyler White" - }, - { - "quote": "It’s easy money. Until we catch you.", - "author": "Hank Schrader" - }, - { - "quote": "I once told a woman I was Kevin Costner and it worked because I believed it.", - "author": "Saul Goodman" - }, - { - "quote": "Scientists love lasers.", - "author": "Saul Goodman" - }, - { - "quote": "If you’re committed enough, you can make any story work.", - "author": "Saul Goodman" - }, - { - "quote": "Did I say you could open your mouth? And, hands off the car!", - "author": "Hank Schrader" - }, - { - "quote": "If you believe that there’s a hell, we’re pretty much already going there.", - "author": "Walter White" - }, - { - "quote": "You add plus a douchebag to a minus douchebag and you get, Like, Zero Douchebags.", - "author": "Jesse Pinkman" - }, - { - "quote": "A guy that clean has to be dirty.", - "author": "Hank Schrader" - }, - { - "quote": "There is gold in the streets just waiting for someone to come and scoop it up.", - "author": "Walter White" - }, - { - "quote": "The fun’s over. From here on out, I’m Mr. Low Profile. Just another douche bag with a job and three pairs of Dockers. If I’m lucky, month from now, best-case scenario, I’m managing a Cinnabon in Omaha.", - "author": "Saul Goodman" - }, - { - "quote": "I am speaking to my family now. Skyler, you are the love of my life. I hope you know that.", - "author": "Walter White" - }, - { - "quote": "I could have saved her.", - "author": "Walter White" - }, - { - "quote": "I'm not a criminal. I'm a criminal lawyer.", - "author": "Saul Goodman" - }, - { - "quote": "I have lived under the threat of death for a year now, and because of that, I've made peace with it.", - "author": "Walter White" - }, - { - "quote": "I investigate everyone with whom I do business. What careful man wouldn't?", - "author": "Gustavo Fring" - }, - { - "quote": "It’s like Scarface had sex with Mr. Rogers or something.", - "author": "Hank Schrader" - }, - { - "quote": "Sitting around, smoking marijuana, eating Cheetos and masturbating do not constitute ‘plans.’", - "author": "Walter White" - }, - { - "quote": "Gatorade me, bitch!", - "author": "Jesse Pinkman" - }, - { - "quote": "We're done when I say we're done.", - "author": "Walter White" - }, - { - "quote": "My name is Skyler White yo. My husband is Walter White... yo.", - "author": "Skyler White" - }, - { - "quote": "To all law enforcement entities, this is not an admission of guilt.", - "author": "Walter White" - }, - { - "quote": "We're all on the same page. The one that says, if I can't kill you, you'll sure as shit wish you were dead.", - "author": "Jesse Pinkman" - }, - { - "quote": "Coin flip is sacred.", - "author": "Jesse Pinkman" - }, - { - "quote": "You either run from things, or you face them, Mr. White.", - "author": "Jesse Pinkman" - }, - { - "quote": "Tight. Tight. Tight.", - "author": "Tuco Salamanca" - }, - { - "quote": "Get busy living or get busy dying.", - "author": "Stephen King" - }, - { - "quote": "Free to cook anytime, anywhere.", - "author": "Jesse Pinkman" - }, - { - "quote": "Cooking is art. And the shit I cook is the bomb.", - "author": "Jesse Pinkman" - }, - { - "quote": "I'm the guy your boss brought here to show you how it's done.", - "author": "Jesse Pinkman" - }, - { - "quote": "Moral of the story is: I chose a half measure when I should have gone all the way. I'll never make that mistake again. No more half measures, Walter.", - "author": "Mike Ehrmantraut" - }, -]; diff --git a/quotesRepository.js b/quotesRepository.js deleted file mode 100644 index 4a4dfc7..0000000 --- a/quotesRepository.js +++ /dev/null @@ -1,21 +0,0 @@ -'use strict'; - -const quotes = require('./quotes'); - -const getRandom = (numberOfQuotes) => { - const limit = numberOfQuotes > quotes.length ? quotes.length : numberOfQuotes; - - const out = new Array(limit); - - const availableQuotes = quotes.slice(); - - for (const i = 0; i < limit; i++) { - out[i] = availableQuotes.splice(Math.floor(Math.random() * availableQuotes.length), 1)[0]; - } - - return out; -} - -module.exports = { - getRandom -}; diff --git a/routes/quotes.js b/routes/quotes.js new file mode 100644 index 0000000..7d21a48 --- /dev/null +++ b/routes/quotes.js @@ -0,0 +1,8 @@ +const { Router } = require('express'); +const { getRandom } = require('../controllers/quotes.controller'); + +const router = Router(); + +router.get('/:num?', getRandom); + +module.exports = router; \ No newline at end of file diff --git a/server.js b/server.js deleted file mode 100644 index 83786a6..0000000 --- a/server.js +++ /dev/null @@ -1,26 +0,0 @@ -'use strict'; - -var express = require('express'); -var quotesRepository = require('./quotesRepository'); -var app = express(); -var port = process.env.PORT || 3001; - -app.all('*', function (req, res, next) { - res.set('Access-Control-Allow-Origin', '*'); - next(); -}); - -app.get('/v1/quote/:id', function(req, res) { - res.send({ - quote: 'Yo soy el mero macizo', - author: 'Alex Vargas', - }) -}) -app.get('/v1/quotes/:num?', function (req, res) { - res.send(quotesRepository.getRandom(req.params.num || 1)); -}); - - -app.listen(port, function () { - console.log('Server running on port', port); -}) \ No newline at end of file From 78d9359984653d2655f2925d9a5b999253bff7e1 Mon Sep 17 00:00:00 2001 From: Alex Vargas Date: Thu, 4 Jan 2024 10:57:49 -0600 Subject: [PATCH 5/7] Feature get quote by id was added --- controllers/quotes.controller.js | 10 +++++++++- helpers/validateFields.js | 14 ++++++++++++++ package-lock.json | 28 +++++++++++++++++++++++++++- package.json | 3 ++- routes/quote.js | 0 routes/quotes.js | 14 ++++++++++++-- 6 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 helpers/validateFields.js create mode 100644 routes/quote.js diff --git a/controllers/quotes.controller.js b/controllers/quotes.controller.js index 47e0eba..eaba373 100644 --- a/controllers/quotes.controller.js +++ b/controllers/quotes.controller.js @@ -14,6 +14,14 @@ const getRandom = (req = request, res = response) => { res.send(out); } +const getById = (req = request, res = response) => { + const { id } = req.params; + const _id = id > limit ? limit : id; + + res.send(quotes[_id]); +} + module.exports = { - getRandom + getRandom, + getById } \ No newline at end of file diff --git a/helpers/validateFields.js b/helpers/validateFields.js new file mode 100644 index 0000000..9a58dbb --- /dev/null +++ b/helpers/validateFields.js @@ -0,0 +1,14 @@ +const {validationResult} = require('express-validator'); + +const validateFields = (req, res, next) => { + const errors = validationResult(req); + if(!errors.isEmpty()) { + return res.status(400).json(errors); + } + + next(); +} + +module.exports = { + validateFields +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 2a1fa34..148cf2f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,8 @@ "version": "1.0.0", "dependencies": { "cors": "^2.8.5", - "express": "^4.14.1" + "express": "^4.14.1", + "express-validator": "^7.0.1" } }, "node_modules/accepts": { @@ -222,6 +223,18 @@ "node": ">= 0.10.0" } }, + "node_modules/express-validator": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/express-validator/-/express-validator-7.0.1.tgz", + "integrity": "sha512-oB+z9QOzQIE8FnlINqyIFA8eIckahC6qc8KtqLdLJcU3/phVyuhXH3bA4qzcrhme+1RYaCSwrq+TlZ/kAKIARA==", + "dependencies": { + "lodash": "^4.17.21", + "validator": "^13.9.0" + }, + "engines": { + "node": ">= 8.0.0" + } + }, "node_modules/finalhandler": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.2.0.tgz", @@ -371,6 +384,11 @@ "node": ">= 0.10" } }, + "node_modules/lodash": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" + }, "node_modules/media-typer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", @@ -665,6 +683,14 @@ "node": ">= 0.4.0" } }, + "node_modules/validator": { + "version": "13.11.0", + "resolved": "https://registry.npmjs.org/validator/-/validator-13.11.0.tgz", + "integrity": "sha512-Ii+sehpSfZy+At5nPdnyMhx78fEoPDkR2XW/zimHEL3MyGJQOCQ7WeP20jPYRz7ZCpcKLB21NxuXHF3bxjStBQ==", + "engines": { + "node": ">= 0.10" + } + }, "node_modules/vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", diff --git a/package.json b/package.json index dd16a3f..c2a1794 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ }, "dependencies": { "cors": "^2.8.5", - "express": "^4.14.1" + "express": "^4.14.1", + "express-validator": "^7.0.1" } } diff --git a/routes/quote.js b/routes/quote.js new file mode 100644 index 0000000..e69de29 diff --git a/routes/quotes.js b/routes/quotes.js index 7d21a48..e077bec 100644 --- a/routes/quotes.js +++ b/routes/quotes.js @@ -1,8 +1,18 @@ const { Router } = require('express'); -const { getRandom } = require('../controllers/quotes.controller'); +const { check } = require('express-validator'); +const { getRandom, getById } = require('../controllers/quotes.controller'); +const { validateFields } = require('../helpers/validateFields'); const router = Router(); -router.get('/:num?', getRandom); +router.get('/:num?', [ + check('num', 'The parameter must be an integer numeric value').isInt(), + validateFields +], getRandom); + +router.get('/by/:id', [ + check('id', 'The id must be an integer numeric value').isInt(), + validateFields +], getById); module.exports = router; \ No newline at end of file From 64f73539ce30bf5413ceb28f9c28b2ecc24c0fa7 Mon Sep 17 00:00:00 2001 From: Alex Vargas Date: Thu, 4 Jan 2024 11:04:15 -0600 Subject: [PATCH 6/7] README modified with the new getQuoteById feature added --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 17f934e..6d3ef52 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,17 @@ Returns an array with `{number}` quotes e.g. `GET /v1/quotes/5`. } ] +### `GET /v1/quotes/by/{id}` + +Returns a specific quote from the 'breaking bad' quotes bank by the id given. + +> [https://api.breakingbadquotes.xyz/v1/quotes/by/1](https://api.breakingbadquotes.xyz/v1/quotes/by/1) + + { + "quote": "Alright, I've got the talking pillow now... Okay?", + "author": "Walter White" + } + ## Postman From 361c5b3173a49952599e174f55537f6de4a4f051 Mon Sep 17 00:00:00 2001 From: Alex Vargas Date: Thu, 4 Jan 2024 11:22:23 -0600 Subject: [PATCH 7/7] version 1.1.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c2a1794..a649593 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "breaking-bad-quotes", - "version": "1.0.0", + "version": "1.1.1", "description": "An API for retrieving Breaking Bad quotes", "repository": { "type": "git",