Skip to content
Snippets Groups Projects
Commit b3aad920 authored by Mariana Molina's avatar Mariana Molina
Browse files

Subo pequeño cambio

parent e36d5744
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
......@@ -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.');
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment