Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
noSQL
Manage
Activity
Members
Labels
Plan
Issues
0
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mariana Molina Reyes
noSQL
Commits
b3aad920
Commit
b3aad920
authored
5 years ago
by
Mariana Molina
Browse files
Options
Downloads
Patches
Plain Diff
Subo pequeño cambio
parent
e36d5744
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/database.js
+11
-7
11 additions, 7 deletions
src/database.js
src/routes/comment.js
+6
-13
6 additions, 13 deletions
src/routes/comment.js
with
17 additions
and
20 deletions
src/database.js
+
11
−
7
View file @
b3aad920
...
...
@@ -96,7 +96,7 @@ exports.newComment = async (com) => {
const
id
=
uuidv4
();
const
params
=
{
TableName
:
commentTableName
,
Item
:{
Item
:
{
"
id
"
:
id
,
"
user
"
:
com
.
user
,
"
text
"
:
com
.
text
,
...
...
@@ -104,9 +104,9 @@ exports.newComment = async (com) => {
}
};
console
.
log
(
"
Agregando comentario...
"
);
const
res
=
await
docClient
.
put
(
params
).
promise
();
console
.
log
(
"
Comentario agregado:
"
,
JSON
.
stringify
(
res
,
null
,
2
));
return
res
;
await
docClient
.
put
(
params
).
promise
();
console
.
log
(
"
Comentario agregado:
"
,
JSON
.
stringify
(
params
.
Item
,
null
,
2
));
return
params
.
Item
;
}
catch
(
e
)
{
console
.
error
(
"
No se pudo agregar el comentario. Error JSON:
"
,
JSON
.
stringify
(
err
,
null
,
2
));
throw
e
;
...
...
@@ -118,15 +118,19 @@ exports.getComment = async (idC) => {
try
{
const
params
=
{
TableName
:
commentTableName
,
Key
:{
Key
:
{
"
id
"
:
idC
}
};
// Hago el pedido
const
res
=
await
docClient
.
get
(
params
).
promise
();
// Si lo encontró, lo devuelvo
console
.
log
(
"
Comentario Obtenido:
"
,
JSON
.
stringify
(
res
,
null
,
2
));
return
data
;
if
(
res
&&
res
.
Item
)
{
console
.
log
(
"
Comentario Obtenido:
"
,
JSON
.
stringify
(
res
.
Item
,
null
,
2
));
return
res
.
Item
;
}
else
{
return
null
;
}
}
catch
(
e
)
{
console
.
error
(
"
No se pudo obtener el comentario. Error JSON:
"
,
JSON
.
stringify
(
e
,
null
,
2
));
return
null
;
...
...
This diff is collapsed.
Click to expand it.
src/routes/comment.js
+
6
−
13
View file @
b3aad920
...
...
@@ -2,16 +2,6 @@ const express = require('express');
const
router
=
express
.
Router
();
const
database
=
require
(
'
../database
'
);
// FIXME: SACARRRR
const
comments
=
require
(
'
../models/Comment
'
).
comments
;
const
users
=
require
(
'
../models/User
'
).
users
;
let
commentId
=
1
;
// FIN FIXMEEE
// FIXME
// [GET] OBTENER UN COMENTARIO: /comment/:id
router
.
get
(
'
/comment/:id
'
,
async
(
req
,
res
)
=>
{
try
{
...
...
@@ -28,7 +18,6 @@ router.get('/comment/:id', async (req, res) => {
}
});
// FIXME
// [POST] CREAR UN COMENTARIO: /comment
router
.
post
(
'
/comment
'
,
async
(
req
,
res
)
=>
{
try
{
...
...
@@ -42,8 +31,12 @@ router.post('/comment', async (req, res) => {
const
text
=
req
.
body
.
text
.
toString
();
const
newComment
=
{
user
:
userEmail
,
text
:
text
,
comment
:
[]
};
const
comment
=
await
database
.
newComment
(
newComment
);
console
.
log
(
comment
);
res
.
json
(
comments
);
if
(
comment
)
{
console
.
log
(
comment
);
res
.
json
(
comment
);
}
else
{
res
.
status
(
500
).
send
(
'
No se pudo crear el comentario
'
);
}
}
else
{
res
.
status
(
500
).
send
(
'
El comentario no debe ser vacío.
'
);
}
...
...
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
register
or
sign in
to comment