Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2017
511
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. // Here is just a demonstration of how the dataset comes from the mongoose request
  2. const emails = [{
  3. _id: 4632472,
  4. sender: 'zozimo@gmail.com',
  5. broadcasted: [{
  6. tracker_id: '111-222-333',
  7. email: 'claudio.fernando@gmail.com',
  8. file: '42348424284728421424/43216472462746242.pdf',
  9. name: 'claudio fernando maciel',
  10. sent: false,
  11. approved: 0,
  12. edited: false
  13. },
  14. {
  15. tracker_id: '222-333-444',
  16. email: 'jerry.lewis@gmail.com',
  17. file: '42348424284728421424/432164fdsafsadfas.pdf',
  18. name: 'jerry lewis',
  19. sent: false,
  20. approved: 1,
  21. edited: true
  22. }
  23. ]
  24. },
  25. {
  26. _id: 42384232,
  27. sender: 'klencher@gmail.com',
  28. broadcasted: [{
  29. tracker_id: '333-444-555',
  30. email: 'luiz@gmail.com',
  31. file: '42348424284728421424/45785hfsjdf.pdf',
  32. name: 'luiz diaz',
  33. sent: false,
  34. approved: 1,
  35. edited: true
  36. }]
  37. }
  38. ]
  39.  
  40. // Here is just a demonstration of how the dataset comes from the mongoose request
  41. const users = [{
  42. name: 'claudio fernando',
  43. last_name: 'maciel',
  44. tracker_id: '111-222-333',
  45. cv: '42348424284728421424/editedstamped43216472462746242.pdf',
  46. email: 'claudio.fernando@gmail.com'
  47. },
  48. {
  49. name: 'jerry',
  50. last_name: 'lewis',
  51. tracker_id: '222-333-444',
  52. cv: '42348424284728421424/editedformated432164fdsafsadfas.pdf',
  53. email: 'jerry.lewis@gmail.com'
  54. },
  55. {
  56. name: 'luiz',
  57. last_name: 'diaz',
  58. tracker_id: '333-444-555',
  59. cv: '42348424284728421424/editedformated45785hfsjdf.pdf',
  60. email: 'luiz@gmail.com'
  61. }
  62. ]
  63.  
  64. // here's the real deal!
  65. let sendableEmails =
  66. emails
  67. .map(x => x.broadcasted)
  68. .map((x, y) => x.map(z => {
  69. if (z.edited && !z.sent) return z.tracker_id
  70. }))
  71. .map((x, y) => {
  72. x[y] = x[y] || ''
  73. return x
  74. })
  75. .reduce((flat, toFlatten) => flat.concat(toFlatten), [])
  76. .filter(x => x !== '')
  77.  
  78. let changed =
  79. .map((x, y) => {
  80. if (sendableEmails.indexOf(x.tracker_id) != -1) {
  81. return x.tracker_id || ''
  82. }
  83. })
  84. .filter(x => x)
  85.  
  86. // much better, huh!?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement