@resolveio/server-lib 12.5.54 → 12.5.56

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (400) hide show
  1. package/client-server-app.d.ts +1 -0
  2. package/client-server-app.js +48 -0
  3. package/client-server-app.js.map +1 -0
  4. package/collections/app-status.collection.d.ts +3 -0
  5. package/collections/app-status.collection.js +51 -0
  6. package/collections/app-status.collection.js.map +1 -0
  7. package/collections/counter.collection.d.ts +3 -0
  8. package/collections/counter.collection.js +54 -0
  9. package/collections/counter.collection.js.map +1 -0
  10. package/collections/cron-job-history.collection.d.ts +3 -0
  11. package/collections/cron-job-history.collection.js +82 -0
  12. package/collections/cron-job-history.collection.js.map +1 -0
  13. package/collections/cron-job.collection.d.ts +3 -0
  14. package/collections/cron-job.collection.js +85 -0
  15. package/collections/cron-job.collection.js.map +1 -0
  16. package/collections/email-history.collection.d.ts +3 -0
  17. package/collections/email-history.collection.js +66 -0
  18. package/collections/email-history.collection.js.map +1 -0
  19. package/collections/email-verified.collection.d.ts +3 -0
  20. package/collections/email-verified.collection.js +61 -0
  21. package/collections/email-verified.collection.js.map +1 -0
  22. package/collections/file.collection.d.ts +3 -0
  23. package/collections/file.collection.js +73 -0
  24. package/collections/file.collection.js.map +1 -0
  25. package/collections/flag.collection.d.ts +3 -0
  26. package/collections/flag.collection.js +56 -0
  27. package/collections/flag.collection.js.map +1 -0
  28. package/collections/log-method-latency.collection.d.ts +3 -0
  29. package/collections/log-method-latency.collection.js +64 -0
  30. package/collections/log-method-latency.collection.js.map +1 -0
  31. package/collections/log-subscription.collection.d.ts +3 -0
  32. package/collections/log-subscription.collection.js +68 -0
  33. package/collections/log-subscription.collection.js.map +1 -0
  34. package/collections/log-ts.collection.d.ts +3 -0
  35. package/collections/log-ts.collection.js +78 -0
  36. package/collections/log-ts.collection.js.map +1 -0
  37. package/collections/log.collection.d.ts +3 -0
  38. package/collections/log.collection.js +77 -0
  39. package/collections/log.collection.js.map +1 -0
  40. package/collections/logged-in-users.collection.d.ts +3 -0
  41. package/collections/logged-in-users.collection.js +65 -0
  42. package/collections/logged-in-users.collection.js.map +1 -0
  43. package/collections/method-response.collection.d.ts +3 -0
  44. package/collections/method-response.collection.js +66 -0
  45. package/collections/method-response.collection.js.map +1 -0
  46. package/collections/monitor-cpu.collection.d.ts +3 -0
  47. package/collections/monitor-cpu.collection.js +63 -0
  48. package/collections/monitor-cpu.collection.js.map +1 -0
  49. package/collections/monitor-memory.collection.d.ts +3 -0
  50. package/collections/monitor-memory.collection.js +75 -0
  51. package/collections/monitor-memory.collection.js.map +1 -0
  52. package/collections/monitor-mongo.collection.d.ts +3 -0
  53. package/collections/monitor-mongo.collection.js +69 -0
  54. package/collections/monitor-mongo.collection.js.map +1 -0
  55. package/collections/notification.collection.d.ts +3 -0
  56. package/collections/notification.collection.js +51 -0
  57. package/collections/notification.collection.js.map +1 -0
  58. package/collections/report-builder-dashboard-builder.collection.d.ts +3 -0
  59. package/collections/report-builder-dashboard-builder.collection.js +109 -0
  60. package/collections/report-builder-dashboard-builder.collection.js.map +1 -0
  61. package/collections/report-builder-library.collection.d.ts +3 -0
  62. package/collections/report-builder-library.collection.js +87 -0
  63. package/collections/report-builder-library.collection.js.map +1 -0
  64. package/collections/report-builder-report.collection.d.ts +4 -0
  65. package/collections/report-builder-report.collection.js +149 -0
  66. package/collections/report-builder-report.collection.js.map +1 -0
  67. package/collections/user-group.collection.d.ts +4 -0
  68. package/collections/user-group.collection.js +90 -0
  69. package/collections/user-group.collection.js.map +1 -0
  70. package/collections/user-guide.collection.d.ts +3 -0
  71. package/collections/user-guide.collection.js +57 -0
  72. package/collections/user-guide.collection.js.map +1 -0
  73. package/collections/user.collection.d.ts +4 -0
  74. package/collections/user.collection.js +259 -0
  75. package/collections/user.collection.js.map +1 -0
  76. package/cron/cron.d.ts +5 -0
  77. package/cron/cron.js +162 -0
  78. package/cron/cron.js.map +1 -0
  79. package/fixtures/cron-jobs.d.ts +1 -0
  80. package/fixtures/cron-jobs.js +73 -0
  81. package/fixtures/cron-jobs.js.map +1 -0
  82. package/fixtures/init.d.ts +1 -0
  83. package/fixtures/init.js +59 -0
  84. package/fixtures/init.js.map +1 -0
  85. package/http/auth.d.ts +2 -0
  86. package/http/auth.js +763 -0
  87. package/http/auth.js.map +1 -0
  88. package/http/health.d.ts +1 -0
  89. package/http/health.js +12 -0
  90. package/http/health.js.map +1 -0
  91. package/http/home.d.ts +2 -0
  92. package/http/home.js +66 -0
  93. package/http/home.js.map +1 -0
  94. package/index.d.ts +23 -0
  95. package/index.js +127 -0
  96. package/index.js.map +1 -0
  97. package/managers/cron.manager.d.ts +17 -0
  98. package/managers/cron.manager.js +242 -0
  99. package/managers/cron.manager.js.map +1 -0
  100. package/managers/method.manager.d.ts +38 -0
  101. package/managers/method.manager.js +595 -0
  102. package/managers/method.manager.js.map +1 -0
  103. package/managers/mongo.manager.d.ts +178 -0
  104. package/managers/mongo.manager.js +2221 -0
  105. package/managers/mongo.manager.js.map +1 -0
  106. package/managers/monitor.manager.d.ts +59 -0
  107. package/managers/monitor.manager.js +351 -0
  108. package/managers/monitor.manager.js.map +1 -0
  109. package/managers/subscription.manager.d.ts +50 -0
  110. package/managers/subscription.manager.js +1091 -0
  111. package/managers/subscription.manager.js.map +1 -0
  112. package/managers/subscription.performance.d.ts +1 -0
  113. package/{src/managers/subscription.performance.ts → managers/subscription.performance.js} +33 -68
  114. package/managers/subscription.performance.js.map +1 -0
  115. package/methods/accounts.d.ts +2 -0
  116. package/methods/accounts.js +274 -0
  117. package/methods/accounts.js.map +1 -0
  118. package/methods/aws.d.ts +2 -0
  119. package/methods/aws.js +617 -0
  120. package/methods/aws.js.map +1 -0
  121. package/methods/collections.d.ts +2 -0
  122. package/methods/collections.js +499 -0
  123. package/methods/collections.js.map +1 -0
  124. package/methods/counters.d.ts +2 -0
  125. package/methods/counters.js +122 -0
  126. package/methods/counters.js.map +1 -0
  127. package/methods/cron-jobs.d.ts +2 -0
  128. package/methods/cron-jobs.js +1315 -0
  129. package/methods/cron-jobs.js.map +1 -0
  130. package/methods/flags.d.ts +2 -0
  131. package/methods/flags.js +9 -0
  132. package/methods/flags.js.map +1 -0
  133. package/methods/logs.d.ts +2 -0
  134. package/methods/logs.js +371 -0
  135. package/methods/logs.js.map +1 -0
  136. package/methods/monitor.d.ts +2 -0
  137. package/methods/monitor.js +565 -0
  138. package/methods/monitor.js.map +1 -0
  139. package/methods/pdf.d.ts +2 -0
  140. package/methods/pdf.js +468 -0
  141. package/methods/pdf.js.map +1 -0
  142. package/methods/report-builder.d.ts +2 -0
  143. package/methods/report-builder.js +858 -0
  144. package/methods/report-builder.js.map +1 -0
  145. package/methods/support.d.ts +2 -0
  146. package/methods/support.js +246 -0
  147. package/methods/support.js.map +1 -0
  148. package/{src/models/app-status.model.ts → models/app-status.model.d.ts} +2 -3
  149. package/models/app-status.model.js +4 -0
  150. package/models/app-status.model.js.map +1 -0
  151. package/{src/models/billing-logged-in-users.model.ts → models/billing-logged-in-users.model.d.ts} +4 -5
  152. package/models/billing-logged-in-users.model.js +4 -0
  153. package/models/billing-logged-in-users.model.js.map +1 -0
  154. package/models/collection-document.model.d.ts +19 -0
  155. package/models/collection-document.model.js +4 -0
  156. package/models/collection-document.model.js.map +1 -0
  157. package/{src/models/counter.model.ts → models/counter.model.d.ts} +3 -4
  158. package/models/counter.model.js +4 -0
  159. package/models/counter.model.js.map +1 -0
  160. package/models/cron-job-history.model.d.ts +12 -0
  161. package/models/cron-job-history.model.js +4 -0
  162. package/models/cron-job-history.model.js.map +1 -0
  163. package/models/cron-job.model.d.ts +13 -0
  164. package/models/cron-job.model.js +4 -0
  165. package/models/cron-job.model.js.map +1 -0
  166. package/models/dialog.model.d.ts +23 -0
  167. package/models/dialog.model.js +4 -0
  168. package/models/dialog.model.js.map +1 -0
  169. package/{src/models/email-history.model.ts → models/email-history.model.d.ts} +7 -8
  170. package/models/email-history.model.js +4 -0
  171. package/models/email-history.model.js.map +1 -0
  172. package/{src/models/email-verified.model.ts → models/email-verified.model.d.ts} +5 -6
  173. package/models/email-verified.model.js +4 -0
  174. package/models/email-verified.model.js.map +1 -0
  175. package/{src/models/file.model.ts → models/file.model.d.ts} +7 -8
  176. package/models/file.model.js +4 -0
  177. package/models/file.model.js.map +1 -0
  178. package/{src/models/flag.model.ts → models/flag.model.d.ts} +3 -4
  179. package/models/flag.model.js +4 -0
  180. package/models/flag.model.js.map +1 -0
  181. package/{src/models/log-method-latency.model.ts → models/log-method-latency.model.d.ts} +4 -5
  182. package/models/log-method-latency.model.js +4 -0
  183. package/models/log-method-latency.model.js.map +1 -0
  184. package/{src/models/log-subscription.model.ts → models/log-subscription.model.d.ts} +6 -8
  185. package/models/log-subscription.model.js +4 -0
  186. package/models/log-subscription.model.js.map +1 -0
  187. package/{src/models/log.model.ts → models/log.model.d.ts} +10 -12
  188. package/models/log.model.js +4 -0
  189. package/models/log.model.js.map +1 -0
  190. package/{src/models/logged-in-users.model.ts → models/logged-in-users.model.d.ts} +5 -6
  191. package/models/logged-in-users.model.js +4 -0
  192. package/models/logged-in-users.model.js.map +1 -0
  193. package/{src/models/method-response.model.ts → models/method-response.model.d.ts} +6 -7
  194. package/models/method-response.model.js +4 -0
  195. package/models/method-response.model.js.map +1 -0
  196. package/models/method.model.d.ts +9 -0
  197. package/models/method.model.js +4 -0
  198. package/models/method.model.js.map +1 -0
  199. package/{src/models/monitor-cpu.model.ts → models/monitor-cpu.model.d.ts} +7 -9
  200. package/models/monitor-cpu.model.js +4 -0
  201. package/models/monitor-cpu.model.js.map +1 -0
  202. package/models/monitor-memory.model.d.ts +15 -0
  203. package/models/monitor-memory.model.js +4 -0
  204. package/models/monitor-memory.model.js.map +1 -0
  205. package/models/monitor-mongo.model.d.ts +13 -0
  206. package/models/monitor-mongo.model.js +4 -0
  207. package/models/monitor-mongo.model.js.map +1 -0
  208. package/{src/models/notification.model.ts → models/notification.model.d.ts} +2 -3
  209. package/models/notification.model.js +4 -0
  210. package/models/notification.model.js.map +1 -0
  211. package/models/pagination.model.d.ts +10 -0
  212. package/models/pagination.model.js +24 -0
  213. package/models/pagination.model.js.map +1 -0
  214. package/models/permission.model.d.ts +12 -0
  215. package/models/permission.model.js +4 -0
  216. package/models/permission.model.js.map +1 -0
  217. package/models/report-builder-dashboard-builder.model.d.ts +25 -0
  218. package/models/report-builder-dashboard-builder.model.js +4 -0
  219. package/models/report-builder-dashboard-builder.model.js.map +1 -0
  220. package/models/report-builder-library.model.d.ts +17 -0
  221. package/models/report-builder-library.model.js +4 -0
  222. package/models/report-builder-library.model.js.map +1 -0
  223. package/models/report-builder-report.model.d.ts +98 -0
  224. package/models/report-builder-report.model.js +4 -0
  225. package/models/report-builder-report.model.js.map +1 -0
  226. package/models/report-builder.model.d.ts +61 -0
  227. package/models/report-builder.model.js +4 -0
  228. package/models/report-builder.model.js.map +1 -0
  229. package/models/select-data-label.model.d.ts +9 -0
  230. package/models/select-data-label.model.js +4 -0
  231. package/models/select-data-label.model.js.map +1 -0
  232. package/models/server-response.model.d.ts +5 -0
  233. package/models/server-response.model.js +4 -0
  234. package/models/server-response.model.js.map +1 -0
  235. package/models/subscription.model.d.ts +23 -0
  236. package/models/subscription.model.js +4 -0
  237. package/models/subscription.model.js.map +1 -0
  238. package/models/support-ticket.model.d.ts +72 -0
  239. package/models/support-ticket.model.js +4 -0
  240. package/models/support-ticket.model.js.map +1 -0
  241. package/models/user-group.model.d.ts +19 -0
  242. package/models/user-group.model.js +4 -0
  243. package/models/user-group.model.js.map +1 -0
  244. package/{src/models/user-guide.model.ts → models/user-guide.model.d.ts} +4 -5
  245. package/models/user-guide.model.js +4 -0
  246. package/models/user-guide.model.js.map +1 -0
  247. package/models/user.model.d.ts +70 -0
  248. package/models/user.model.js +4 -0
  249. package/models/user.model.js.map +1 -0
  250. package/package.json +1 -1
  251. package/{src/public_api.ts → public_api.d.ts} +1 -1
  252. package/public_api.js +75 -0
  253. package/public_api.js.map +1 -0
  254. package/publications/app-status.d.ts +2 -0
  255. package/publications/app-status.js +17 -0
  256. package/publications/app-status.js.map +1 -0
  257. package/publications/cron-jobs.d.ts +2 -0
  258. package/publications/cron-jobs.js +33 -0
  259. package/publications/cron-jobs.js.map +1 -0
  260. package/publications/files.d.ts +2 -0
  261. package/publications/files.js +37 -0
  262. package/publications/files.js.map +1 -0
  263. package/publications/flags.d.ts +2 -0
  264. package/publications/flags.js +23 -0
  265. package/publications/flags.js.map +1 -0
  266. package/publications/logs.d.ts +2 -0
  267. package/publications/logs.js +165 -0
  268. package/publications/logs.js.map +1 -0
  269. package/publications/method-responses.d.ts +2 -0
  270. package/publications/method-responses.js +17 -0
  271. package/publications/method-responses.js.map +1 -0
  272. package/publications/notifications.d.ts +2 -0
  273. package/publications/notifications.js +17 -0
  274. package/publications/notifications.js.map +1 -0
  275. package/publications/report-builder-dashboard-builders.d.ts +2 -0
  276. package/publications/report-builder-dashboard-builders.js +43 -0
  277. package/publications/report-builder-dashboard-builders.js.map +1 -0
  278. package/publications/report-builder-libraries.d.ts +2 -0
  279. package/publications/report-builder-libraries.js +90 -0
  280. package/publications/report-builder-libraries.js.map +1 -0
  281. package/publications/report-builder-reports.d.ts +2 -0
  282. package/publications/report-builder-reports.js +51 -0
  283. package/publications/report-builder-reports.js.map +1 -0
  284. package/publications/super-admin.d.ts +2 -0
  285. package/publications/super-admin.js +17 -0
  286. package/publications/super-admin.js.map +1 -0
  287. package/publications/user-groups.d.ts +1 -0
  288. package/publications/user-groups.js +17 -0
  289. package/publications/user-groups.js.map +1 -0
  290. package/publications/user-guides.d.ts +1 -0
  291. package/publications/user-guides.js +17 -0
  292. package/publications/user-guides.js.map +1 -0
  293. package/server-app.d.ts +52 -0
  294. package/server-app.js +739 -0
  295. package/server-app.js.map +1 -0
  296. package/util/common.d.ts +25 -0
  297. package/util/common.js +524 -0
  298. package/util/common.js.map +1 -0
  299. package/util/schema-report-builder.d.ts +6 -0
  300. package/util/schema-report-builder.js +453 -0
  301. package/util/schema-report-builder.js.map +1 -0
  302. package/.nodemon.json +0 -5
  303. package/.vscode/settings.json +0 -3
  304. package/README.md +0 -22
  305. package/compileDTS.pl +0 -64
  306. package/gulpfile.js +0 -127
  307. package/mongodbensurers.js +0 -2
  308. package/mongostop.js +0 -3
  309. package/settings.development.json +0 -13
  310. package/src/client-server-app.ts +0 -7
  311. package/src/collections/app-status.collection.ts +0 -51
  312. package/src/collections/counter.collection.ts +0 -54
  313. package/src/collections/cron-job-history.collection.ts +0 -82
  314. package/src/collections/cron-job.collection.ts +0 -85
  315. package/src/collections/email-history.collection.ts +0 -66
  316. package/src/collections/email-verified.collection.ts +0 -61
  317. package/src/collections/file.collection.ts +0 -73
  318. package/src/collections/flag.collection.ts +0 -56
  319. package/src/collections/log-method-latency.collection.ts +0 -64
  320. package/src/collections/log-subscription.collection.ts +0 -68
  321. package/src/collections/log-ts.collection.ts +0 -78
  322. package/src/collections/log.collection.ts +0 -77
  323. package/src/collections/logged-in-users.collection.ts +0 -65
  324. package/src/collections/method-response.collection.ts +0 -66
  325. package/src/collections/monitor-cpu.collection.ts +0 -63
  326. package/src/collections/monitor-memory.collection.ts +0 -75
  327. package/src/collections/monitor-mongo.collection.ts +0 -69
  328. package/src/collections/notification.collection.ts +0 -51
  329. package/src/collections/report-builder-dashboard-builder.collection.ts +0 -109
  330. package/src/collections/report-builder-library.collection.ts +0 -89
  331. package/src/collections/report-builder-report.collection.ts +0 -149
  332. package/src/collections/user-group.collection.ts +0 -90
  333. package/src/collections/user-guide.collection.ts +0 -57
  334. package/src/collections/user.collection.ts +0 -259
  335. package/src/cron/cron.ts +0 -188
  336. package/src/fixtures/cron-jobs.ts +0 -25
  337. package/src/fixtures/init.ts +0 -10
  338. package/src/http/auth.ts +0 -732
  339. package/src/http/health.ts +0 -7
  340. package/src/http/home.ts +0 -71
  341. package/src/index.ts +0 -71
  342. package/src/managers/cron.manager.ts +0 -208
  343. package/src/managers/method.manager.ts +0 -607
  344. package/src/managers/mongo.manager.ts +0 -2282
  345. package/src/managers/monitor.manager.ts +0 -323
  346. package/src/managers/subscription.manager.ts +0 -1196
  347. package/src/methods/accounts.ts +0 -202
  348. package/src/methods/aws.ts +0 -507
  349. package/src/methods/collections.ts +0 -512
  350. package/src/methods/counters.ts +0 -75
  351. package/src/methods/cron-jobs.ts +0 -1454
  352. package/src/methods/flags.ts +0 -7
  353. package/src/methods/logs.ts +0 -327
  354. package/src/methods/monitor.ts +0 -548
  355. package/src/methods/pdf.ts +0 -615
  356. package/src/methods/report-builder.ts +0 -876
  357. package/src/methods/support.ts +0 -146
  358. package/src/models/collection-document.model.ts +0 -22
  359. package/src/models/cron-job-history.model.ts +0 -13
  360. package/src/models/cron-job.model.ts +0 -14
  361. package/src/models/dialog.model.ts +0 -25
  362. package/src/models/method.model.ts +0 -11
  363. package/src/models/monitor-memory.model.ts +0 -17
  364. package/src/models/monitor-mongo.model.ts +0 -15
  365. package/src/models/pagination.model.ts +0 -30
  366. package/src/models/permission.model.ts +0 -14
  367. package/src/models/report-builder-dashboard-builder.model.ts +0 -29
  368. package/src/models/report-builder-library.model.ts +0 -20
  369. package/src/models/report-builder-report.model.ts +0 -110
  370. package/src/models/report-builder.model.ts +0 -68
  371. package/src/models/select-data-label.model.ts +0 -9
  372. package/src/models/server-response.model.ts +0 -5
  373. package/src/models/subscription.model.ts +0 -64
  374. package/src/models/support-ticket.model.ts +0 -81
  375. package/src/models/user-group.model.ts +0 -23
  376. package/src/models/user.model.ts +0 -79
  377. package/src/publications/app-status.ts +0 -13
  378. package/src/publications/cron-jobs.ts +0 -30
  379. package/src/publications/files.ts +0 -34
  380. package/src/publications/flags.ts +0 -20
  381. package/src/publications/logs.ts +0 -164
  382. package/src/publications/method-responses.ts +0 -13
  383. package/src/publications/notifications.ts +0 -13
  384. package/src/publications/report-builder-dashboard-builders.ts +0 -39
  385. package/src/publications/report-builder-libraries.ts +0 -41
  386. package/src/publications/report-builder-reports.ts +0 -48
  387. package/src/publications/super-admin.ts +0 -13
  388. package/src/publications/user-groups.ts +0 -12
  389. package/src/publications/user-guides.ts +0 -12
  390. package/src/server-app.ts +0 -769
  391. package/src/util/common.ts +0 -519
  392. package/src/util/schema-report-builder.ts +0 -413
  393. package/tsconfig.json +0 -30
  394. package/tslint.json +0 -143
  395. /package/{src/private → private}/email-templates/enrollment.html +0 -0
  396. /package/{src/private → private}/email-templates/forgot-password.html +0 -0
  397. /package/{src/private → private}/email-templates/support-ticket-deleted.html +0 -0
  398. /package/{src/private → private}/email-templates/support-ticket-modified.html +0 -0
  399. /package/{src/private → private}/email-templates/support-ticket.html +0 -0
  400. /package/{src/private → private}/images/ResolveIO.png +0 -0
