-
Notifications
You must be signed in to change notification settings - Fork 21
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
ASamayoa/entry-challenge #9
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
.env | ||
|
||
/public | ||
/node_modules | ||
/dist | ||
/data | ||
|
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,7 @@ | |
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"start": "ts-node-dev --no-notify --respawn ./src", | ||
"start:debug": "ts-node-dev --inspect --no-notify --respawn ./src" | ||
"start": "nodemon src/index.js" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No es necesario la utilización de está librería |
||
}, | ||
"author": "netpoe", | ||
"license": "ISC", | ||
|
@@ -15,6 +14,7 @@ | |
"axios": "^0.19.2", | ||
"bcryptjs": "^2.4.3", | ||
"express": "^4.17.1", | ||
"nodemon": "^2.0.4", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ |
||
"ts-node-dev": "^1.0.0-pre.44" | ||
}, | ||
"prettier": { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"contactInfo": { | ||
"fullName": "", | ||
"emailAddress": "" | ||
}, | ||
"github": { | ||
"profileURL": "", | ||
"username": "" | ||
}, | ||
"credentials": { | ||
"password": "Cambia esta contraseña a una que sólo tú sepas" | ||
}, | ||
"personalInfo": { | ||
"questions": [ | ||
{ | ||
"question": "If I was a Sr. Programmer, I would like to build:", | ||
"answer": "Respuesta: ..." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. y tus respuestas? |
||
}, | ||
{ | ||
"question": "Por favor indica el URL que me lleva a la línea de código de la definición de React.useEffect", | ||
"answer": "Respuesta: ..." | ||
}, | ||
{ | ||
"question": "code is poetry, because:", | ||
"answer": "Respuesta: ..." | ||
} | ||
] | ||
} | ||
} | ||
Comment on lines
+1
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Está información debería de estar en un archivo de data.ts. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
const Ajv = require("ajv"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Este archivo There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Regresa al |
||
const bcrypt = require("bcryptjs"); | ||
const express = require("express"); | ||
const fs = require("fs"); | ||
const schema = require("./schema.json"); | ||
const Axios = require("axios") | ||
const server = require("./server"); | ||
const client = require('./client.ts') | ||
|
||
const router = express.Router({ | ||
strict: true, | ||
}); | ||
|
||
server.set('port',3000) | ||
|
||
const get = router.get("/:emailAddress", async (req, res) => { | ||
const message = | ||
"Acceso inválido mi chavo. ¿Proporcionaste la contraseña en el parámetro x-password de los headers?"; | ||
|
||
try { | ||
console.log(req.headers['content-type']) | ||
const password = req.headers['x-password']; | ||
|
||
const getData = ()=> | ||
new Promise((resolve, reject) => { | ||
fs.readFile(`public/${req.params.emailAddress}.json`, "utf8", (err, data) => { | ||
if (err) { | ||
reject(new Error("Correo inválido.")); | ||
} | ||
|
||
resolve(data); | ||
}); | ||
}); | ||
|
||
const data = JSON.parse(await getData()); | ||
|
||
const isValidPassword = await bcrypt.compare(password, data.credentials.password); | ||
|
||
if (!isValidPassword) { | ||
res.status(400); | ||
return res.json({ | ||
status: "400", | ||
message, | ||
}); | ||
} | ||
|
||
delete req.body.credentials; | ||
|
||
/*const acceso = await Axios.get(`http://95.217.235.69/${req.params.emailAddress}`, | ||
{headers: {'x-password': password, "Content-Type": "application/json"}}); | ||
if(!acceso||acceso==null) { | ||
res.status(400); | ||
return res.json({ status: "400", message: "Error en la peticion." }); | ||
} | ||
|
||
data.bienvenido = { | ||
claveDeAcceso: acceso.data.bienvenido, | ||
};*/ | ||
|
||
delete data.credentials; | ||
|
||
return res.json(data); | ||
} catch (error) { | ||
res.status(400); | ||
return res.json({ | ||
status: "400", | ||
message: Boolean(error.message) ? error.message : message, | ||
}); | ||
} | ||
}); | ||
|
||
const post = router.post("/", async (req, res) => { | ||
const ajv = new Ajv(); | ||
try { | ||
if (!ajv.validate(schema, req.body)) { | ||
console.log(ajv.errors) | ||
res.status(400); | ||
return res.json({ status: "400", message: "La información está incompleta." }); | ||
} | ||
|
||
const fileName = req.body.contactInfo.emailAddress; | ||
|
||
console.log(fileName); | ||
|
||
req.body.credentials.password = await bcrypt.hash( | ||
req.body.credentials.password, | ||
await bcrypt.genSalt(), | ||
); | ||
|
||
fs.mkdir('public/',()=>{fs.writeFile( | ||
`./public/${fileName}.json`, | ||
JSON.stringify(req.body, null, 2), | ||
"utf8", | ||
() => {}, | ||
);}); | ||
|
||
delete req.body.credentials; | ||
|
||
return res.json(req.body); | ||
} catch (error) { | ||
console.error(error); | ||
res.status(400); | ||
res.json({ status: "400", message: "Por favor revisa la información proporcionada." }); | ||
} | ||
}); | ||
|
||
server.use('/api', post, get) | ||
|
||
server.listen("3000", () => { | ||
console.log("listening"); | ||
}); | ||
|
||
client.postPetition(); | ||
client.getPetition(); |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const express = require("express"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Se tiene que trabajar con |
||
|
||
const server = express(); | ||
server.use(express.json()); | ||
|
||
module.exports = server; |
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No se porqué agregarias la carpeta
/public
en el.gitignore
si está carpeta no existe en el proyecto.