test2.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* the key is to do it in one line. Client just pass 2 arguments, one is the location of the data, which could be file, sql or mongodb, and also
  2. pass in the conditions of their search enquiries. We will aslo have to cater to different file storage location to determine how to prep the
  3. data to be filtered
  4. */
  5. import { Observable } from "rxjs"
  6. import { SearchService } from "../services/query.service"
  7. import { Conditions, Storage } from "../services/query.service"
  8. import { isObject } from 'lodash'
  9. import _ = require("lodash")
  10. let query = new SearchService()
  11. let mongoStorage : Storage = {
  12. type: `MongoDB`,
  13. url: `mongodb://192.168.100.59:27017/fromEnzo`
  14. }
  15. // Array inquiry: should return mutiple data
  16. let conditions1: Conditions[] = [
  17. { 'msgTag': ['Incoming'] }
  18. ]
  19. // Basic inquiry, but with multi search: should return one data
  20. let conditions2: Conditions[] = [
  21. { "msgId": "4f710c4b-a258-4c7e-a4b6-6095bb7028e9" },
  22. { "msgLogDateTime": "2023-01-14T21:50:19.917Z" },
  23. ]
  24. // Value only argument! : should return one data
  25. let conditions3: Conditions[] = [
  26. { "$regex": "cum incidunt maxime voluptatibus" }
  27. ]
  28. // Date Range inquiry: Should return 1 data
  29. let conditions4: Conditions[] = [
  30. {
  31. "$dateRange": {
  32. "startDate": "2022-04-29T00:00:00.000Z",
  33. 'endDate': "2022-04-30T00:00:00.000Z",
  34. 'column': "data.data.appData.msgDateTime"
  35. }
  36. },
  37. ]
  38. // Multi conditions except for regex search: Should return at least 1 data
  39. let conditions5: Conditions[] = [
  40. {
  41. "$dateRange": {
  42. "startDate": "2022-04-29T00:00:00.000Z",
  43. 'endDate': "2022-04-30T00:00:00.000Z",
  44. 'column': "data.data.appData.msgDateTime"
  45. }
  46. },
  47. { 'msgTag': ['basic'] },
  48. { "msgId": "4f710c4b-a258-4c7e-a4b6-6095bb7028e9" },
  49. { "msgLogDateTime": "2023-01-14T21:50:19.917Z" }
  50. ]
  51. // Ultimate search. With all conditions piling at once: Should at least returns 1 data
  52. let conditions6: Conditions[] = [
  53. {
  54. "$dateRange": {
  55. "startDate": "2022-04-29T00:00:00.000Z",
  56. 'endDate': "2022-04-30T00:00:00.000Z",
  57. 'column': "data.data.appData.msgDateTime"
  58. }
  59. },
  60. { "$regex": "maxime voluptatibus ad quasi eveniet" },
  61. { 'msgTag': ['basic'] },
  62. { "msgId": "4f710c4b-a258-4c7e-a4b6-6095bb7028e9" },
  63. ]
  64. // should return 1 data
  65. let conditions7: Conditions[] = [
  66. {
  67. "$dateRange": {
  68. "startDate": "2022-04-29T00:00:00.000Z",
  69. 'endDate': "2022-04-30T00:00:00.000Z",
  70. 'column': "data.data.appData.msgDateTime"
  71. }
  72. },
  73. { "$regex": "maxime voluptatibus ad quasi eveniet" },
  74. // { 'data.data.appData.msgTag': ['basic'] },
  75. { "data.data.appData.msgId": "4f710c4b-a258-4c7e-a4b6-6095bb7028e9" },
  76. { "msgLogDateTime": "2023-01-14T21:50:19.917Z" }
  77. ]
  78. // should not return anything
  79. let conditions8: Conditions[] = [
  80. {
  81. "$dateRange": {
  82. "startDate": "2022-04-29T00:00:00.000Z",
  83. 'endDate': "2022-04-30T00:00:00.000Z",
  84. 'column': "data.data.appData.msgDateTime"
  85. }
  86. },
  87. { "$regex": "maxime voluptatibus ad quasi eveniet" },
  88. { 'msgTag': ['basic'] },
  89. { "data.data.appDatamsgId": "4f710c4b-a258-4c7e-a4b6-6095bb7028e9" },
  90. { "header.msgLogDateTime": "2023-01-14T21:50:19.917Z" }
  91. ]
  92. query.query(mongoStorage, ...conditions1).subscribe((element) => {
  93. console.log(element.appData.msgId)
  94. })