@@ -0,0 +1,1315 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.loadCronJobMethods = void 0;
40
+ var report_builder_report_collection_1 = require("../collections/report-builder-report.collection");
41
+ var simpl_schema_1 = require("simpl-schema");
42
+ var common_1 = require("../util/common");
43
+ var moment = require("moment");
44
+ var XLSX = require("xlsx");
45
+ var Excel = require("exceljs");
46
+ var file_collection_1 = require("../collections/file.collection");
47
+ function loadCronJobMethods(methodManager) {
48
+ methodManager.methods({
49
+ cronEmailMergedDocsCleanUp: {
50
+ function: function () {
51
+ var _this = this;
52
+ return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
53
+ var files;
54
+ return __generator(this, function (_a) {
55
+ switch (_a.label) {
56
+ case 0: return [4 /*yield*/, file_collection_1.Files.find({ $and: [{ type: 'Email Merged Docs' }, { createdAt: { $lte: moment().subtract(1, 'day').toDate() } }] })];
57
+ case 1:
58
+ files = _a.sent();
59
+ if (files.length) {
60
+ this.callMethodInternal('deleteFiles');
61
+ file_collection_1.Files.deleteMany({ _id: { $in: files.map(function (a) { return a._id; }) } });
62
+ }
63
+ resolve(true);
64
+ return [2 /*return*/];
65
+ }
66
+ });
67
+ }); });
68
+ }
69
+ },
70
+ reportbuilderCronJob: {
71
+ check: new simpl_schema_1.default({
72
+ data: {
73
+ type: Object,
74
+ blackbox: true
75
+ }
76
+ }),
77
+ function: function (data) {
78
+ var _this = this;
79
+ return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
80
+ var report, fieldsObj_1, count_1, sortObj_1, rootOptions_1, filters_1;
81
+ var _this = this;
82
+ return __generator(this, function (_a) {
83
+ switch (_a.label) {
84
+ case 0: return [4 /*yield*/, report_builder_report_collection_1.ReportBuilderReports.findById(data['id_report'])];
85
+ case 1:
86
+ report = _a.sent();
87
+ report.fields_selected.forEach(function (field) {
88
+ var _a, _b;
89
+ var dotPath = field.fieldPath.replace(/\.\$/g, '');
90
+ var fieldData = dotPath.split('.');
91
+ field.fieldPathObj = null;
92
+ for (var i = fieldData.length - 1; i >= 0; i--) {
93
+ if (!field.fieldPathObj) {
94
+ field.fieldPathObj = (_a = {}, _a[fieldData[i]] = 1, _a);
95
+ }
96
+ else {
97
+ field.fieldPathObj = (_b = {}, _b[fieldData[i]] = field.fieldPathObj, _b);
98
+ }
99
+ }
100
+ });
101
+ if ((report.fields_selected && report.fields_selected.length) || (report.groups_row && report.groups_row.length)) {
102
+ fieldsObj_1 = {};
103
+ count_1 = 0;
104
+ report.fields_selected.forEach(function (field) {
105
+ if (field.collection_name === report.collection_root) {
106
+ fieldsObj_1 = (0, common_1.mergeDeep)(fieldsObj_1, field.fieldPathObj);
107
+ }
108
+ var sortIndex = report.fields_sort.findIndex(function (a) { return a.field === field['id']; });
109
+ if (sortIndex >= 0) {
110
+ report.fields_sort[sortIndex].field = ('f_' + count_1);
111
+ }
112
+ field['id'] = 'f_' + count_1;
113
+ count_1 += 1;
114
+ });
115
+ sortObj_1 = {};
116
+ if (report.fields_sort.length) {
117
+ report.fields_sort.forEach(function (sortField) {
118
+ if (sortField.field.startsWith('gr_')) {
119
+ sortObj_1['_id.' + sortField.field] = (sortField.order === 'asc' ? 1 : -1);
120
+ }
121
+ else {
122
+ sortObj_1[sortField.field] = (sortField.order === 'asc' ? 1 : -1);
123
+ }
124
+ });
125
+ }
126
+ else {
127
+ sortObj_1 = null;
128
+ }
129
+ rootOptions_1 = {
130
+ limit: 0,
131
+ skip: 0,
132
+ fields: fieldsObj_1,
133
+ sort: sortObj_1
134
+ };
135
+ filters_1 = [];
136
+ report.fields_filter.forEach(function (filterAnd) {
137
+ var ors = [];
138
+ filterAnd.ors.filter(function (a) { return !a.field.includes('.$.'); }).forEach(function (filter) {
139
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
140
+ if (filter.condition && filter.field && ((filter.value !== null && (!Array.isArray(filter.value) || filter.value.length)) || filter.condition === 'null' || filter.condition === 'nnull')) {
141
+ if (filter.condition === 'bw') {
142
+ if (filter.fieldType === 'Date' && filter.is_rolling) {
143
+ var startDate = null;
144
+ var endDate = null;
145
+ if (filter.rolling_interval === 'Q1') {
146
+ startDate = moment().startOf('year').toDate();
147
+ endDate = moment().startOf('year').quarter(2).subtract(1, 'days').toDate();
148
+ }
149
+ else if (filter.rolling_interval === 'Q2') {
150
+ startDate = moment().startOf('year').quarter(2).toDate();
151
+ endDate = moment().startOf('year').quarter(3).subtract(1, 'days').toDate();
152
+ }
153
+ else if (filter.rolling_interval === 'Q3') {
154
+ startDate = moment().startOf('year').quarter(3).toDate();
155
+ endDate = moment().startOf('year').quarter(4).subtract(1, 'days').toDate();
156
+ }
157
+ else if (filter.rolling_interval === 'Q4') {
158
+ startDate = moment().startOf('year').quarter(4).toDate();
159
+ endDate = moment().endOf('year').toDate();
160
+ }
161
+ else if (filter.rolling_interval === 'Today') {
162
+ startDate = moment().startOf('day').toDate();
163
+ endDate = moment().endOf('day').toDate();
164
+ }
165
+ else if (filter.rolling_interval === 'Yesterday') {
166
+ startDate = moment().subtract(1, 'days').startOf('day').toDate();
167
+ endDate = moment().subtract(1, 'days').endOf('day').toDate();
168
+ }
169
+ else if (filter.rolling_interval === 'Week') {
170
+ startDate = moment().startOf('isoWeek').toDate();
171
+ endDate = moment().endOf('day').toDate();
172
+ }
173
+ else if (filter.rolling_interval === 'Last Week') {
174
+ endDate = moment().startOf('isoWeek').subtract(1, 'days').toDate();
175
+ startDate = moment(endDate).startOf('isoWeek').toDate();
176
+ }
177
+ else if (filter.rolling_interval === 'Month') {
178
+ startDate = moment().startOf('month').toDate();
179
+ endDate = moment().endOf('day').toDate();
180
+ }
181
+ else if (filter.rolling_interval === 'Last Month') {
182
+ endDate = moment().startOf('month').subtract(1, 'days').endOf('day').toDate();
183
+ startDate = moment(endDate).startOf('month').toDate();
184
+ }
185
+ else if (filter.rolling_interval === 'Last 30 Days') {
186
+ endDate = moment().endOf('day').toDate();
187
+ startDate = moment().subtract(30, 'days').startOf('day').toDate();
188
+ }
189
+ else if (filter.rolling_interval === 'Quarter') {
190
+ startDate = moment().startOf('year').quarter(moment().quarter()).toDate();
191
+ endDate = moment().endOf('day').toDate();
192
+ }
193
+ else if (filter.rolling_interval === 'Last Quarter') {
194
+ endDate = moment().startOf('year').quarter(moment().quarter()).subtract(1, 'days').endOf('day').toDate();
195
+ startDate = moment(endDate).startOf('quarter').toDate();
196
+ }
197
+ else if (filter.rolling_interval === 'Year') {
198
+ startDate = moment().startOf('year').toDate();
199
+ endDate = moment().endOf('day').toDate();
200
+ }
201
+ else if (filter.rolling_interval === 'Last Year') {
202
+ endDate = moment().startOf('year').subtract(1, 'days').endOf('day').toDate();
203
+ startDate = moment(endDate).startOf('year').toDate();
204
+ }
205
+ else if (filter.rolling_interval === 'All') {
206
+ startDate = new Date(2017, 0, 1, 0, 0, 0, 0);
207
+ endDate = moment().endOf('day').toDate();
208
+ }
209
+ endDate.setHours(23);
210
+ endDate.setMinutes(59);
211
+ endDate.setSeconds(59);
212
+ endDate.setMilliseconds(999);
213
+ ors.push({ $and: [(_a = {}, _a[filter.field] = { '$gte': startDate }, _a), (_b = {}, _b[filter.field] = { '$lte': endDate }, _b)] });
214
+ }
215
+ else {
216
+ ors.push({ $and: [(_c = {}, _c[filter.field] = { '$gte': filter.value }, _c), (_d = {}, _d[filter.field] = { '$lte': filter.highValue }, _d)] });
217
+ }
218
+ }
219
+ else if (filter.condition === 'nnull') {
220
+ var and = [];
221
+ and.push((_e = {}, _e[filter.field] = { '$exists': true }, _e));
222
+ and.push((_f = {}, _f[filter.field] = { '$ne': null }, _f));
223
+ if (filter.fieldType === 'String') {
224
+ and.push((_g = {}, _g[filter.field] = { '$ne': '' }, _g));
225
+ }
226
+ ors.push({ $and: and });
227
+ }
228
+ else if (filter.condition === 'null') {
229
+ ors.push((_h = {}, _h[filter.field] = { '$eq': null }, _h));
230
+ }
231
+ else {
232
+ if (Array.isArray(filter.value)) {
233
+ if (filter.condition === 'ne') {
234
+ var and_1 = [];
235
+ filter.value.forEach(function (filt) {
236
+ var _a, _b;
237
+ and_1.push((_a = {}, _a[filter.field] = (_b = {}, _b['$' + filter.condition] = (Array.isArray(filt) ? filt[0] : filt), _b), _a));
238
+ });
239
+ if (and_1.length > 1) {
240
+ ors.push({ $and: and_1 });
241
+ }
242
+ else {
243
+ ors.push(and_1[0]);
244
+ }
245
+ }
246
+ else {
247
+ var or_1 = [];
248
+ filter.value.forEach(function (filt) {
249
+ var _a, _b;
250
+ or_1.push((_a = {}, _a[filter.field] = (_b = {}, _b['$' + filter.condition] = (Array.isArray(filt) ? filt[0] : filt), _b), _a));
251
+ });
252
+ if (or_1.length > 1) {
253
+ ors.push({ $or: or_1 });
254
+ }
255
+ else {
256
+ ors.push(or_1[0]);
257
+ }
258
+ }
259
+ }
260
+ else {
261
+ ors.push((_j = {}, _j[filter.field] = (_k = {}, _k['$' + filter.condition] = filter.value, _k), _j));
262
+ }
263
+ }
264
+ }
265
+ });
266
+ if (ors.length) {
267
+ filters_1.push({ $or: ors });
268
+ }
269
+ });
270
+ this.callMethodInternal('reportBuilderBuildTree', report.collection_root, function (errCollTree, collectionTree) {
271
+ if (collectionTree) {
272
+ collectionTree.layers = [collectionTree];
273
+ var treeLeaves = [];
274
+ var allLeaves_1 = [];
275
+ getTreeLeaves(collectionTree.children, treeLeaves);
276
+ getTreeLeaves(collectionTree.children, allLeaves_1, true);
277
+ var filterArrayFields_1 = [];
278
+ var filterArrays_1 = [];
279
+ report.fields_filter.forEach(function (filterAnd) {
280
+ var ors = [];
281
+ filterAnd.ors.filter(function (a) { return a.field.includes('.$.'); }).forEach(function (filter) {
282
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
283
+ if (allLeaves_1.filter(function (a) { return a.fieldPath === filter.field; })[0]) {
284
+ filterArrayFields_1.push(allLeaves_1.filter(function (a) { return a.fieldPath === filter.field; })[0]);
285
+ }
286
+ if (filter.condition && filter.field && ((filter.value !== null && (!Array.isArray(filter.value) || filter.value.length)) || filter.condition === 'null' || filter.condition === 'nnull')) {
287
+ if (filter.condition === 'bw') {
288
+ if (filter.fieldType === 'Date' && filter.is_rolling) {
289
+ var startDate = null;
290
+ var endDate = null;
291
+ if (filter.rolling_interval === 'Q1') {
292
+ startDate = moment().startOf('year').toDate();
293
+ endDate = moment().startOf('year').quarter(2).subtract(1, 'days').toDate();
294
+ }
295
+ else if (filter.rolling_interval === 'Q2') {
296
+ startDate = moment().startOf('year').quarter(2).toDate();
297
+ endDate = moment().startOf('year').quarter(3).subtract(1, 'days').toDate();
298
+ }
299
+ else if (filter.rolling_interval === 'Q3') {
300
+ startDate = moment().startOf('year').quarter(3).toDate();
301
+ endDate = moment().startOf('year').quarter(4).subtract(1, 'days').toDate();
302
+ }
303
+ else if (filter.rolling_interval === 'Q4') {
304
+ startDate = moment().startOf('year').quarter(4).toDate();
305
+ endDate = moment().endOf('year').toDate();
306
+ }
307
+ else if (filter.rolling_interval === 'Today') {
308
+ startDate = moment().startOf('day').toDate();
309
+ endDate = moment().endOf('day').toDate();
310
+ }
311
+ else if (filter.rolling_interval === 'Yesterday') {
312
+ startDate = moment().subtract(1, 'days').startOf('day').toDate();
313
+ endDate = moment().subtract(1, 'days').endOf('day').toDate();
314
+ }
315
+ else if (filter.rolling_interval === 'Week') {
316
+ startDate = moment().startOf('isoWeek').toDate();
317
+ endDate = moment().endOf('day').toDate();
318
+ }
319
+ else if (filter.rolling_interval === 'Last Week') {
320
+ endDate = moment().startOf('isoWeek').subtract(1, 'days').toDate();
321
+ startDate = moment(endDate).startOf('isoWeek').toDate();
322
+ }
323
+ else if (filter.rolling_interval === 'Month') {
324
+ startDate = moment().startOf('month').toDate();
325
+ endDate = moment().endOf('day').toDate();
326
+ }
327
+ else if (filter.rolling_interval === 'Last Month') {
328
+ endDate = moment().startOf('month').subtract(1, 'days').endOf('day').toDate();
329
+ startDate = moment(endDate).startOf('month').toDate();
330
+ }
331
+ else if (filter.rolling_interval === 'Last 30 Days') {
332
+ endDate = moment().endOf('day').toDate();
333
+ startDate = moment().subtract(30, 'days').startOf('day').toDate();
334
+ }
335
+ else if (filter.rolling_interval === 'Quarter') {
336
+ startDate = moment().startOf('year').quarter(moment().quarter()).toDate();
337
+ endDate = moment().endOf('day').toDate();
338
+ }
339
+ else if (filter.rolling_interval === 'Last Quarter') {
340
+ endDate = moment().startOf('year').quarter(moment().quarter()).subtract(1, 'days').endOf('day').toDate();
341
+ startDate = moment(endDate).startOf('quarter').toDate();
342
+ }
343
+ else if (filter.rolling_interval === 'Year') {
344
+ startDate = moment().startOf('year').toDate();
345
+ endDate = moment().endOf('day').toDate();
346
+ }
347
+ else if (filter.rolling_interval === 'Last Year') {
348
+ endDate = moment().startOf('year').subtract(1, 'days').endOf('day').toDate();
349
+ startDate = moment(endDate).startOf('year').toDate();
350
+ }
351
+ else if (filter.rolling_interval === 'All') {
352
+ startDate = new Date(2017, 0, 1, 0, 0, 0, 0);
353
+ endDate = moment().endOf('day').toDate();
354
+ }
355
+ endDate.setHours(23);
356
+ endDate.setMinutes(59);
357
+ endDate.setSeconds(59);
358
+ endDate.setMilliseconds(999);
359
+ ors.push({ $and: [(_a = {}, _a[filter.field.replace(/\.\$/g, '')] = { '$gte': startDate }, _a), (_b = {}, _b[filter.field.replace(/\.\$/g, '')] = { '$lte': endDate }, _b)] });
360
+ }
361
+ else {
362
+ filterArrays_1.push({ $and: [(_c = {}, _c[filter.field.replace(/\.\$/g, '')] = { '$gte': filter.value }, _c), (_d = {}, _d[filter.field.replace(/\.\$/g, '')] = { '$lte': filter.highValue }, _d)] });
363
+ }
364
+ }
365
+ else if (filter.condition === 'nnull') {
366
+ var and = [];
367
+ and.push((_e = {}, _e[filter.field.replace(/\.\$/g, '')] = { '$exists': true }, _e));
368
+ and.push((_f = {}, _f[filter.field.replace(/\.\$/g, '')] = { '$ne': null }, _f));
369
+ if (filter.fieldType === 'String') {
370
+ and.push((_g = {}, _g[filter.field.replace(/\.\$/g, '')] = { '$ne': '' }, _g));
371
+ }
372
+ ors.push({ $and: and });
373
+ }
374
+ else if (filter.condition === 'null') {
375
+ ors.push((_h = {}, _h[filter.field.replace(/\.\$/g, '')] = { '$eq': null }, _h));
376
+ }
377
+ else {
378
+ if (Array.isArray(filter.value)) {
379
+ if (filter.condition === 'ne') {
380
+ var and_2 = [];
381
+ filter.value.forEach(function (filt) {
382
+ var _a, _b;
383
+ and_2.push((_a = {}, _a[filter.field.replace(/\.\$/g, '')] = (_b = {}, _b['$' + filter.condition] = (Array.isArray(filt) ? filt[0] : filt), _b), _a));
384
+ });
385
+ if (and_2.length > 1) {
386
+ ors.push({ $and: and_2 });
387
+ }
388
+ else {
389
+ ors.push(and_2[0]);
390
+ }
391
+ }
392
+ else {
393
+ var or_2 = [];
394
+ filter.value.forEach(function (filt) {
395
+ var _a, _b;
396
+ or_2.push((_a = {}, _a[filter.field.replace(/\.\$/g, '')] = (_b = {}, _b['$' + filter.condition] = (Array.isArray(filt) ? filt[0] : filt), _b), _a));
397
+ });
398
+ if (or_2.length > 1) {
399
+ ors.push({ $or: or_2 });
400
+ }
401
+ else {
402
+ ors.push(or_2[0]);
403
+ }
404
+ }
405
+ }
406
+ else {
407
+ ors.push((_j = {}, _j[filter.field.replace(/\.\$/g, '')] = (_k = {}, _k['$' + filter.condition] = filter.value, _k), _j));
408
+ }
409
+ }
410
+ }
411
+ });
412
+ if (ors.length) {
413
+ filterArrays_1.push({ $or: ors });
414
+ }
415
+ });
416
+ _this.callMethodInternal('reportBuilderGetResults', report.type, report.collection_root, rootOptions_1, filters_1, filterArrays_1, filterArrayFields_1, report.fields_selected, report.fields_custom, report.groups_row, report.fields_total, report.fields_link, report.id_date_field || null, report.date_interval || null, report.group_type, function (err, res) {
417
+ if (res && res[0]) {
418
+ var results_1 = res[0].results;
419
+ var reportTotals = res[0].totals;
420
+ if (report.type === 'List') {
421
+ report.fields_selected.filter(function (a) { return a.show; }).forEach(function (field) {
422
+ if ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'Number') {
423
+ results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
424
+ result[field.id] = result[field.id].toLocaleString();
425
+ });
426
+ }
427
+ else if ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'String') {
428
+ results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
429
+ result[field.id] = result[field.id].toLocaleString('en-US', { style: 'currency', currency: 'USD' });
430
+ });
431
+ }
432
+ else if ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'Currency') {
433
+ results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
434
+ result[field.id] = result[field.id].toLocaleString('en-US', { style: 'currency', currency: 'USD' });
435
+ });
436
+ }
437
+ else if (field.fieldType === 'Boolean' && (!field.leafFormatType || field.leafFormatType === 'Boolean')) {
438
+ results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
439
+ result[field.id] = result[field.id] === true ? 'True' : 'False';
440
+ });
441
+ }
442
+ else if (field.fieldType === 'Boolean' && field.leafFormatType === 'String') {
443
+ results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
444
+ result[field.id] = result[field.id] === true ? 'Yes' : 'No';
445
+ });
446
+ }
447
+ else if (field.fieldType === 'Boolean' && field.leafFormatType === 'Boolean_Number') {
448
+ results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
449
+ result[field.id] = result[field.id] === true ? 1 : 0;
450
+ });
451
+ }
452
+ else if (field.fieldType === 'Date' && (field.leafFormatType === 'Date')) {
453
+ results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
454
+ result[field.id] = moment(result[field.id]).format('L');
455
+ });
456
+ }
457
+ else if (field.fieldType === 'Date' && field.leafFormatType === 'Time') {
458
+ results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
459
+ result[field.id] = moment(result[field.id]).format('LT');
460
+ });
461
+ }
462
+ else if (field.fieldType === 'Date' && field.leafFormatType === 'DateTime') {
463
+ results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
464
+ result[field.id] = moment(result[field.id]).format('MM/DD/YYYY h:mm A');
465
+ });
466
+ }
467
+ else if (field.fieldType === 'Date' && field.leafFormatType === 'Date_long') {
468
+ results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
469
+ result[field.id] = moment(result[field.id]).format('LL');
470
+ });
471
+ }
472
+ else if (field.fieldType === 'Date' && field.leafFormatType === 'DateTime_long') {
473
+ results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
474
+ result[field.id] = moment(result[field.id]).format('LLL');
475
+ });
476
+ }
477
+ else if (field.fieldType === 'Date' && field.leafFormatType === 'Timestamp') {
478
+ results_1.filter(function (a) { return a[field.id] !== null && a[field.id] !== undefined; }).forEach(function (result) {
479
+ result[field.id] = moment(result[field.id]).toDate().getTime();
480
+ });
481
+ }
482
+ });
483
+ var lines_1 = [];
484
+ var tmpHeaders_1 = {};
485
+ report.groups_row.forEach(function (group) {
486
+ tmpHeaders_1[group.id] = group.columnName;
487
+ });
488
+ report.fields_selected.filter(function (a) { return a.show; }).forEach(function (header) {
489
+ tmpHeaders_1[header.columnName] = header.columnName;
490
+ });
491
+ var wb = XLSX.utils.book_new();
492
+ results_1.forEach(function (result) {
493
+ var tmp = {};
494
+ report.groups_row.forEach(function (group) {
495
+ if (Array.isArray(result._id[group.id])) {
496
+ tmp[group.columnName] = result._id[group.id].join(',');
497
+ }
498
+ else {
499
+ if (group.treeItem.fieldType === 'Number') {
500
+ tmp[group.columnName] = result._id[group.id] ? (typeof (result._id[group.id]) === 'string' ? parseFloat(result._id[group.id].replace(/,/g, '').replace(/\$/g, '')) : result._id[group.id]) : '';
501
+ }
502
+ else {
503
+ tmp[group.columnName] = result._id[group.id] || '';
504
+ }
505
+ }
506
+ });
507
+ report.fields_selected.filter(function (a) { return a.show; }).forEach(function (header) {
508
+ if (Array.isArray(result[header.id])) {
509
+ tmp[header.columnName] = result[header.id].join(',');
510
+ }
511
+ else {
512
+ if (header.fieldType === 'Number' || header.leafValueType === 'Count') {
513
+ tmp[header.columnName] = result[header.id] ? (typeof (result[header.id]) === 'string' ? parseFloat(result[header.id].replace(/,/g, '').replace(/\$/g, '')) : result[header.id]) : '';
514
+ }
515
+ else {
516
+ tmp[header.columnName] = result[header.id] || '';
517
+ }
518
+ }
519
+ });
520
+ lines_1.push(tmp);
521
+ });
522
+ var ws = XLSX.utils.json_to_sheet(lines_1);
523
+ XLSX.utils.book_append_sheet(wb, ws, 'RB Data');
524
+ var wbout_1 = XLSX.write(wb, { bookType: 'xlsx', type: 'base64' });
525
+ data['emails'].forEach(function (email) {
526
+ _this.sendEmail(email, _this.serverConfig['CLIENT_NAME'] + ' Scheduled Report - ' + report.report_name, '', "\n\t\t\t\t\t\t\t\t\t\t\t\t<b>" + _this.serverConfig['CLIENT_NAME'] + " Automated Report</b><br>\n\t\t\t\t\t\t\t\t\t\t\t\t<b>Report Name: </b>" + report.report_name + "<br>\n\t\t\t\t\t\t\t\t\t\t\t\t<b>Prepared By: </b>" + data['user'] + "<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\tAttached are the results of this automated report.<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\tResolveIO<br><br>", [
527
+ {
528
+ filename: report.report_name + '-' + moment().format('MM-DD-YYYY-hh-mm-A') + '.xlsx',
529
+ content: wbout_1,
530
+ encoding: 'base64'
531
+ }
532
+ ], _this.serverConfig['MAIL_FROM_REPORTS'], '');
533
+ });
534
+ }
535
+ else if (report.type === 'Group') {
536
+ report.fields_selected.filter(function (a) { return a.show; }).forEach(function (field) {
537
+ results_1.forEach(function (result) {
538
+ modifyDataTypeField(report, result, field, 1);
539
+ });
540
+ });
541
+ var wb = new Excel.Workbook();
542
+ var ws_1 = wb.addWorksheet('RB_1', { views: [{ showGridLines: false }] });
543
+ wb.properties.date1904 = false;
544
+ wb.calcProperties.fullCalcOnLoad = true;
545
+ var currentRow_1 = 1;
546
+ var row = ws_1.getRow(currentRow_1);
547
+ row.getCell(2).font = {
548
+ name: 'Arial',
549
+ bold: true,
550
+ size: 14
551
+ };
552
+ row.getCell(4).font = {
553
+ name: 'Arial',
554
+ size: 14
555
+ };
556
+ row.getCell(2).value = 'Report Name:';
557
+ row.getCell(4).value = report.report_name;
558
+ currentRow_1 += 1;
559
+ row = ws_1.getRow(currentRow_1);
560
+ row.getCell(2).font = {
561
+ name: 'Arial',
562
+ bold: true,
563
+ size: 14
564
+ };
565
+ row.getCell(4).font = {
566
+ name: 'Arial',
567
+ size: 14
568
+ };
569
+ row.getCell(2).value = 'Run Date:';
570
+ row.getCell(4).value = moment().format('LLL');
571
+ currentRow_1 += 2;
572
+ var copy = (0, common_1.deepCopy)(results_1);
573
+ var widths_1 = [];
574
+ copy.forEach(function (res) {
575
+ currentRow_1 = tabGroupExcelRecursive(report, ws_1, currentRow_1, 1, res);
576
+ tabGroupExcelWidthRecursive(report, 1, res, widths_1);
577
+ });
578
+ for (var i = 1; i < ws_1.columns.length; i++) {
579
+ ws_1.columns[i].width = widths_1[i - 1];
580
+ }
581
+ var now_1 = new Date();
582
+ wb.xlsx.writeBuffer().then(function (buffer) {
583
+ data['emails'].forEach(function (email) {
584
+ _this.sendEmail(email, _this.serverConfig['CLIENT_NAME'] + ' Scheduled Report - ' + report.report_name, '', "\n\t\t\t\t\t\t\t\t\t\t\t\t\t<b>" + _this.serverConfig['CLIENT_NAME'] + " Automated Report</b><br>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<b>Report Name: </b>" + report.report_name + "<br>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<b>Prepared By: </b>" + data['user'] + "<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\t\tAttached are the results of this automated report.<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\t\tHave a great day!<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\t\tResolveIO<br><br>", [
585
+ {
586
+ filename: 'Group_Report_' + report.report_name + '_' + now_1.getFullYear() + '_' + (now_1.getMonth() + 1) + '_' + now_1.getDate() + '.xlsx',
587
+ content: buffer
588
+ }
589
+ ], _this.serverConfig['MAIL_FROM_REPORTS'], '');
590
+ });
591
+ }).catch(function (err) { return console.log('Error writing excel export', err); });
592
+ }
593
+ else if (report.type === 'Dated') {
594
+ var lines_2 = [];
595
+ var tmpHeaders_2 = {};
596
+ report.groups_row.forEach(function (group) {
597
+ tmpHeaders_2[group.id] = group.columnName;
598
+ });
599
+ tmpHeaders_2[''] = '';
600
+ var datedUniqueDates_1 = [];
601
+ var datedUniqueGroups_1 = [];
602
+ if (report.date_interval === 'Quarterly') {
603
+ results_1.forEach(function (dataPt) {
604
+ if (dataPt._id.month < 4) {
605
+ dataPt._id.quarter = 1;
606
+ }
607
+ else if (dataPt._id.month < 7) {
608
+ dataPt._id.quarter = 2;
609
+ }
610
+ else if (dataPt._id.month < 10) {
611
+ dataPt._id.quarter = 3;
612
+ }
613
+ else {
614
+ dataPt._id.quarter = 4;
615
+ }
616
+ delete dataPt._id.month;
617
+ });
618
+ var _loop_1 = function (i) {
619
+ var dataPt = results_1[i];
620
+ if (results_1.filter(function (a) { return JSON.stringify(a._id) === JSON.stringify(dataPt._id); }).length > 1) {
621
+ var tmpData_1 = results_1.filter(function (a) { return JSON.stringify(a._id) === JSON.stringify(dataPt._id); })[0];
622
+ Object.keys(tmpData_1).filter(function (a) { return a !== '_id'; }).forEach(function (key) {
623
+ tmpData_1[key] += dataPt[key];
624
+ });
625
+ results_1.splice(i, 1);
626
+ }
627
+ };
628
+ for (var i = results_1.length - 1; i >= 1; i--) {
629
+ _loop_1(i);
630
+ }
631
+ }
632
+ var tmpResults = (0, common_1.deepCopy)(results_1);
633
+ tmpResults.forEach(function (result) {
634
+ delete result._id.day;
635
+ delete result._id.week;
636
+ delete result._id.month;
637
+ delete result._id.quarter;
638
+ delete result._id.year;
639
+ var tmp = {};
640
+ Object.keys(result._id).forEach(function (key) {
641
+ tmp[key] = result._id[key];
642
+ });
643
+ if (!datedUniqueGroups_1.filter(function (a) { return JSON.stringify(a) === JSON.stringify(tmp); }).length) {
644
+ datedUniqueGroups_1.push(tmp);
645
+ }
646
+ });
647
+ tmpResults = (0, common_1.deepCopy)(results_1);
648
+ tmpResults.forEach(function (result) {
649
+ Object.keys(result._id).filter(function (a) { return a !== 'second' && a !== 'hour' && a !== 'minute' && a !== 'day' && a !== 'week' && a !== 'month' && a !== 'quarter' && a !== 'year'; }).forEach(function (key) {
650
+ delete result._id[key];
651
+ });
652
+ var tmp = {};
653
+ Object.keys(result._id).forEach(function (key) {
654
+ tmp[key] = result._id[key];
655
+ });
656
+ if (!datedUniqueDates_1.filter(function (a) { return JSON.stringify(a) === JSON.stringify(tmp); }).length) {
657
+ datedUniqueDates_1.push(tmp);
658
+ }
659
+ });
660
+ datedUniqueDates_1.forEach(function (result) {
661
+ if (!result.year) {
662
+ result.dateString = 'No Date';
663
+ }
664
+ else {
665
+ if (report.date_interval === 'Seconds') {
666
+ result.date = new Date(result.year, result.month - 1, result.day, result.hour, result.minute, result.second, 0);
667
+ result.dateString = moment(result.date).format('MMM DD YYYY HH:mm:ss');
668
+ }
669
+ else if (report.date_interval === 'Minutes') {
670
+ result.date = new Date(result.year, result.month - 1, result.day, result.hour, result.minute, 0, 0);
671
+ result.dateString = moment(result.date).format('MMM DD YYYY HH:mm');
672
+ }
673
+ else if (report.date_interval === 'Hours') {
674
+ result.date = new Date(result.year, result.month - 1, result.day, result.hour, 0, 0, 0);
675
+ result.dateString = moment(result.date).format('MMM DD YYYY HH');
676
+ }
677
+ else if (report.date_interval === 'Daily') {
678
+ result.date = new Date(result.year, result.month - 1, result.day, 0, 0, 0, 0);
679
+ result.dateString = moment(result.date).format('MMM DD YYYY');
680
+ }
681
+ else if (report.date_interval === 'Weekly') {
682
+ result.date = moment().day('Monday').isoWeekYear(result.year).isoWeek(result.week).toDate();
683
+ result.dateLast = moment().day('Sunday').isoWeekYear(result.year).isoWeek(result.week).toDate();
684
+ result.dateString = 'Week #' + result.week + ' ' + result.year + '(' + moment(result.date).format('MM/DD/YY') + ' - ' + moment(result.dateLast).format('MM/DD/YY') + ')';
685
+ }
686
+ else if (report.date_interval === 'Monthly') {
687
+ result.date = new Date(result.year, result.month - 1, 1, 0, 0, 0, 0);
688
+ result.dateString = moment(result.date).format('MMM YYYY');
689
+ }
690
+ else if (report.date_interval === 'Quarterly') {
691
+ result.date = moment().quarter(result.quarter).year(result.year).toDate();
692
+ result.dateString = 'Q' + result.quarter + ' ' + result.year;
693
+ }
694
+ else if (report.date_interval === 'Yearly') {
695
+ result.date = new Date(result.year);
696
+ result.dateString = result.year.toString();
697
+ }
698
+ }
699
+ });
700
+ datedUniqueDates_1 = datedUniqueDates_1.filter(function (a) { return !a.date; }).concat(datedUniqueDates_1.filter(function (a) { return a.date; }).sort(function (a, b) { return a.date.getTime() - b.date.getTime(); }));
701
+ var reportTotalGroups_1 = [];
702
+ var reportTotalDates_1 = [];
703
+ var datedData_1 = [];
704
+ datedUniqueDates_1.forEach(function (date) {
705
+ var tmpData = [];
706
+ var tmpTotalDated = {};
707
+ var tmpTotalCnt = {};
708
+ var tmpTotalType = {};
709
+ datedUniqueGroups_1.forEach(function (group) {
710
+ var result = results_1.filter(function (a) {
711
+ var res = true;
712
+ Object.keys(date).filter(function (a) { return a !== 'date' && a !== 'dateLast' && a !== 'dateString'; }).forEach(function (key) {
713
+ if (a._id[key] !== date[key]) {
714
+ res = false;
715
+ }
716
+ });
717
+ Object.keys(group).forEach(function (key) {
718
+ if (a._id[key] !== group[key]) {
719
+ res = false;
720
+ }
721
+ });
722
+ return res;
723
+ })[0];
724
+ if (result) {
725
+ tmpData.push(result);
726
+ Object.keys(result._id).filter(function (a) { return a; }).forEach(function (key) {
727
+ if (report.fields_total.filter(function (a) { return a.fields.includes(key); }).length) {
728
+ if (!tmpTotalDated[key]) {
729
+ tmpTotalDated[key] = result._id[key];
730
+ }
731
+ else {
732
+ tmpTotalDated[key] += result._id[key];
733
+ }
734
+ if (!tmpTotalCnt[key]) {
735
+ tmpTotalCnt[key] = 1;
736
+ }
737
+ else {
738
+ tmpTotalCnt[key] += 1;
739
+ }
740
+ tmpTotalType[key] = report.fields_total.filter(function (a) { return a.fields.includes(key); })[0].type;
741
+ }
742
+ });
743
+ Object.keys(result).filter(function (a) { return a && a !== '_id'; }).forEach(function (key) {
744
+ if (report.fields_total.filter(function (a) { return a.fields.includes(key); }).length) {
745
+ if (!tmpTotalDated[key]) {
746
+ tmpTotalDated[key] = result[key];
747
+ }
748
+ else {
749
+ tmpTotalDated[key] += result[key];
750
+ }
751
+ if (!tmpTotalCnt[key]) {
752
+ tmpTotalCnt[key] = 1;
753
+ }
754
+ else {
755
+ tmpTotalCnt[key] += 1;
756
+ }
757
+ tmpTotalType[key] = report.fields_total.filter(function (a) { return a.fields.includes(key); })[0].type;
758
+ }
759
+ });
760
+ }
761
+ else {
762
+ tmpData.push(null);
763
+ }
764
+ });
765
+ Object.keys(tmpTotalType).forEach(function (totalKey) {
766
+ if (tmpTotalType[totalKey] === 'avg') {
767
+ tmpTotalDated[totalKey] = tmpTotalDated[totalKey] / tmpTotalCnt[totalKey];
768
+ }
769
+ tmpTotalDated[totalKey] = Math.round(tmpTotalDated[totalKey] * 100) / 100;
770
+ });
771
+ reportTotalDates_1.push(tmpTotalDated);
772
+ datedData_1.push(tmpData);
773
+ });
774
+ datedUniqueGroups_1.forEach(function (group) {
775
+ var tmpTotalGroup = {};
776
+ var filteredData = results_1.filter(function (a) {
777
+ var res = (!Object.keys(group).length || group._id === null) ? false : true;
778
+ Object.keys(group).filter(function (a) { return a !== 'date' && a !== 'dateLast' && a !== 'dateString' && a !== 'second' && a !== 'minute' && a !== 'hour' && a !== 'day' && a !== 'week' && a !== 'month' && a !== 'quarter' && a !== 'year'; }).forEach(function (key) {
779
+ if (a._id[key] !== group[key]) {
780
+ res = false;
781
+ }
782
+ });
783
+ return res;
784
+ });
785
+ report.fields_total.forEach(function (total) {
786
+ total.fields.forEach(function (field) {
787
+ if (filteredData.length) {
788
+ tmpTotalGroup[field] = filteredData.filter(function (a) { return a && a[field]; }).map(function (a) { return a[field]; }).reduce(function (a, b) { return a + b; }, 0);
789
+ if (total.type === 'avg') {
790
+ tmpTotalGroup[field] = Math.round(tmpTotalGroup[field] / filteredData.length * 100) / 100;
791
+ }
792
+ }
793
+ else {
794
+ tmpTotalGroup[field] = 0;
795
+ }
796
+ });
797
+ });
798
+ reportTotalGroups_1.push(tmpTotalGroup);
799
+ });
800
+ datedUniqueDates_1.forEach(function (date) {
801
+ tmpHeaders_2[date.dateString] = date.dateString;
802
+ });
803
+ report.fields_total.forEach(function (total) {
804
+ tmpHeaders_2['Totals - ' + total.type.toUpperCase()] = 'Totals - ' + (0, common_1.toTitleCase)(total.type);
805
+ });
806
+ lines_2.push(tmpHeaders_2);
807
+ var selectedFields_1 = (0, common_1.deepCopy)(report.fields_selected);
808
+ //add custom
809
+ report.fields_custom.forEach(function (customField) {
810
+ selectedFields_1.push({
811
+ collection_name: '',
812
+ columnName: customField.columnName,
813
+ fieldName: customField.selFieldId,
814
+ fieldType: 'Number',
815
+ fieldTypeName: 'Number',
816
+ distinctFieldValues: [],
817
+ fieldPath: customField.selFieldId,
818
+ fieldPathName: 'Custom Field',
819
+ lookup_collection: '',
820
+ lookup_local_key: '',
821
+ lookup_foreign_key: '',
822
+ lookup_as: '',
823
+ text: '',
824
+ value: '',
825
+ isLeaf: true,
826
+ isActive: true,
827
+ isSelected: true,
828
+ depth: 0,
829
+ leafValueType: customField.leafValueType,
830
+ leafValueTypes: [],
831
+ leafFormatType: 'Number',
832
+ leafFormatTypes: [],
833
+ id: customField.selFieldId,
834
+ show: true
835
+ });
836
+ });
837
+ for (var i = 0; i < datedUniqueGroups_1.length; i++) {
838
+ var group = datedUniqueGroups_1[i];
839
+ var fieldsSelectedArr = selectedFields_1.filter(function (a) { return a.show; });
840
+ var _loop_2 = function (j) {
841
+ var field = fieldsSelectedArr[j];
842
+ var tmp = {};
843
+ for (var k = 0; k <= report.groups_row.length - 1; k++) {
844
+ var groupRow = report.groups_row[k];
845
+ if (j === 0) {
846
+ tmp[group[groupRow.id]] = group[groupRow.id];
847
+ }
848
+ else {
849
+ tmp[group[groupRow.id]] = '';
850
+ }
851
+ }
852
+ tmp[field.columnName] = field.columnName;
853
+ for (var k = 0; k <= datedData_1.length - 1; k++) {
854
+ var result = datedData_1[k];
855
+ if (result[i]) {
856
+ if (allLeaves_1.filter(function (a) { return a.id === field.id; })[0] && allLeaves_1.filter(function (a) { return a.id === field.id; })[0].fieldType === 'Number') {
857
+ tmp[i + ' ' + j + ' ' + k] = result[i][field.id] ? (typeof (result[i][field.id]) === 'string' ? parseInt(result[i][field.id].replace(/,/g, '')) : result[i][field.id]) : '';
858
+ }
859
+ else {
860
+ tmp[i + ' ' + j + ' ' + k] = result[i][field.id] ? (typeof (result[i][field.id]) === 'string' ? result[i][field.id].replace(/,/g, '') : result[i][field.id]) : '';
861
+ }
862
+ }
863
+ else {
864
+ tmp[i + ' ' + j + ' ' + k] = '';
865
+ }
866
+ }
867
+ for (var k = 0; k <= report.fields_total.length - 1; k++) {
868
+ var total = report.fields_total[k];
869
+ if (total.fields.includes(field.id)) {
870
+ tmp['total' + i + ' ' + j + ' ' + k] = reportTotalGroups_1[i][field.id] ? (typeof (reportTotalGroups_1[i][field.id]) === 'string' ? parseInt(reportTotalGroups_1[i][field.id].replace(/,/g, '')) : reportTotalGroups_1[i][field.id]) : '';
871
+ }
872
+ else {
873
+ tmp['total' + i + ' ' + j + ' ' + k] = '';
874
+ }
875
+ }
876
+ lines_2.push(tmp);
877
+ };
878
+ for (var j = 0; j < fieldsSelectedArr.length; j++) {
879
+ _loop_2(j);
880
+ }
881
+ }
882
+ if (reportTotals) {
883
+ for (var i = 0; i < report.fields_total.length; i++) {
884
+ var total = report.fields_total[i];
885
+ var tmp = {};
886
+ tmp[total.type] = (0, common_1.toTitleCase)(total.type) + ' Totals';
887
+ for (var j = 0; j < report.groups_row.length - 1; j++) {
888
+ tmp['total_gr_j'] = '';
889
+ }
890
+ tmp['Total - Fields'] = '';
891
+ for (var j = 0; j < datedData_1.length; j++) {
892
+ tmp['Total - Dated ' + j] = '';
893
+ }
894
+ for (var j = 0; j <= report.fields_selected.filter(function (a) { return a.show; }).length - 1; j++) {
895
+ var field = report.fields_selected.filter(function (a) { return a.show; })[j];
896
+ if (total.fields.includes(field.id)) {
897
+ tmp['totalreportTotals' + j] = reportTotals[total.id + '_' + field.id];
898
+ }
899
+ else {
900
+ tmp['totalreportTotals' + j] = '';
901
+ }
902
+ }
903
+ lines_2.push(tmp);
904
+ }
905
+ }
906
+ var newCSV_1 = '';
907
+ lines_2.forEach(function (row, index) {
908
+ Object.keys(row).forEach(function (key, keyIndex) {
909
+ if (row[key] && typeof (row[key]) === 'string') {
910
+ row[key] = row[key].replace(new RegExp(/,/g), '');
911
+ }
912
+ newCSV_1 += row[key];
913
+ if (keyIndex < Object.keys(row).length - 1) {
914
+ newCSV_1 += ',';
915
+ }
916
+ });
917
+ if (index < lines_2.length - 1) {
918
+ newCSV_1 += '\r\n';
919
+ }
920
+ });
921
+ data['emails'].forEach(function (email) {
922
+ _this.sendEmail(email, _this.serverConfig['CLIENT_NAME'] + ' Scheduled Report - ' + report.report_name, '', "\n\t\t\t\t\t\t\t\t\t\t\t\t<b>" + _this.serverConfig['CLIENT_NAME'] + " Automated Report</b><br>\n\t\t\t\t\t\t\t\t\t\t\t\t<b>Report Name: </b>" + report.report_name + "<br>\n\t\t\t\t\t\t\t\t\t\t\t\t<b>Prepared By: </b>" + data['user'] + "<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\tAttached are the results of this automated report.<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\tHave a great day!<br><br>\n\t\t\t\t\t\t\t\t\t\t\t\tResolveIO<br><br>", [
923
+ {
924
+ filename: report.report_name + '-' + moment().format('MM-DD-YYYY-hh-mm-A') + '.csv',
925
+ content: newCSV_1
926
+ }
927
+ ], _this.serverConfig['MAIL_FROM_REPORTS'], '');
928
+ });
929
+ resolve(true);
930
+ }
931
+ }
932
+ else {
933
+ _this.callMethodInternal('insertErrorLog', 'Report Builder Cron Job - Report Builder Get Results', [
934
+ err
935
+ ]);
936
+ reject(err);
937
+ }
938
+ });
939
+ }
940
+ });
941
+ }
942
+ return [2 /*return*/];
943
+ }
944
+ });
945
+ }); });
946
+ }
947
+ }
948
+ });
949
+ }
950
+ exports.loadCronJobMethods = loadCronJobMethods;
951
+ function getTreeLeaves(items, resArray, allowLookups) {
952
+ if (allowLookups === void 0) { allowLookups = false; }
953
+ items.forEach(function (item) {
954
+ if (item.isLeaf) {
955
+ resArray.push(item);
956
+ }
957
+ else {
958
+ if (!item.lookup_collection || allowLookups) {
959
+ getTreeLeaves(item.children, resArray, allowLookups);
960
+ }
961
+ }
962
+ });
963
+ }
964
+ function modifyDataTypeField(report, result, field, index) {
965
+ if (index < report.groups_row.length) {
966
+ result = result['gr_' + (index + 1)];
967
+ result.forEach(function (tDataRes, tIndex) {
968
+ modifyDataTypeField(report, tDataRes, field, index + 1);
969
+ });
970
+ }
971
+ else {
972
+ if (Array.isArray(result[field.id])) {
973
+ result[field.id].forEach(function (arr, arrIndex) {
974
+ if ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'Number') {
975
+ result[field.id].splice(arrIndex, 1, arr.toLocaleString());
976
+ }
977
+ else if ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'String') {
978
+ result[field.id].splice(arrIndex, 1, arr.toString());
979
+ }
980
+ else if ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'Currency') {
981
+ result[field.id].splice(arrIndex, 1, arr.toLocaleString('en-US', { style: 'currency', currency: 'USD' }));
982
+ }
983
+ else if (field.fieldType === 'Boolean' && (!field.leafFormatType || field.leafFormatType === 'Boolean')) {
984
+ result[field.id].splice(arrIndex, 1, arr === true ? 'True' : 'False');
985
+ }
986
+ else if (field.fieldType === 'Boolean' && field.leafFormatType === 'String') {
987
+ result[field.id].splice(arrIndex, 1, arr === true ? 'Yes' : 'No');
988
+ }
989
+ else if (field.fieldType === 'Boolean' && field.leafFormatType === 'Boolean_Number') {
990
+ result[field.id].splice(arrIndex, 1, arr === true ? 1 : 0);
991
+ }
992
+ else if (field.fieldType === 'Date' && (field.leafFormatType === 'Date')) {
993
+ result[field.id].splice(arrIndex, 1, moment(arr).format('L'));
994
+ }
995
+ else if (field.fieldType === 'Date' && field.leafFormatType === 'Time') {
996
+ result[field.id].splice(arrIndex, 1, moment(arr).format('LT'));
997
+ }
998
+ else if (field.fieldType === 'Date' && field.leafFormatType === 'DateTime') {
999
+ result[field.id].splice(arrIndex, 1, moment(arr).format('MM/DD/YYYY h:mm A'));
1000
+ }
1001
+ else if (field.fieldType === 'Date' && field.leafFormatType === 'Date_long') {
1002
+ result[field.id].splice(arrIndex, 1, moment(arr).format('LL'));
1003
+ }
1004
+ else if (field.fieldType === 'Date' && field.leafFormatType === 'DateTime_long') {
1005
+ result[field.id].splice(arrIndex, 1, moment(arr).format('LLL'));
1006
+ }
1007
+ else if (field.fieldType === 'Date' && field.leafFormatType === 'Timestamp') {
1008
+ result[field.id].splice(arrIndex, 1, moment(arr).toDate().getTime());
1009
+ }
1010
+ });
1011
+ }
1012
+ else {
1013
+ if ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'Number') {
1014
+ result[field.id] = result[field.id].toLocaleString();
1015
+ }
1016
+ else if ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'String') {
1017
+ result[field.id] = result[field.id].toString();
1018
+ }
1019
+ else if ((field.fieldType === 'Number' || field.leafValueType === 'Count') && field.leafFormatType === 'Currency') {
1020
+ result[field.id] = result[field.id].toLocaleString('en-US', { style: 'currency', currency: 'USD' });
1021
+ }
1022
+ else if (field.fieldType === 'Boolean' && (!field.leafFormatType || field.leafFormatType === 'Boolean')) {
1023
+ result[field.id] = result[field.id] === true ? 'True' : 'False';
1024
+ }
1025
+ else if (field.fieldType === 'Boolean' && field.leafFormatType === 'String') {
1026
+ result[field.id] = result[field.id] === true ? 'Yes' : 'No';
1027
+ }
1028
+ else if (field.fieldType === 'Boolean' && field.leafFormatType === 'Boolean_Number') {
1029
+ result[field.id] = result[field.id] === true ? 1 : 0;
1030
+ }
1031
+ else if (field.fieldType === 'Date' && (field.leafFormatType === 'Date')) {
1032
+ result[field.id] = moment(result[field.id]).format('L');
1033
+ }
1034
+ else if (field.fieldType === 'Date' && field.leafFormatType === 'Time') {
1035
+ result[field.id] = moment(result[field.id]).format('LT');
1036
+ }
1037
+ else if (field.fieldType === 'Date' && field.leafFormatType === 'DateTime') {
1038
+ result[field.id] = moment(result[field.id]).format('MM/DD/YYYY h:mm A');
1039
+ }
1040
+ else if (field.fieldType === 'Date' && field.leafFormatType === 'Date_long') {
1041
+ result[field.id] = moment(result[field.id]).format('LL');
1042
+ }
1043
+ else if (field.fieldType === 'Date' && field.leafFormatType === 'DateTime_long') {
1044
+ result[field.id] = moment(result[field.id]).format('LLL');
1045
+ }
1046
+ else if (field.fieldType === 'Date' && field.leafFormatType === 'Timestamp') {
1047
+ result[field.id] = moment(result[field.id]).toDate().getTime();
1048
+ }
1049
+ }
1050
+ }
1051
+ }
1052
+ function tabGroupExcelRecursive(report, ws, currentRow, level, result) {
1053
+ var row = ws.getRow(currentRow);
1054
+ if (level < report.groups_row.length) {
1055
+ row.getCell(2).fill = {
1056
+ fgColor: { argb: report.groups_row[level - 1].fill_color ? report.groups_row[level - 1].fill_color.replace('#', '') : 'ffffff' },
1057
+ type: 'pattern',
1058
+ pattern: 'solid'
1059
+ };
1060
+ row.getCell(2).font = {
1061
+ color: { argb: report.groups_row[level - 1].font_color ? report.groups_row[level - 1].font_color.replace('#', '') : '000000' },
1062
+ name: 'Arial',
1063
+ bold: true,
1064
+ size: 14
1065
+ };
1066
+ row.getCell(2).value = report.groups_row[level - 1].columnName + ': ' + result._id['gr_' + level];
1067
+ ws.mergeCells(row.getCell(2).$col$row + ':' + row.getCell(report.fields_selected.filter(function (a) { return a.show; }).length + 1).$col$row);
1068
+ row.getCell(2).border = {
1069
+ top: { style: 'thick' },
1070
+ left: { style: 'thick' },
1071
+ right: { style: 'thick' }
1072
+ };
1073
+ if (report.fields_total.length) {
1074
+ report.fields_total.forEach(function (total) {
1075
+ currentRow += 1;
1076
+ row = ws.getRow(currentRow);
1077
+ report.fields_selected.filter(function (a) { return a.show; }).forEach(function (field, fieldIndex) {
1078
+ if (total.fields.includes(field.id)) {
1079
+ row.getCell(fieldIndex + 2).value = field.columnName;
1080
+ row.getCell(fieldIndex + 2).font = {
1081
+ name: 'Arial',
1082
+ bold: true,
1083
+ size: 10
1084
+ };
1085
+ }
1086
+ if (field.leafFormatType === 'Currency') {
1087
+ row.getCell(fieldIndex + 2).numFmt = '"$"#,##0.00';
1088
+ }
1089
+ else if (field.leafFormatType === 'Number') {
1090
+ row.getCell(fieldIndex + 2).numFmt = '#,##0';
1091
+ }
1092
+ if (fieldIndex === 0) {
1093
+ row.getCell(fieldIndex + 2).border = {
1094
+ left: { style: 'thick' }
1095
+ };
1096
+ }
1097
+ else if (fieldIndex === report.fields_selected.filter(function (a) { return a.show; }).length - 1) {
1098
+ row.getCell(fieldIndex + 2).border = {
1099
+ right: { style: 'thick' }
1100
+ };
1101
+ }
1102
+ });
1103
+ });
1104
+ }
1105
+ // Totals
1106
+ report.fields_total.forEach(function (total) {
1107
+ currentRow += 1;
1108
+ row = ws.getRow(currentRow);
1109
+ report.fields_selected.filter(function (a) { return a.show; }).forEach(function (field, fieldIndex) {
1110
+ if (total.fields.includes(field.id)) {
1111
+ row.getCell(fieldIndex + 2).value = result[total.id + '_' + field.id];
1112
+ row.getCell(fieldIndex + 2).font = {
1113
+ name: 'Arial',
1114
+ bold: true,
1115
+ size: 10
1116
+ };
1117
+ if (field.leafFormatType === 'Currency') {
1118
+ row.getCell(fieldIndex + 2).numFmt = '"$"#,##0.00';
1119
+ }
1120
+ else if (field.leafFormatType === 'Number') {
1121
+ row.getCell(fieldIndex + 2).numFmt = '#,##0';
1122
+ }
1123
+ }
1124
+ if (fieldIndex === 0) {
1125
+ row.getCell(fieldIndex + 2).border = {
1126
+ top: { style: 'thin' },
1127
+ left: { style: 'thick' },
1128
+ bottom: { style: 'thick' }
1129
+ };
1130
+ }
1131
+ else if (fieldIndex === report.fields_selected.filter(function (a) { return a.show; }).length - 1) {
1132
+ row.getCell(fieldIndex + 2).border = {
1133
+ top: { style: 'thin' },
1134
+ bottom: { style: 'thick' },
1135
+ right: { style: 'thick' }
1136
+ };
1137
+ }
1138
+ else {
1139
+ row.getCell(fieldIndex + 2).border = {
1140
+ top: { style: 'thin' },
1141
+ bottom: { style: 'thick' }
1142
+ };
1143
+ }
1144
+ });
1145
+ });
1146
+ currentRow += 1;
1147
+ result = result['gr_' + (level + 1)];
1148
+ result.forEach(function (tDataRes, tIndex) {
1149
+ currentRow = tabGroupExcelRecursive(report, ws, currentRow, level + 1, tDataRes);
1150
+ });
1151
+ }
1152
+ else {
1153
+ row.getCell(2).fill = {
1154
+ fgColor: { argb: report.groups_row[level - 1].fill_color ? report.groups_row[level - 1].fill_color.replace('#', '') : 'ffffff' },
1155
+ type: 'pattern',
1156
+ pattern: 'solid'
1157
+ };
1158
+ row.getCell(2).font = {
1159
+ color: { argb: report.groups_row[level - 1].font_color ? report.groups_row[level - 1].font_color.replace('#', '') : '000000' },
1160
+ name: 'Arial',
1161
+ bold: true,
1162
+ size: 12
1163
+ };
1164
+ row.getCell(2).value = report.groups_row[level - 1].columnName + ': ' + result._id['gr_' + level];
1165
+ ws.mergeCells(row.getCell(2).$col$row + ':' + row.getCell(report.fields_selected.filter(function (a) { return a.show; }).length + 1).$col$row);
1166
+ row.getCell(2).border = {
1167
+ top: { style: 'thick' },
1168
+ left: { style: 'thick' },
1169
+ right: { style: 'thick' }
1170
+ };
1171
+ currentRow += 1;
1172
+ row = ws.getRow(currentRow);
1173
+ // Headers
1174
+ report.fields_selected.filter(function (a) { return a.show; }).forEach(function (field, fieldIndex) {
1175
+ row.getCell(fieldIndex + 2).value = field.columnName;
1176
+ row.getCell(fieldIndex + 2).font = {
1177
+ name: 'Arial',
1178
+ bold: true,
1179
+ size: 10
1180
+ };
1181
+ if (field.leafFormatType === 'Currency') {
1182
+ row.getCell(fieldIndex + 2).numFmt = '"$"#,##0.00';
1183
+ }
1184
+ else if (field.leafFormatType === 'Number') {
1185
+ row.getCell(fieldIndex + 2).numFmt = '#,##0';
1186
+ }
1187
+ if (fieldIndex === 0) {
1188
+ row.getCell(fieldIndex + 2).border = {
1189
+ left: { style: 'thick' }
1190
+ };
1191
+ }
1192
+ else if (fieldIndex === report.fields_selected.filter(function (a) { return a.show; }).length - 1) {
1193
+ row.getCell(fieldIndex + 2).border = {
1194
+ right: { style: 'thick' }
1195
+ };
1196
+ }
1197
+ });
1198
+ // Data
1199
+ result['f_0'].forEach(function (res, resIndex) {
1200
+ currentRow += 1;
1201
+ row = ws.getRow(currentRow);
1202
+ report.fields_selected.filter(function (a) { return a.show; }).forEach(function (field, fieldIndex) {
1203
+ if (field.fieldType === 'Number' && typeof (result[field.id][resIndex] === 'string') && result[field.id][resIndex]) {
1204
+ row.getCell(fieldIndex + 2).value = parseFloat(result[field.id][resIndex].replace(new RegExp(/\,/g), '').replace(new RegExp(/\$/g), ''));
1205
+ }
1206
+ else {
1207
+ row.getCell(fieldIndex + 2).value = result[field.id][resIndex];
1208
+ }
1209
+ if (field.leafFormatType === 'Currency') {
1210
+ row.getCell(fieldIndex + 2).numFmt = '"$"#,##0.00';
1211
+ }
1212
+ else if (field.leafFormatType === 'Number') {
1213
+ row.getCell(fieldIndex + 2).numFmt = '#,##0';
1214
+ }
1215
+ row.getCell(fieldIndex + 2).font = {
1216
+ name: 'Arial',
1217
+ size: 10
1218
+ };
1219
+ if (fieldIndex === 0) {
1220
+ row.getCell(fieldIndex + 2).border = {
1221
+ left: { style: 'thick' }
1222
+ };
1223
+ }
1224
+ else if (fieldIndex === report.fields_selected.filter(function (a) { return a.show; }).length - 1) {
1225
+ row.getCell(fieldIndex + 2).border = {
1226
+ right: { style: 'thick' }
1227
+ };
1228
+ }
1229
+ });
1230
+ });
1231
+ // Totals
1232
+ report.fields_total.forEach(function (total) {
1233
+ currentRow += 1;
1234
+ row = ws.getRow(currentRow);
1235
+ report.fields_selected.filter(function (a) { return a.show; }).forEach(function (field, fieldIndex) {
1236
+ if (total.fields.includes(field.id)) {
1237
+ row.getCell(fieldIndex + 2).value = result[total.id + '_' + field.id];
1238
+ row.getCell(fieldIndex + 2).font = {
1239
+ name: 'Arial',
1240
+ bold: true,
1241
+ size: 10
1242
+ };
1243
+ if (field.leafFormatType === 'Currency') {
1244
+ row.getCell(fieldIndex + 2).numFmt = '"$"#,##0.00';
1245
+ }
1246
+ else if (field.leafFormatType === 'Number') {
1247
+ row.getCell(fieldIndex + 2).numFmt = '#,##0';
1248
+ }
1249
+ }
1250
+ if (fieldIndex === 0) {
1251
+ row.getCell(fieldIndex + 2).border = {
1252
+ top: { style: 'thin' },
1253
+ left: { style: 'thick' },
1254
+ bottom: { style: 'thick' }
1255
+ };
1256
+ }
1257
+ else if (fieldIndex === report.fields_selected.filter(function (a) { return a.show; }).length - 1) {
1258
+ row.getCell(fieldIndex + 2).border = {
1259
+ top: { style: 'thin' },
1260
+ bottom: { style: 'thick' },
1261
+ right: { style: 'thick' }
1262
+ };
1263
+ }
1264
+ else {
1265
+ row.getCell(fieldIndex + 2).border = {
1266
+ top: { style: 'thin' },
1267
+ bottom: { style: 'thick' }
1268
+ };
1269
+ }
1270
+ });
1271
+ });
1272
+ }
1273
+ return currentRow + 1;
1274
+ }
1275
+ function tabGroupExcelWidthRecursive(report, level, result, cols) {
1276
+ if (level < report.groups_row.length) {
1277
+ result = result['gr_' + (level + 1)];
1278
+ result.forEach(function (tDataRes, tIndex) {
1279
+ cols = tabGroupExcelWidthRecursive(report, level + 1, tDataRes, cols);
1280
+ });
1281
+ }
1282
+ else {
1283
+ report.fields_selected.filter(function (a) { return a.show; }).forEach(function (field, fieldIndex) {
1284
+ if (Array.isArray(result[field.id])) {
1285
+ result[field.id].forEach(function (res) {
1286
+ var length = 10;
1287
+ if (res) {
1288
+ length = res.length + 3;
1289
+ }
1290
+ if (!cols[fieldIndex]) {
1291
+ cols[fieldIndex] = Math.max(10, field.columnName.length);
1292
+ }
1293
+ if (length > cols[fieldIndex]) {
1294
+ cols[fieldIndex] = length;
1295
+ }
1296
+ });
1297
+ }
1298
+ else {
1299
+ var res = result[field.id];
1300
+ if (res) {
1301
+ length = res.length + 3;
1302
+ }
1303
+ if (!cols[fieldIndex]) {
1304
+ cols[fieldIndex] = Math.max(10, field.columnName.length);
1305
+ }
1306
+ if (length > cols[fieldIndex]) {
1307
+ cols[fieldIndex] = length;
1308
+ }
1309
+ }
1310
+ });
1311
+ }
1312
+ return cols;
1313
+ }
1314
+
1315
+ //# sourceMappingURL=cron-jobs.js.map