test2.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 _ = require("lodash")
  8. import { Conditions, StorageLocation } from "../types/interface"
  9. let query = new SearchService()
  10. let mongoStorage : StorageLocation = {
  11. type: `MongoDB`,
  12. url: `mongodb://192.168.100.59:27017/default`
  13. }
  14. // Array inquiry: should return mutiple data
  15. let conditions1: Conditions[] = [
  16. { 'msgTag': ['Incoming'] }
  17. ]
  18. // Basic inquiry, but with multi search: should return one data
  19. let conditions2: Conditions[] = [
  20. { "msgId": "4f710c4b-a258-4c7e-a4b6-6095bb7028e9" },
  21. { "msgLogDateTime": "2023-01-14T21:50:19.917Z" },
  22. ]
  23. // Value only argument! : should return one data
  24. let conditions3: Conditions[] = [
  25. { "$regex": "cum incidunt maxime voluptatibus" }
  26. ]
  27. // Date Range inquiry: Should return 1 data
  28. let conditions4: Conditions[] = [
  29. {
  30. "$dateRange": {
  31. "startDate": "2022-04-29T00:00:00.000Z",
  32. 'endDate': "2022-04-30T00:00:00.000Z",
  33. 'column': "data.data.appData.msgDateTime"
  34. }
  35. },
  36. ]
  37. // Multi conditions except for regex search: Should return at least 1 data
  38. let conditions5: Conditions[] = [
  39. {
  40. "$dateRange": {
  41. "startDate": "2022-04-29T00:00:00.000Z",
  42. 'endDate': "2022-04-30T00:00:00.000Z",
  43. 'column': "data.data.appData.msgDateTime"
  44. }
  45. },
  46. { 'msgTag': ['basic'] },
  47. { "msgId": "4f710c4b-a258-4c7e-a4b6-6095bb7028e9" },
  48. { "msgLogDateTime": "2023-01-14T21:50:19.917Z" }
  49. ]
  50. // Ultimate search. With all conditions piling at once: Should at least returns 1 data
  51. let conditions6: Conditions[] = [
  52. {
  53. "$dateRange": {
  54. "startDate": "2022-04-29T00:00:00.000Z",
  55. 'endDate': "2022-04-30T00:00:00.000Z",
  56. 'column': "data.data.appData.msgDateTime"
  57. }
  58. },
  59. { "$regex": "maxime voluptatibus ad quasi eveniet" },
  60. { 'msgTag': ['basic'] },
  61. { "msgId": "4f710c4b-a258-4c7e-a4b6-6095bb7028e9" },
  62. ]
  63. // should return 1 data
  64. let conditions7: Conditions[] = [
  65. {
  66. "$dateRange": {
  67. "startDate": "2022-04-29T00:00:00.000Z",
  68. 'endDate': "2022-04-30T00:00:00.000Z",
  69. 'column': "data.data.appData.msgDateTime"
  70. }
  71. },
  72. { "$regex": "maxime voluptatibus ad quasi eveniet" },
  73. // { 'data.data.appData.msgTag': ['basic'] },
  74. { "data.data.appData.msgId": "4f710c4b-a258-4c7e-a4b6-6095bb7028e9" },
  75. { "msgLogDateTime": "2023-01-14T21:50:19.917Z" }
  76. ]
  77. // should not return anything
  78. let conditions8: Conditions[] = [
  79. {
  80. "$dateRange": {
  81. "startDate": "2022-04-29T00:00:00.000Z",
  82. 'endDate': "2022-04-30T00:00:00.000Z",
  83. 'column': "data.data.appData.msgDateTime"
  84. }
  85. },
  86. { "$regex": "maxime voluptatibus ad quasi eveniet" },
  87. { 'msgTag': ['basic'] },
  88. { "data.data.appDatamsgId": "4f710c4b-a258-4c7e-a4b6-6095bb7028e9" },
  89. { "header.msgLogDateTime": "2023-01-14T21:50:19.917Z" }
  90. ]
  91. query.query(mongoStorage, ...conditions1).subscribe((element) => {
  92. console.log(element.appData.msgId)
  93. })