Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
/node_modules
/dist
/data
src/client.ts
1,875 changes: 1,875 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"axios": "^0.19.2",
"bcryptjs": "^2.4.3",
"express": "^4.17.1",
"nodemon": "^2.0.4",
"ts-node-dev": "^1.0.0-pre.44"
},
"prettier": {
Copy link
Copy Markdown

@pugaIsaias pugaIsaias Jun 23, 2020

Choose a reason for hiding this comment

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

Veo que ya instalaste prettier pero creo que no se esta aplicando el formato, por los espacios en blanco en tu codigo.

Sugerencia: Puedes colocar el siguiente codigo que me funciono en los setting.json de tu editor:

"editor.codeActionsOnSave": {
		"source.organizeImports": true
	},
"editor.formatOnSave": true,

Expand Down
32 changes: 32 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

import axios from "axios"
import datos from "./datos.json"


async function postData() {
axios.post('http://95.217.235.69/',datos)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
axios.post('http://95.217.235.69/',datos)
axios.post('http://95.217.235.69/', datos)

ya instalaste prettier?

.then(function(response){
console.log(response);
}).catch(function(error){
console.log(error);
})
}


function getData() {
axios.get(`http://95.217.235.69/${process.env.EMAIL}`,{

Copy link
Copy Markdown

@danbart danbart Jun 23, 2020

Choose a reason for hiding this comment

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

te recomiendo instalar la extensión prettier en tu editor para aplicarlo en los archivos de client.ts y data.json

en el archivo settings.json de tu editor agrega lo siguiente:

"editor.codeActionsOnSave": {
    "source.organizeImports": true
  },


headers:{
"Content-Type": "application/json",
"x-password": process.env.PASSWORD,
Comment on lines +17 to +22
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
axios.get(`http://95.217.235.69/${process.env.EMAIL}`,{
headers:{
"Content-Type": "application/json",
"x-password": process.env.PASSWORD,
axios.get("http://95.217.235.69/"+data.contactInfo.emailAddress,{
headers:{
"Content-Type": "application/json",
"x-password": data.credentials.password,

Para mantenerse consistente, y no causar mal entendidos; como que process.env.EMAIL en GET no es igual a data.contactInfo.emailAddress en POST, y que no estamos buscando dos cosas totalmente diferente.

Sugerencia: podemos utilizar la misma variable importada de datos para llenar los parámetros tanto del POST como el GET.

}
}).then(function(response){
console.log(response);
}).catch(function(error){
console.log(error);
})
}

postData();
var s = 0
Copy link
Copy Markdown

@danbart danbart Jun 23, 2020

Choose a reason for hiding this comment

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

te sugiero que elimines variables innecesarias y que ejecutes la función de getData() dentro de este archivo

Suggested change
var s = 0
getData()

28 changes: 28 additions & 0 deletions src/datos.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"contactInfo": {
"fullName": "Jose Eduardo Lopez Gonzalez",
"emailAddress": "[email protected]"
},
"github": {
"profileURL": "https://github.com/jelg14",
"username": "jelg14"
},
"credentials": {
"password": "asdf"
Comment on lines +10 to +11
Copy link
Copy Markdown

@pugaIsaias pugaIsaias Jun 23, 2020

Choose a reason for hiding this comment

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

Suggested change
"credentials": {
"password": "asdf"
"credentials": {
"password": ""

Ingresar la contraseña directamente desde el código es una mala practica de seguridad. Y veo que al parecer tambien la tienes guardado en process.env.PASSWORD. Lo cual es correcto.

Por favor puedes borrar la contraseña del .json. Y realizar los cambios necesarios en tu código para que continué funcionando.

Sugerencia: Para evitar redundancias, mantenerlo modular, y no manipular mucho de los datos dentro del client.ts. Y ya que no se pueden asignar valores desde el datos.json, puedes utilizar un datos.ts para asignar los valores necesarios para el POST. He importar para utilizar en client.ts.

},
"personalInfo": {
"questions": [{
"question": "If I was a Sr. Programmer, I would like to build:",
"answer": "If I was a S. Programmer, I would like to create a technology that could change the world"
},
{
"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:https://github.com/facebook/react/blob/655affa302437208e6f03c9ca6d170ea1707ace3/packages/react-reconciler/src/ReactFiberHooks.new.js#L1878"
},
{
"question": "code is poetry, because:",
"answer": "code is poetry because with it you can create anything you can imagine"
}
]
}
}
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Ajv from "ajv";
import { compare, genSalt, hash } from "bcryptjs";
import express from "express";
import express, { Request, Response } from "express";
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

las importaciones de Request y Response son innecesarias, tienes que regresar este archivo a su estado original, para esto intenta hacer un git checkout master src/index.ts.

Suggested change
import express, { Request, Response } from "express";
import express from "express";

import fs from "fs";
import schema from "./schema.json";
import server from "./server";
Expand Down
197 changes: 90 additions & 107 deletions src/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,34 @@
"title": "The root schema",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Deja sólo la data necesaria, en este caso tu data.

"description": "The root schema comprises the entire JSON document.",
"default": {},
"examples": [
{
"contactInfo": {
"fullName": "Gus",
"emailAddress": "[email protected]"
},
"github": {
"profileURL": "",
"username": ""
},
"credentials": {
"password": "password"
},
"personalInfo": {
"questions": [
{
"question": "If I was a Sr. Programmer, I would like to build:",
"answer": "..."
},
{
"question": "Por favor indica el URL que me lleva a la línea de código de la definición de React.useEffect",
"answer": "..."
},
{
"question": "code is poetry, because:",
"answer": ""
}
]
}
"examples": [{
"contactInfo": {
"fullName": "Gus",
"emailAddress": "[email protected]"
},
"github": {
"profileURL": "",
"username": ""
},
"credentials": {
"password": "password"
},
"personalInfo": {
"questions": [{
"question": "If I was a Sr. Programmer, I would like to build:",
"answer": "..."
},
{
"question": "Por favor indica el URL que me lleva a la línea de código de la definición de React.useEffect",
"answer": "..."
},
{
"question": "code is poetry, because:",
"answer": ""
}
]
}
],
}],
"required": [
"contactInfo",
"github",
Expand All @@ -50,12 +47,10 @@
"title": "The contactInfo schema",
"description": "An explanation about the purpose of this instance.",
"default": {},
"examples": [
{
"fullName": "Gus",
"emailAddress": "[email protected]"
}
],
"examples": [{
"fullName": "Gus",
"emailAddress": "[email protected]"
}],
"required": [
"fullName",
"emailAddress"
Expand Down Expand Up @@ -90,12 +85,10 @@
"title": "The github schema",
"description": "An explanation about the purpose of this instance.",
"default": {},
"examples": [
{
"profileURL": "",
"username": ""
}
],
"examples": [{
"profileURL": "",
"username": ""
}],
"required": [
"profileURL",
"username"
Expand Down Expand Up @@ -130,11 +123,9 @@
"title": "The credentials schema",
"description": "An explanation about the purpose of this instance.",
"default": {},
"examples": [
{
"password": "password"
}
],
"examples": [{
"password": "password"
}],
"required": [
"password"
],
Expand All @@ -158,24 +149,21 @@
"title": "The personalInfo schema",
"description": "An explanation about the purpose of this instance.",
"default": {},
"examples": [
{
"questions": [
{
"question": "If I was a Sr. Programmer, I would like to build:",
"answer": "..."
},
{
"question": "Por favor indica el URL que me lleva a la línea de código de la definición de React.useEffect",
"answer": "..."
},
{
"question": "code is poetry, because:",
"answer": ""
}
]
}
],
"examples": [{
"questions": [{
"question": "If I was a Sr. Programmer, I would like to build:",
"answer": "..."
},
{
"question": "Por favor indica el URL que me lleva a la línea de código de la definición de React.useEffect",
"answer": "..."
},
{
"question": "code is poetry, because:",
"answer": ""
}
]
}],
"required": [
"questions"
],
Expand All @@ -188,8 +176,7 @@
"description": "An explanation about the purpose of this instance.",
"default": [],
"examples": [
[
{
[{
"question": "If I was a Sr. Programmer, I would like to build:",
"answer": "..."
},
Expand All @@ -201,48 +188,44 @@
],
"additionalItems": true,
"items": {
"anyOf": [
{
"$id": "#/properties/personalInfo/properties/questions/items/anyOf/0",
"type": "object",
"title": "The first anyOf schema",
"description": "An explanation about the purpose of this instance.",
"default": {},
"examples": [
{
"question": "If I was a Sr. Programmer, I would like to build:",
"answer": "..."
}
],
"required": [
"question",
"answer"
],
"additionalProperties": true,
"properties": {
"question": {
"$id": "#/properties/personalInfo/properties/questions/items/anyOf/0/properties/question",
"type": "string",
"title": "The question schema",
"description": "An explanation about the purpose of this instance.",
"default": "",
"examples": [
"If I was a Sr. Programmer, I would like to build:"
]
},
"answer": {
"$id": "#/properties/personalInfo/properties/questions/items/anyOf/0/properties/answer",
"type": "string",
"title": "The answer schema",
"description": "An explanation about the purpose of this instance.",
"default": "",
"examples": [
"..."
]
}
"anyOf": [{
"$id": "#/properties/personalInfo/properties/questions/items/anyOf/0",
"type": "object",
"title": "The first anyOf schema",
"description": "An explanation about the purpose of this instance.",
"default": {},
"examples": [{
"question": "If I was a Sr. Programmer, I would like to build:",
"answer": "..."
}],
"required": [
"question",
"answer"
],
"additionalProperties": true,
"properties": {
"question": {
"$id": "#/properties/personalInfo/properties/questions/items/anyOf/0/properties/question",
"type": "string",
"title": "The question schema",
"description": "An explanation about the purpose of this instance.",
"default": "",
"examples": [
"If I was a Sr. Programmer, I would like to build:"
]
},
"answer": {
"$id": "#/properties/personalInfo/properties/questions/items/anyOf/0/properties/answer",
"type": "string",
"title": "The answer schema",
"description": "An explanation about the purpose of this instance.",
"default": "",
"examples": [
"..."
]
}
}
],
}],
"$id": "#/properties/personalInfo/properties/questions/items"
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ import express from "express";
export const server = express();
server.use(express.json());

export default server;
export default server;