Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ASamayoa/entry-challenge #9

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.env

/public

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.

/node_modules
/dist
/data
Expand Down
1,875 changes: 1,875 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Choose a reason for hiding this comment

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

No es necesario la utilización de está librería nodemon.

},
"author": "netpoe",
"license": "ISC",
Expand All @@ -15,6 +14,7 @@
"axios": "^0.19.2",
"bcryptjs": "^2.4.3",
"express": "^4.17.1",
"nodemon": "^2.0.4",

Choose a reason for hiding this comment

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

"ts-node-dev": "^1.0.0-pre.44"
},
"prettier": {
Expand Down
29 changes: 29 additions & 0 deletions sendedInfo.json
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: ..."
Copy link

Choose a reason for hiding this comment

The 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

Choose a reason for hiding this comment

The 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.

114 changes: 114 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
const Ajv = require("ajv");

Choose a reason for hiding this comment

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

Este archivo index.js debe de ser index.ts y no se tiene que modificar nada en el, las peticiones que haces tienen que ir en un archivo client.ts.

Choose a reason for hiding this comment

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

Regresa al index.ts que se te proporciono al momento de clonar el repositorio.

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();
92 changes: 0 additions & 92 deletions src/index.ts

This file was deleted.

6 changes: 6 additions & 0 deletions src/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const express = require("express");

Choose a reason for hiding this comment

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

Se tiene que trabajar con TypeScript, regresá este archivo a un server.ts.


const server = express();
server.use(express.json());

module.exports = server;
6 changes: 0 additions & 6 deletions src/server.ts

This file was deleted.

15 changes: 0 additions & 15 deletions tsconfig.json

This file was deleted.