acknowledgement.service.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import { AnyObject } from "mongoose";
  2. import { map, Observable, of, tap } from "rxjs";
  3. import { Command, ResponseMessage, Uuid } from "../dependencies/fisappmessagejsutilty/interface/export"
  4. import { FisCreateMessageUtility } from "../dependencies/fisappmessagejsutilty/interface/export";
  5. import { LoggingService } from "../dependencies/fisloggingservice/services/logging-service";
  6. import { LogSetting, MessageLog } from "../dependencies/fisloggingservice/type/datatype";
  7. import { Acknowledgemeent, AcknowledgementLogSetting } from "../type/acknowledgement.interface";
  8. export class AcknowledgementService implements Acknowledgemeent {
  9. private messageUtil: FisCreateMessageUtility = new FisCreateMessageUtility("FisAppID/Name")
  10. // private settings1: LogSetting = {
  11. // storage: '',
  12. // setting: {
  13. // appId: '',
  14. // appName: '',
  15. // logLocName: '',
  16. // logLocId: '',
  17. // appLogLocId: '',
  18. // appLocName: '',
  19. // appLogId: ''
  20. // }
  21. // }
  22. private settings2: LogSetting = {
  23. storage: '',
  24. setting: {
  25. appId: '',
  26. appName: '',
  27. logLocName: '',
  28. logLocId: '',
  29. appLogLocId: '',
  30. appLocName: '',
  31. appLogId: ''
  32. }
  33. }
  34. constructor(private logService1?: LoggingService, private logService2?: LoggingService) {
  35. // this.logService1 = new LoggingService()
  36. this.logService2 = new LoggingService()
  37. }
  38. // set the data. I dont know what to set yet
  39. public async init(settings: AcknowledgementLogSetting) {
  40. // let logSetting1: LogSetting = {
  41. // ...settings,
  42. // setting: {
  43. // ...settings.setting,
  44. // logLocName: "locationName1",
  45. // appLocName: "appLocName1"
  46. // }
  47. // }
  48. let logSetting2: LogSetting = {
  49. ...settings,
  50. setting: {
  51. ...settings.setting,
  52. logLocName: "locationName2",
  53. appLocName: "appLocName2"
  54. }
  55. }
  56. // console.log(settings)
  57. // this.settings1 = logSetting1
  58. // this.logService1.init(logSetting1)
  59. this.settings2 = logSetting2
  60. this.logService2.init(logSetting2)
  61. }
  62. // suppose to call logging service to give an observable type report for every message streamed
  63. public subscribe(obs: Observable<any>): Observable<ResponseMessage> {
  64. let acknowledgementToken: Observable<ResponseMessage> = obs.pipe(
  65. map(
  66. incoming_msg => {
  67. let emulatedId = "GeneratedFromMessageSync"
  68. let emulatedRequest = this.messageUtil.getCommandMessage(emulatedId, Command.New, incoming_msg)
  69. let finalResponse = this.messageUtil.getResponseMessage(emulatedId, { "Acknowledgement": 1 }, emulatedRequest)
  70. return finalResponse
  71. }
  72. ))
  73. let acknowledgementTokenLogging: Observable<MessageLog> = obs.pipe(
  74. map(
  75. incoming_msg => {
  76. let finalResponse:MessageLog = {
  77. appLogLocId: this.settings2.setting.appLogId || "",
  78. appData: {
  79. msgId: new Uuid().generateId(),
  80. msgLogDateTime: new Date(),
  81. msgDateTime: new Date(),
  82. msgTag: ['Acknowledgement'],
  83. msgPayload: JSON.stringify(incoming_msg)
  84. }
  85. }
  86. return finalResponse
  87. }
  88. )
  89. )
  90. this.logService2.subscribe(acknowledgementTokenLogging)
  91. return acknowledgementToken
  92. }
  93. }