test1.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 { queryService } from "../services/query.service"
  7. import { Conditions, Storage } from "../services/query.service"
  8. import { _, isObject } from 'lodash'
  9. let query = new queryService()
  10. //For now just local file storage. More will be preapred in the design phase later.
  11. let storageAddress: Storage = {
  12. type: "File",
  13. url: "payload.json"
  14. }
  15. // Array inquiry: should return mutiple data
  16. let conditions1: Conditions[] = [
  17. { 'msgTag': ['basic'] }
  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(storageAddress, ...conditions1).subscribe((element) => {
  93. console.log(`OBS1 : ${element.header.messageName} is matched`)
  94. })
  95. query.query(storageAddress, ...conditions2).subscribe((element) => {
  96. console.log(`OBS2 :${element.header.messageName} is matched`)
  97. })
  98. query.query(storageAddress, ...conditions3).subscribe((element) => {
  99. console.log(`OBS3 :${element.header.messageName} is matched`)
  100. })
  101. query.query(storageAddress, ...conditions4).subscribe((element) => {
  102. console.log(`OBS4 :${element.header.messageName} is matched`)
  103. })
  104. query.query(storageAddress, ...conditions5).subscribe((element) => {
  105. console.log(`OBS5 :${element.header.messageName} is matched`)
  106. })
  107. query.query(storageAddress, ...conditions6).subscribe((element) => {
  108. console.log(`OBS6 :${element.header.messageName} is matched`)
  109. })
  110. query.query(storageAddress, ...conditions7).subscribe((element) => {
  111. console.log(`OBS7 :${element.header.messageName} is matched`)
  112. })
  113. query.query(storageAddress, ...conditions8).subscribe((element) => {
  114. console.log(`OBS8 :${element.header.messageName} is matched`)
  115. })