Advertisement
Guest User

Untitled

a guest
Mar 8th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. "blogStatus": "published",
  2. "blogContent": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.,
  3. "storeId": "10",
  4. "tagDate": "Thu Mar 07 2019 18:02:33 GMT+0530 (India Standard Time)",
  5. "type": "comment",
  6. "blogTitle": "best hospitalsss",
  7. "createdDate": "Thu Mar 07 2019 18:02:33 GMT+0530 (India Standard Time)",
  8. "Comments": [
  9. {
  10. "date": "Fri Mar 08 2019 10:24:50 GMT+0530 (India Standard Time)",
  11. "userEmail": "liza@gmail.com",
  12. "id": "4e4e8210-415e-11e9-bd72-a17467608922",
  13. "userName": "liza",
  14. "status": "draft",
  15. "replies": [
  16. {
  17. "date": "Fri Mar 08 2019 09:54:00 GMT+0530 (India Standard Time)",
  18. "userEmail": "liza1@gmail.com",
  19. "id": "ff3096e0-4159-11e9-9315-652881dffd8b",
  20. "userName": "liza1",
  21. "status": "draft"
  22. },
  23. {
  24. "date": "Fri Mar 08 2019 09:54:00 GMT+0530 (India Standard Time)",
  25. "userEmail": "liza2@gmail.com",
  26. "id": "ff3096e0-4159-11e9-9315-652881dffd8b",
  27. "userName": "liza2",
  28. "status": "draft"
  29. }
  30. }
  31. ]
  32.  
  33. ]
  34.  
  35. app.post('/api/v1/reply/:id', function (req, res) {
  36. var blogId = req.params.id;
  37. var replyId = uuid.v1();
  38. var d = new Date();
  39. var date = d.toString();
  40. const {
  41. reply,
  42. userName,
  43. userEmail,
  44. status
  45. } = req.body
  46. var params = {
  47. TableName: "BlogTest",
  48.  
  49. Key: {
  50. "id": blogId,
  51. },
  52. UpdateExpression: "SET #comments[0].#replies = :attrValue",
  53. ExpressionAttributeNames: {
  54. '#comments': 'Comments',
  55. '#replies': 'replies'
  56. },
  57. "ExpressionAttributeValues": {
  58. ":attrValue": [{ id: replyId, date: date, message:reply, userName:userName, userEmail:userEmail,status:status},{ id: replyId, date: date, message:reply, userName:userName, userEmail:userEmail,status:status}]
  59. },
  60. ReturnValues: "UPDATED_NEW"
  61. };
  62. console.log(params);
  63.  
  64. docClient.update(params, (error) => {
  65. if (error) {
  66. console.log(error);
  67. res.status(400).json({ error: 'Could not create reply' });
  68. }
  69. res.status(200).json({ success: 'Created the reply' });
  70. // res.json({ id, name, info });
  71. });
  72. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement