test1.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 { isObject } from 'lodash'
  8. import _ = require("lodash")
  9. import { Conditions, StorageLocation } from "../types/interface"
  10. let query = new SearchService()
  11. //For now just local file storage. More will be preapred in the design phase later.
  12. let storageAddress: StorageLocation = {
  13. type: "File",
  14. url: "payload.json"
  15. }
  16. // Array inquiry: should return mutiple data
  17. let conditions1: Conditions[] = [
  18. { 'msgTag': ['basic'] }
  19. ]
  20. // Basic inquiry, but with multi search: should return one data
  21. let conditions2: Conditions[] = [
  22. { "msgId": "4f710c4b-a258-4c7e-a4b6-6095bb7028e9" },
  23. { "msgLogDateTime": "2023-01-14T21:50:19.917Z" },
  24. ]
  25. // Value only argument! : should return one data
  26. let conditions3: Conditions[] = [
  27. { "$regex": "cum incidunt maxime voluptatibus" }
  28. ]
  29. // Date Range inquiry: Should return 1 data
  30. let conditions4: Conditions[] = [
  31. {
  32. "$dateRange": {
  33. "startDate": "2022-04-29T00:00:00.000Z",
  34. 'endDate': "2022-04-30T00:00:00.000Z",
  35. 'column': "data.data.appData.msgDateTime"
  36. }
  37. },
  38. ]
  39. // Multi conditions except for regex search: Should return at least 1 data
  40. let conditions5: Conditions[] = [
  41. {
  42. "$dateRange": {
  43. "startDate": "2022-04-29T00:00:00.000Z",
  44. 'endDate': "2022-04-30T00:00:00.000Z",
  45. 'column': "data.data.appData.msgDateTime"
  46. }
  47. },
  48. { 'msgTag': ['basic'] },
  49. { "msgId": "4f710c4b-a258-4c7e-a4b6-6095bb7028e9" },
  50. { "msgLogDateTime": "2023-01-14T21:50:19.917Z" }
  51. ]
  52. // Ultimate search. With all conditions piling at once: Should at least returns 1 data
  53. let conditions6: Conditions[] = [
  54. {
  55. "$dateRange": {
  56. "startDate": "2022-04-29T00:00:00.000Z",
  57. 'endDate': "2022-04-30T00:00:00.000Z",
  58. 'column': "data.data.appData.msgDateTime"
  59. }
  60. },
  61. { "$regex": "maxime voluptatibus ad quasi eveniet" },
  62. { 'msgTag': ['basic'] },
  63. { "msgId": "4f710c4b-a258-4c7e-a4b6-6095bb7028e9" },
  64. ]
  65. // should return 1 data
  66. let conditions7: Conditions[] = [
  67. {
  68. "$dateRange": {
  69. "startDate": "2022-04-29T00:00:00.000Z",
  70. 'endDate': "2022-04-30T00:00:00.000Z",
  71. 'column': "data.data.appData.msgDateTime"
  72. }
  73. },
  74. { "$regex": "maxime voluptatibus ad quasi eveniet" },
  75. // { 'data.data.appData.msgTag': ['basic'] },
  76. { "data.data.appData.msgId": "4f710c4b-a258-4c7e-a4b6-6095bb7028e9" },
  77. { "msgLogDateTime": "2023-01-14T21:50:19.917Z" }
  78. ]
  79. // should not return anything
  80. let conditions8: Conditions[] = [
  81. {
  82. "$dateRange": {
  83. "startDate": "2022-04-29T00:00:00.000Z",
  84. 'endDate': "2022-04-30T00:00:00.000Z",
  85. 'column': "data.data.appData.msgDateTime"
  86. }
  87. },
  88. { "$regex": "maxime voluptatibus ad quasi eveniet" },
  89. { 'msgTag': ['basic'] },
  90. { "data.data.appDatamsgId": "4f710c4b-a258-4c7e-a4b6-6095bb7028e9" },
  91. { "header.msgLogDateTime": "2023-01-14T21:50:19.917Z" }
  92. ]
  93. query.query(storageAddress, ...conditions1).subscribe((element) => {
  94. console.log(`OBS1 : ${element.header.messageName} is matched`)
  95. })
  96. query.query(storageAddress, ...conditions2).subscribe((element) => {
  97. console.log(`OBS2 :${element.header.messageName} is matched`)
  98. })
  99. query.query(storageAddress, ...conditions3).subscribe((element) => {
  100. console.log(`OBS3 :${element.header.messageName} is matched`)
  101. })
  102. query.query(storageAddress, ...conditions4).subscribe((element) => {
  103. console.log(`OBS4 :${element.header.messageName} is matched`)
  104. })
  105. query.query(storageAddress, ...conditions5).subscribe((element) => {
  106. console.log(`OBS5 :${element.header.messageName} is matched`)
  107. })
  108. query.query(storageAddress, ...conditions6).subscribe((element) => {
  109. console.log(`OBS6 :${element.header.messageName} is matched`)
  110. })
  111. query.query(storageAddress, ...conditions7).subscribe((element) => {
  112. console.log(`OBS7 :${element.header.messageName} is matched`)
  113. })
  114. query.query(storageAddress, ...conditions8).subscribe((element) => {
  115. console.log(`OBS8 :${element.header.messageName} is matched`)
  116. })