Guest User

Untitled

a guest
Nov 20th, 2018
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.33 KB | None | 0 0
  1. [
  2. {
  3. _accountId: "5beee0966d17bc42501f1234",
  4. name: "Company Name 1",
  5. contactEmail: "email1@email.com",
  6. contactName: "contact Name 1"
  7. reason: "Warranties",
  8. total: 1152,
  9. lineItems: [
  10. {
  11. _id: "5beee0966d17bc42501f5086",
  12. jobsiteAddress: "1234 Street Southwest Sunnyville, Wyoming 12345",
  13. warrantyFee: 384
  14. },
  15. {
  16. _id: "5bf43929e7179a56e21382bc",
  17. jobsiteAddress: "1234 Street Southwest Sunnyville, Wyoming 12345",
  18. warrantyFee: 384
  19. },
  20. {
  21. _id: "5bf4392fe7179a56e21382bd",
  22. jobsiteAddress: "1234 Street Southwest Sunnyville, Wyoming 12345",
  23. warrantyFee: 384
  24. }
  25. ]
  26. },
  27. {
  28. _accountId: "5beee0966d17bc42501f1235",
  29. name: "Company Name 2",
  30. contactEmail: "email2@email.com",
  31. contactName: "contact Name 2"
  32. reason: "Warranties",
  33. total: 1152,
  34. lineItems: [
  35. {
  36. _id: "5beee0966d17bc42501f5086",
  37. jobsiteAddress: "1234 Street Southwest Sunnyville, Wyoming 12345",
  38. warrantyFee: 384
  39. },
  40. {
  41. _id: "5bf43929e7179a56e21382bc",
  42. jobsiteAddress: "1234 Street Southwest Sunnyville, Wyoming 12345",
  43. warrantyFee: 384
  44. },
  45. {
  46. _id: "5bf4392fe7179a56e21382bd",
  47. jobsiteAddress: "1234 Street Southwest Sunnyville, Wyoming 12345",
  48. warrantyFee: 384
  49. }
  50. ]
  51. }
  52. ]
  53.  
  54. {
  55. _id: "5beee0966d17bc42501f5086",
  56. jobsiteAddressStreet: String,
  57. jobsiteAddressCity: String,
  58. jobsiteAddressState" String,
  59. jobsiteAddressZip: Number,
  60. warrantyFee: Number,
  61. _accountId: {
  62. type: Schema.Types.ObjectId,
  63. ref: "accounts"
  64. },
  65. payStatus: String
  66. }
  67.  
  68. {
  69. _id: "5beee0966d17bc42501f1235",
  70. name: String,
  71. contactName: String,
  72. contactEmail: String
  73. }
  74.  
  75. Warranty.aggregate([
  76. {
  77. $match: {
  78. payStatus: "Invoiced Next Billing Cycle"
  79. }
  80. },
  81. {
  82. $group: {
  83. _id: "$_accountId",
  84. total: {
  85. $sum: "$warrantyFee"
  86. },
  87. lineItems: {
  88. $push: {
  89. _id: "$_id",
  90. jobsiteAddress: {
  91. $concat: [
  92. "$jobsiteAddressStreet",
  93. " ",
  94. "$jobsiteAddressCity",
  95. ", ",
  96. "$jobsiteAddressState",
  97. " ",
  98. "$jobsiteAddressZip"
  99. ]
  100. },
  101. warrantyFee: "$warrantyFee"
  102. }
  103. }
  104. }
  105. },
  106. {
  107. $project: {
  108. reason: "Warranties",
  109. total: "$total",
  110. lineItems: "$lineItems"
  111. }
  112. }
  113. ])
  114. .then(warranties => {
  115. console.log(warranties);
  116. Account.populate(warranties, {
  117. path: "_id",
  118. select: "contactName contactEmail name"
  119. })
  120. .then(warranties => {
  121. res.send(warranties);
  122. })
  123. .catch(err => {
  124. res.status(422).send(err);
  125. throw err;
  126. });
  127. })
  128. .catch(err => {
  129. res.status(422).send(err);
  130. throw err;
  131. });
  132.  
  133. [
  134. {
  135. _id: {
  136. _id: "5bc39dfa331c0e2cb897b61e",
  137. name: "Company Name 1",
  138. contactEmail: "email1@email.com",
  139. contactName: "Contact Name 1"
  140. },
  141. reason: "Warranties",
  142. total: 1152,
  143. lineItems: [
  144. {
  145. _id: "5beee0966d17bc42501f5086",
  146. jobsiteAddress: "1234 Street Southwest Sunnyville, Wyoming 12345",
  147. warrantyFee: 384
  148. },
  149. {
  150. _id: "5bf43929e7179a56e21382bc",
  151. jobsiteAddress: "1234 Street Southwest Sunnyville, Wyoming 12345",
  152. warrantyFee: 384
  153. },
  154. {
  155. _id: "5bf4392fe7179a56e21382bd",
  156. jobsiteAddress: "1234 Street Southwest Sunnyville, Wyoming 12345",
  157. warrantyFee: 384
  158. }
  159. ]
  160. },
  161. {
  162. _id: {
  163. _id: "5bc39dfa331c0e2cb897b61e",
  164. name: "Company Name 2",
  165. contactEmail: "email2@email.com",
  166. contactName: "Contact Name 2"
  167. },
  168. reason: "Warranties",
  169. total: 1152,
  170. lineItems: [
  171. {
  172. _id: "5beee0966d17bc42501f5086",
  173. jobsiteAddress: "1234 Street Southwest Sunnyville, Wyoming 12345",
  174. warrantyFee: 384
  175. },
  176. {
  177. _id: "5bf43929e7179a56e21382bc",
  178. jobsiteAddress: "1234 Street Southwest Sunnyville, Wyoming 12345",
  179. warrantyFee: 384
  180. },
  181. {
  182. _id: "5bf4392fe7179a56e21382bd",
  183. jobsiteAddress: "1234 Street Southwest Sunnyville, Wyoming 12345",
  184. warrantyFee: 384
  185. }
  186. ]
  187. }
  188. ]
Add Comment
Please, Sign In to add comment