Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
noSQL
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mariana Molina Reyes
noSQL
Commits
a2334768
Commit
a2334768
authored
Nov 3, 2019
by
Mariana Molina
Browse files
Options
Downloads
Patches
Plain Diff
Arreglo problema con API POST
parent
843ce3af
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
node_modules/body-parser/package.json
+6
-6
6 additions, 6 deletions
node_modules/body-parser/package.json
src/index.js
+4
-0
4 additions, 0 deletions
src/index.js
src/routes/user.js
+23
-14
23 additions, 14 deletions
src/routes/user.js
with
33 additions
and
20 deletions
node_modules/body-parser/package.json
+
6
−
6
View file @
a2334768
{
{
"_from"
:
"body-parser"
,
"_from"
:
"body-parser
@^1.19.0
"
,
"_id"
:
"body-parser@1.19.0"
,
"_id"
:
"body-parser@1.19.0"
,
"_inBundle"
:
false
,
"_inBundle"
:
false
,
"_integrity"
:
"sha512-dhEPs72UPbDnAQJ9ZKMNTP6ptJaionhP5cBb541nXPlW60Jepo9RV/a4fX4XWW9CuFNK22krhrj1+rgzifNCsw=="
,
"_integrity"
:
"sha512-dhEPs72UPbDnAQJ9ZKMNTP6ptJaionhP5cBb541nXPlW60Jepo9RV/a4fX4XWW9CuFNK22krhrj1+rgzifNCsw=="
,
"_location"
:
"/body-parser"
,
"_location"
:
"/body-parser"
,
"_phantomChildren"
:
{},
"_phantomChildren"
:
{},
"_requested"
:
{
"_requested"
:
{
"type"
:
"
tag
"
,
"type"
:
"
range
"
,
"registry"
:
true
,
"registry"
:
true
,
"raw"
:
"body-parser"
,
"raw"
:
"body-parser
@^1.19.0
"
,
"name"
:
"body-parser"
,
"name"
:
"body-parser"
,
"escapedName"
:
"body-parser"
,
"escapedName"
:
"body-parser"
,
"rawSpec"
:
""
,
"rawSpec"
:
"
^1.19.0
"
,
"saveSpec"
:
null
,
"saveSpec"
:
null
,
"fetchSpec"
:
"
latest
"
"fetchSpec"
:
"
^1.19.0
"
},
},
"_requiredBy"
:
[
"_requiredBy"
:
[
"#USER"
,
"#USER"
,
...
@@ -22,7 +22,7 @@
...
@@ -22,7 +22,7 @@
],
],
"_resolved"
:
"https://registry.npmjs.org/body-parser/-/body-parser-1.19.0.tgz"
,
"_resolved"
:
"https://registry.npmjs.org/body-parser/-/body-parser-1.19.0.tgz"
,
"_shasum"
:
"96b2709e57c9c4e09a6fd66a8fd979844f69f08a"
,
"_shasum"
:
"96b2709e57c9c4e09a6fd66a8fd979844f69f08a"
,
"_spec"
:
"body-parser"
,
"_spec"
:
"body-parser
@^1.19.0
"
,
"_where"
:
"C:
\\
Users
\\
Usuario
\\
Desktop
\\
Laboratorio02"
,
"_where"
:
"C:
\\
Users
\\
Usuario
\\
Desktop
\\
Laboratorio02"
,
"bugs"
:
{
"bugs"
:
{
"url"
:
"https://github.com/expressjs/body-parser/issues"
"url"
:
"https://github.com/expressjs/body-parser/issues"
...
...
This diff is collapsed.
Click to expand it.
src/index.js
+
4
−
0
View file @
a2334768
const
express
=
require
(
'
express
'
);
const
express
=
require
(
'
express
'
);
const
bodyParser
=
require
(
'
body-parser
'
);
// ----------------- Initializations -----------------
// ----------------- Initializations -----------------
// Importo librería express
// Importo librería express
...
@@ -8,6 +9,9 @@ require('./database');
...
@@ -8,6 +9,9 @@ require('./database');
// ----------------- Settings -----------------
// ----------------- Settings -----------------
app
.
set
(
'
port
'
,
3000
);
app
.
set
(
'
port
'
,
3000
);
app
.
use
(
bodyParser
.
urlencoded
({
extended
:
true
}));
app
.
use
(
bodyParser
.
json
());
// ----------------- Middlewares -----------------
// ----------------- Middlewares -----------------
// ----------------- Global variables -----------------
// ----------------- Global variables -----------------
...
...
This diff is collapsed.
Click to expand it.
src/routes/user.js
+
23
−
14
View file @
a2334768
const
express
=
require
(
'
express
'
);
const
express
=
require
(
'
express
'
);
const
bodyParser
=
require
(
'
body-parser
'
);
const
router
=
express
.
Router
();
const
app
=
express
();
const
app
=
express
();
app
.
use
(
bodyParser
.
urlencoded
({
extended
:
false
}));
const
router
=
express
.
Router
();
app
.
use
(
bodyParser
.
json
());
const
users
=
[];
const
users
=
[
{
email
:
'
email1
'
,
comment
:
[]
}
];
// [GET] OBTENER TODOS LOS USUARIOS: /users
// [GET] OBTENER TODOS LOS USUARIOS: /users
router
.
get
(
'
/users
'
,
(
req
,
res
)
=>
{
router
.
get
(
'
/users
'
,
(
req
,
res
)
=>
{
...
@@ -16,10 +18,10 @@ router.get('/users', (req, res) => {
...
@@ -16,10 +18,10 @@ router.get('/users', (req, res) => {
// [GET] OBTENER UN USUARIO: /user/:id
// [GET] OBTENER UN USUARIO: /user/:id
router
.
get
(
'
/user/:id
'
,
(
req
,
res
)
=>
{
router
.
get
(
'
/user/:id
'
,
(
req
,
res
)
=>
{
const
user
Id
=
Number
(
req
.
params
.
id
)
;
const
user
Email
=
req
.
params
.
id
;
const
user
=
users
.
find
((
data
)
=>
data
.
id
===
user
Id
);
const
user
=
users
.
find
((
data
)
=>
data
.
email
===
user
Email
);
if
(
!
user
)
{
if
(
!
user
)
{
res
.
status
(
500
).
send
(
'
Usuario no encontrado
'
)
res
.
status
(
500
).
send
(
'
Usuario no encontrado
'
)
;
}
else
{
}
else
{
res
.
json
(
user
);
res
.
json
(
user
);
}
}
...
@@ -27,12 +29,19 @@ router.get('/user/:id', (req, res) => {
...
@@ -27,12 +29,19 @@ router.get('/user/:id', (req, res) => {
// [POST] CREAR UN NUEVO USUARIO: /user/new
// [POST] CREAR UN NUEVO USUARIO: /user/new
router
.
post
(
'
/user
'
,
(
req
,
res
)
=>
{
router
.
post
(
'
/user
'
,
(
req
,
res
)
=>
{
console
.
log
(
req
);
if
(
req
.
body
)
{
console
.
log
(
req
.
body
);
console
.
log
(
req
.
body
);
const
newUser
=
{
email
:
req
.
body
.
email
,
comment
:
[]
};
if
(
req
.
body
.
email
)
{
const
newUser
=
{
email
:
req
.
body
.
email
.
toString
(),
comment
:
[]
};
console
.
log
(
newUser
);
console
.
log
(
newUser
);
users
.
push
(
newUser
);
users
.
push
(
newUser
);
res
.
json
(
users
);
res
.
json
(
users
);
}
else
{
res
.
status
(
500
).
send
(
'
Se debe ingresar un email
'
);
}
}
else
{
res
.
status
(
500
).
send
(
'
Existió un error al procesar la solicitud
'
);
}
});
});
// [GET] OBTENER LOS COMENTARIOS DE UN USUARIO: /user/:id/comments
// [GET] OBTENER LOS COMENTARIOS DE UN USUARIO: /user/:id/comments
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment