diff --git a/.gitignore b/.gitignore index a91eeca..e2b43fa 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,3 @@ /node_modules /dist /data -src/client.ts \ No newline at end of file diff --git a/package.json b/package.json index 2bc6d97..761caa5 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,10 @@ "ajv": "^6.12.2", "axios": "^0.19.2", "bcryptjs": "^2.4.3", + "dotenv": "^8.2.0", "express": "^4.17.1", + "fetch": "^1.1.0", + "prettier": "^2.0.5", "ts-node-dev": "^1.0.0-pre.44" }, "prettier": { diff --git a/src/client.ts b/src/client.ts new file mode 100644 index 0000000..8d15112 --- /dev/null +++ b/src/client.ts @@ -0,0 +1,19 @@ +/** + * nombre: Luis Abel Pozuelos Juares + * correo: lpozuelos@irc.com.gt + */ + +// import post profile function +import { postProfile } from "./postProfile"; +// import get profile funtion +import { getProfile } from "./getProfile"; +// envieroment vars +require("dotenv").config(); +//importamos informacion del perfil +const profile = require("./profile.json"); + +profile.credentials.password = process.env.CLAVE; +//call function PostProfile +postProfile(process.env.URL, profile); +//call gunction getProfile +getProfile(process.env.URL, profile.contactInfo.emailAddress, process.env.CLAVE); diff --git a/src/getProfile.ts b/src/getProfile.ts new file mode 100644 index 0000000..d6298d6 --- /dev/null +++ b/src/getProfile.ts @@ -0,0 +1,24 @@ +/** + * nombre: Luis Abel Pozuelos Juares + * correo: lpozuelos@irc.com.gt + */ +import { request } from "http"; +import axios from "axios"; + +/** + * postProfile + * parameters url, port, email, password + */ + +export async function getProfile(url: string, email: string, passowrd: string) { + axios + .get(`http://${url}/` + email, { + headers: { "Content-Type": "application/json", "x-password": passowrd }, + }) + .then((res) => { + console.log(res.data.bienvenido.claveDeAcceso); + }) + .catch((error) => { + console.log("error " + error); + }); +} diff --git a/src/index.ts b/src/index.ts index 513b905..671e046 100644 --- a/src/index.ts +++ b/src/index.ts @@ -18,7 +18,7 @@ server.get("/:emailAddress", async (req: Request, res: Response) => { const getData = (): Promise => new Promise((resolve, reject) => { - fs.readFile(`./data/${req.params.emailAddress}.json`, "utf8", (err, data) => { + fs.readFile(`./data/${req.conact.emailAddress}.json`, "utf8", (err, data) => { if (Boolean(err)) { reject(new Error("Correo inválido.")); } diff --git a/src/postProfile.ts b/src/postProfile.ts new file mode 100644 index 0000000..7ff3de5 --- /dev/null +++ b/src/postProfile.ts @@ -0,0 +1,21 @@ +/** + * nombre: Luis Abel Pozuelos Juares + * correo: lpozuelos@irc.com.gt +*/ + +import axios from 'axios' + +/** + * postProfile + * parameters url, json data + */ +export async function postProfile(url, profile) { + + axios.post(`http://${url}/`, profile) + .then((res) => { + console.log(res.status); + }) + .catch((err) => { + console.error("error " + err); + }); +} \ No newline at end of file diff --git a/src/profile.json b/src/profile.json new file mode 100644 index 0000000..abf5b70 --- /dev/null +++ b/src/profile.json @@ -0,0 +1,29 @@ +{ + "contactInfo": { + "fullName": "Luis Abel Pozuelos Juarez", + "emailAddress": "lpozuelos@irc.com.gt" + }, + "github": { + "profileURL": "https://github.com/blindlp", + "username": "blindlp" + }, + "credentials": { + "password": "" + }, + "personalInfo": { + "questions": [ + { + "question": "If I was a Sr. Programmer, I would like to build:", + "answer": "I create new application to bring more easily to solve problems in my field,sharing my knowledge and I trying to find new opportunities to develop business and create new sources of work." + }, + { + "question": "Por favor indica el URL que me lleva a la línea de código de la definición de React.useEffect", + "answer": "https://es.reactjs.org/docs/hooks-reference.html#useeffect " + }, + { + "question": "code is poetry, because:", + "answer": "it's poetry because you need to have different feelings to create and develop your abilities, I think is a king of art the way we express our code because its unique everybody has his own style" + } + ] + } +} diff --git a/yarn.lock b/yarn.lock index a12cac9..189748f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -74,6 +74,13 @@ bcryptjs@^2.4.3: resolved "https://registry.yarnpkg.com/bcryptjs/-/bcryptjs-2.4.3.tgz#9ab5627b93e60621ff7cdac5da9733027df1d0cb" integrity sha1-mrVie5PmBiH/fNrF2pczAn3x0Ms= +biskviit@1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/biskviit/-/biskviit-1.0.1.tgz#037a0cd4b71b9e331fd90a1122de17dc49e420a7" + integrity sha1-A3oM1LcbnjMf2QoRIt4X3EnkIKc= + dependencies: + psl "^1.1.7" + body-parser@1.19.0: version "1.19.0" resolved "https://registry.yarnpkg.com/body-parser/-/body-parser-1.19.0.tgz#96b2709e57c9c4e09a6fd66a8fd979844f69f08a" @@ -202,6 +209,11 @@ diff@^4.0.1: resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d" integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A== +dotenv@^8.2.0: + version "8.2.0" + resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-8.2.0.tgz#97e619259ada750eea3e4ea3e26bceea5424b16a" + integrity sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw== + dynamic-dedupe@^0.3.0: version "0.3.0" resolved "https://registry.yarnpkg.com/dynamic-dedupe/-/dynamic-dedupe-0.3.0.tgz#06e44c223f5e4e94d78ef9db23a6515ce2f962a1" @@ -219,6 +231,13 @@ encodeurl@~1.0.2: resolved "https://registry.yarnpkg.com/encodeurl/-/encodeurl-1.0.2.tgz#ad3ff4c86ec2d029322f5a02c3a9a606c95b3f59" integrity sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k= +encoding@0.1.12: + version "0.1.12" + resolved "https://registry.yarnpkg.com/encoding/-/encoding-0.1.12.tgz#538b66f3ee62cd1ab51ec323829d1f9480c74beb" + integrity sha1-U4tm8+5izRq1HsMjgp0flIDHS+s= + dependencies: + iconv-lite "~0.4.13" + error-ex@^1.2.0: version "1.3.2" resolved "https://registry.yarnpkg.com/error-ex/-/error-ex-1.3.2.tgz#b4ac40648107fdcdcfae242f428bea8a14d4f1bf" @@ -282,6 +301,14 @@ fast-json-stable-stringify@^2.0.0: resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz#874bf69c6f404c2b5d99c481341399fd55892633" integrity sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw== +fetch@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/fetch/-/fetch-1.1.0.tgz#0a8279f06be37f9f0ebb567560a30a480da59a2e" + integrity sha1-CoJ58Gvjf58Ou1Z1YKMKSA2lmi4= + dependencies: + biskviit "1.0.1" + encoding "0.1.12" + filewatcher@~3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/filewatcher/-/filewatcher-3.0.1.tgz#f4a1957355ddaf443ccd78a895f3d55e23c8a034" @@ -386,7 +413,7 @@ http-errors@~1.7.2: statuses ">= 1.5.0 < 2" toidentifier "1.0.0" -iconv-lite@0.4.24: +iconv-lite@0.4.24, iconv-lite@~0.4.13: version "0.4.24" resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b" integrity sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA== @@ -664,6 +691,11 @@ pinkie@^2.0.0: resolved "https://registry.yarnpkg.com/pinkie/-/pinkie-2.0.4.tgz#72556b80cfa0d48a974e80e77248e80ed4f7f870" integrity sha1-clVrgM+g1IqXToDnckjoDtT3+HA= +prettier@^2.0.5: + version "2.0.5" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.0.5.tgz#d6d56282455243f2f92cc1716692c08aa31522d4" + integrity sha512-7PtVymN48hGcO4fGjybyBSIWDsLU4H4XlvOHfq91pz9kkGlonzwTfYkaIEwiRg/dAJF9YlbsduBAgtYLi+8cFg== + proxy-addr@~2.0.5: version "2.0.6" resolved "https://registry.yarnpkg.com/proxy-addr/-/proxy-addr-2.0.6.tgz#fdc2336505447d3f2f2c638ed272caf614bbb2bf" @@ -672,6 +704,11 @@ proxy-addr@~2.0.5: forwarded "~0.1.2" ipaddr.js "1.9.1" +psl@^1.1.7: + version "1.8.0" + resolved "https://registry.yarnpkg.com/psl/-/psl-1.8.0.tgz#9326f8bcfb013adcc005fdff056acce020e51c24" + integrity sha512-RIdOzyoavK+hA18OGGWDqUTsCLhtA7IcZ/6NCs4fFJaHBDab+pDDmDIByWFRQJq2Cd7r1OoQxBGKOaztq+hjIQ== + punycode@^2.1.0: version "2.1.1" resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec"